Skip to content

Commit

Permalink
Refactored InMemoryCloudTable to StubCloudTable
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei15193 committed Aug 24, 2021
1 parent 1e2fbe3 commit 394aa93
Show file tree
Hide file tree
Showing 68 changed files with 1,128 additions and 923 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using CloudStub.Core;
using CloudStub.Core.StorageHandlers;
using Microsoft.Azure.Cosmos.Table;

namespace CloudStub.Tests
{
public abstract class BaseInMemoryCloudTableTests : AzureStorageUnitTest
public abstract class BaseStubCloudTableTests : AzureStorageUnitTest
{
/// <summary>A temporary flag to easily switch between in-memory cloud table and actual Azure Storage Table.</summary>
protected static bool UseInMemory { get; } = true;

protected BaseInMemoryCloudTableTests()
protected BaseStubCloudTableTests()
=> CloudTable = GetCloudTable(TestTableName);

protected new string TestTableName { get; } = (nameof(BaseInMemoryCloudTableTests) + "TestTable" + Guid.NewGuid().ToString().Replace("-", "")).Substring(0, 63);
protected new string TestTableName { get; } = (nameof(BaseStubCloudTableTests) + "TestTable" + Guid.NewGuid().ToString().Replace("-", "")).Substring(0, 63);

protected CloudTable CloudTable { get; }

Expand Down Expand Up @@ -57,7 +59,7 @@ protected static async Task<IReadOnlyCollection<ITableEntity>> GetAllEntitiesAsy

protected static CloudTable GetCloudTable(string tableName)
=> UseInMemory ?
new InMemoryCloudTable(tableName) :
new StubCloudTable(new StubTable(tableName, new InMemoryTableStorageHandler())) :
CloudStorageAccount
.Parse(AzureStorageConnectionString)
.CreateCloudTableClient()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace CloudStub.Tests
{
public class InMemoryCloudTableQueryComparisonTestData : IEnumerable<object[]>
public class StubCloudTableQueryComparisonTestData : IEnumerable<object[]>
{
public IEnumerator<object[]> GetEnumerator()
=> MatchingTypeComparisonTestData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace CloudStub.Tests.TableBatchOperationTests.Async
{
public class InMemoryCloudTableBatchOperationTests : BaseInMemoryCloudTableTests
public class StubCloudTableBatchOperationTests : BaseStubCloudTableTests
{
[Fact]
public async Task ExecuteBatchAsync_WhenBatchIsNull_ThrowsException()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace CloudStub.Tests.TableBatchOperationTests.Async
{
public class InMemoryCloudTableEntityDeleteTableBatchOperationTests : BaseInMemoryCloudTableTests
public class StubCloudTableEntityDeleteTableBatchOperationTests : BaseStubCloudTableTests
{
[Fact]
public async Task ExecuteAsync_WhenTableDoesNotExist_ThrowsException()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace CloudStub.Tests.TableBatchOperationTests.Async
{
public class InMemoryCloudTableEntityInsertOrMergeTableBatchOperationTests : BaseInMemoryCloudTableTests
public class StubCloudTableEntityInsertOrMergeTableBatchOperationTests : BaseStubCloudTableTests
{
[Fact]
public async Task ExecuteAsync_WhenTableDoesNotExist_ThrowsException()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace CloudStub.Tests.TableBatchOperationTests.Async
{
public class InMemoryCloudTableEntityInsertOrReplaceTableBatchOperationTests : BaseInMemoryCloudTableTests
public class StubCloudTableEntityInsertOrReplaceTableBatchOperationTests : BaseStubCloudTableTests
{
[Fact]
public async Task ExecuteAsync_WhenTableDoesNotExist_ThrowsException()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace CloudStub.Tests.TableBatchOperationTests.Async
{
public class InMemoryCloudTableEntityInsertTableBatchOperationTests : BaseInMemoryCloudTableTests
public class StubCloudTableEntityInsertTableBatchOperationTests : BaseStubCloudTableTests
{
[Fact]
public async Task ExecuteAsync_WhenTableDoesNotExist_ThrowsException()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace CloudStub.Tests.TableBatchOperationTests.Async
{
public class InMemoryCloudTableEntityMergeTableBatchOperationTests : BaseInMemoryCloudTableTests
public class StubCloudTableEntityMergeTableBatchOperationTests : BaseStubCloudTableTests
{
[Fact]
public async Task ExecuteAsync_WhenTableDoesNotExist_ThrowsException()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace CloudStub.Tests.TableBatchOperationTests.Async
{
public class InMemoryCloudTableEntityReplaceTableBatchOperationTests : BaseInMemoryCloudTableTests
public class StubCloudTableEntityReplaceTableBatchOperationTests : BaseStubCloudTableTests
{
[Fact]
public async Task ExecuteAsync_WhenTableDoesNotExist_ThrowsException()
Expand Down Expand Up @@ -69,7 +69,6 @@ public void TableOperation_WhenETagIsMissing_ThrowsException()
[Fact]
public async Task ExecuteAsync_WhenETagsIsWildcard_ReplacesEntity()
{
var startTime = DateTimeOffset.UtcNow;
var testEntity = new TestEntity
{
PartitionKey = "partition-key",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace CloudStub.Tests.TableBatchOperationTests.Async
{
public class InMemoryCloudTableEntityRetrieveTableBatchOperationTests : BaseInMemoryCloudTableTests
public class StubCloudTableEntityRetrieveTableBatchOperationTests : BaseStubCloudTableTests
{
[Fact]
public async Task ExecuteAsync_WhenTableDoesNotExist_ReturnsNullResult()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace CloudStub.Tests.TableBatchOperationTests.Sync
{
public class InMemoryCloudTableBatchOperationTests : BaseInMemoryCloudTableTests
public class StubCloudTableBatchOperationTests : BaseStubCloudTableTests
{
[Fact]
public void ExecuteBatch_WhenBatchIsNull_ThrowsException()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace CloudStub.Tests.TableBatchOperationTests.Sync
{
public class InMemoryCloudTableEntityDeleteTableBatchOperationTests : BaseInMemoryCloudTableTests
public class StubCloudTableEntityDeleteTableBatchOperationTests : BaseStubCloudTableTests
{
[Fact]
public void Execute_WhenTableDoesNotExist_ThrowsException()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace CloudStub.Tests.TableBatchOperationTests.Sync
{
public class InMemoryCloudTableEntityInsertOrMergeTableBatchOperationTests : BaseInMemoryCloudTableTests
public class StubCloudTableEntityInsertOrMergeTableBatchOperationTests : BaseStubCloudTableTests
{
[Fact]
public void Execute_WhenTableDoesNotExist_ThrowsException()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace CloudStub.Tests.TableBatchOperationTests.Sync
{
public class InMemoryCloudTableEntityInsertOrReplaceTableBatchOperationTests : BaseInMemoryCloudTableTests
public class StubCloudTableEntityInsertOrReplaceTableBatchOperationTests : BaseStubCloudTableTests
{
[Fact]
public void Execute_WhenTableDoesNotExist_ThrowsException()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace CloudStub.Tests.TableBatchOperationTests.Sync
{
public class InMemoryCloudTableEntityInsertTableBatchOperationTests : BaseInMemoryCloudTableTests
public class StubCloudTableEntityInsertTableBatchOperationTests : BaseStubCloudTableTests
{
[Fact]
public void Execute_WhenTableDoesNotExist_ThrowsException()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace CloudStub.Tests.TableBatchOperationTests.Sync
{
public class InMemoryCloudTableEntityMergeTableBatchOperationTests : BaseInMemoryCloudTableTests
public class StubCloudTableEntityMergeTableBatchOperationTests : BaseStubCloudTableTests
{
[Fact]
public void Execute_WhenTableDoesNotExist_ThrowsException()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace CloudStub.Tests.TableBatchOperationTests.Sync
{
public class InMemoryCloudTableEntityReplaceTableBatchOperationTests : BaseInMemoryCloudTableTests
public class StubCloudTableEntityReplaceTableBatchOperationTests : BaseStubCloudTableTests
{
[Fact]
public void Execute_WhenTableDoesNotExist_ThrowsException()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace CloudStub.Tests.TableBatchOperationTests.Sync
{
public class InMemoryCloudTableEntityRetrieveTableBatchOperationTests : BaseInMemoryCloudTableTests
public class StubCloudTableEntityRetrieveTableBatchOperationTests : BaseStubCloudTableTests
{
[Fact]
public void Execute_WhenTableDoesNotExist_ReturnsNullResult()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace CloudStub.Tests.TableOperationTests.Async
{
public class InMemoryCloudTableEntityDeleteTableOperationTests : BaseInMemoryCloudTableTests
public class StubCloudTableEntityDeleteTableOperationTests : BaseStubCloudTableTests
{
[Fact]
public async Task ExecuteAsync_WhenTableDoesNotExist_ThrowsException()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace CloudStub.Tests.TableOperationTests.Async
{
public class InMemoryCloudTableEntityInsertOrMergeTableOperationTests : BaseInMemoryCloudTableTests
public class StubCloudTableEntityInsertOrMergeTableOperationTests : BaseStubCloudTableTests
{
[Fact]
public async Task ExecuteAsync_WhenTableDoesNotExist_ThrowsException()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace CloudStub.Tests.TableOperationTests.Async
{
public class InMemoryCloudTableEntityInsertOrReplaceTableOperationTests : BaseInMemoryCloudTableTests
public class StubCloudTableEntityInsertOrReplaceTableOperationTests : BaseStubCloudTableTests
{
[Fact]
public async Task ExecuteAsync_WhenTableDoesNotExist_ThrowsException()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace CloudStub.Tests.TableOperationTests.Async
{
public class InMemoryCloudTableEntityInsertTableOperationTests : BaseInMemoryCloudTableTests
public class StubCloudTableEntityInsertTableOperationTests : BaseStubCloudTableTests
{
[Fact]
public async Task ExecuteAsync_WhenTableDoesNotExist_ThrowsException()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace CloudStub.Tests.TableOperationTests.Async
{
public class InMemoryCloudTableEntityMergeTableOperationTests : BaseInMemoryCloudTableTests
public class StubCloudTableEntityMergeTableOperationTests : BaseStubCloudTableTests
{
[Fact]
public async Task ExecuteAsync_WhenTableDoesNotExist_ThrowsException()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace CloudStub.Tests.TableOperationTests.Async
{
public class InMemoryCloudTableEntityReplaceTableOperationTests : BaseInMemoryCloudTableTests
public class StubCloudTableEntityReplaceTableOperationTests : BaseStubCloudTableTests
{
[Fact]
public async Task ExecuteAsync_WhenTableDoesNotExist_ThrowsException()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace CloudStub.Tests.TableOperationTests.Async
{
public class InMemoryCloudTableEntityRetrieveTableOperationTests : BaseInMemoryCloudTableTests
public class StubCloudTableEntityRetrieveTableOperationTests : BaseStubCloudTableTests
{
[Fact]
public async Task ExecuteAsync_WhenTableDoesNotExist_ReturnsNullResult()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace CloudStub.Tests.TableOperationTests.Async
{
public class InMemoryCloudTableOperationTests : BaseInMemoryCloudTableTests
public class StubCloudTableOperationTests : BaseStubCloudTableTests
{
[Fact]
public async Task ExecuteAsync_WhenOperationIsNull_ThrowsException()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace CloudStub.Tests.TableOperationTests.Sync
{
public class InMemoryCloudTableEntityDeleteTableOperationTests : BaseInMemoryCloudTableTests
public class StubCloudTableEntityDeleteTableOperationTests : BaseStubCloudTableTests
{
[Fact]
public void Execute_WhenTableDoesNotExist_ThrowsException()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace CloudStub.Tests.TableOperationTests.Sync
{
public class InMemoryCloudTableEntityInsertOrMergeTableOperationTests : BaseInMemoryCloudTableTests
public class StubCloudTableEntityInsertOrMergeTableOperationTests : BaseStubCloudTableTests
{
[Fact]
public void Execute_WhenTableDoesNotExist_ThrowsException()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace CloudStub.Tests.TableOperationTests.Sync
{
public class InMemoryCloudTableEntityInsertOrReplaceTableOperationTests : BaseInMemoryCloudTableTests
public class StubCloudTableEntityInsertOrReplaceTableOperationTests : BaseStubCloudTableTests
{
[Fact]
public void Execute_WhenTableDoesNotExist_ThrowsException()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace CloudStub.Tests.TableOperationTests.Sync
{
public class InMemoryCloudTableEntityInsertTableOperationTests : BaseInMemoryCloudTableTests
public class StubCloudTableEntityInsertTableOperationTests : BaseStubCloudTableTests
{
[Fact]
public void Execute_WhenTableDoesNotExist_ThrowsException()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace CloudStub.Tests.TableOperationTests.Sync
{
public class InMemoryCloudTableEntityMergeTableOperationTests : BaseInMemoryCloudTableTests
public class StubCloudTableEntityMergeTableOperationTests : BaseStubCloudTableTests
{
[Fact]
public void Execute_WhenTableDoesNotExist_ThrowsException()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace CloudStub.Tests.TableOperationTests.Sync
{
public class InMemoryCloudTableEntityReplaceTableOperationTests : BaseInMemoryCloudTableTests
public class StubCloudTableEntityReplaceTableOperationTests : BaseStubCloudTableTests
{
[Fact]
public void Execute_WhenTableDoesNotExist_ThrowsException()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace CloudStub.Tests.TableOperationTests.Sync
{
public class InMemoryCloudTableEntityRetrieveTableOperationTests : BaseInMemoryCloudTableTests
public class StubCloudTableEntityRetrieveTableOperationTests : BaseStubCloudTableTests
{
[Fact]
public void Execute_WhenTableDoesNotExist_ReturnsNullResult()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace CloudStub.Tests.TableOperationTests.Sync
{
public class InMemoryCloudTableOperationTests : BaseInMemoryCloudTableTests
public class StubCloudTableOperationTests : BaseStubCloudTableTests
{
[Fact]
public void Execute_WhenOperationIsNull_ThrowsException()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace CloudStub.Tests.TableTests.Async
{
public class InMemoryCloudTableQuerySegmentedTests : BaseInMemoryCloudTableTests
public class StubCloudTableQuerySegmentedTests : BaseStubCloudTableTests
{
[Fact]
public async Task ExecuteQuerySegmentedAsync_WhenThereAreNoFilters_ReturnsAllItems()
Expand Down Expand Up @@ -312,7 +312,7 @@ await CloudTable.ExecuteAsync(TableOperation.Insert(new TestQueryEntity
}

[Theory]
[ClassData(typeof(InMemoryCloudTableQueryComparisonTestData))]
[ClassData(typeof(StubCloudTableQueryComparisonTestData))]
public async Task ExecuteQuerySegmentedAsync_WhenUsingComparisonFilteOperator_MayReturnEntities(string propertyName, object propertyValue, string filterOperator, object filterValue, bool returnsEntity)
{
await CloudTable.CreateIfNotExistsAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,14 @@

namespace CloudStub.Tests.TableTests.Async
{
public class InMemoryCloudTableTests : BaseInMemoryCloudTableTests
public class StubCloudTableTests : BaseStubCloudTableTests
{
[Fact]
public void TableName_GetsTheSameNameWhichWasProvided()
{
Assert.Equal(TestTableName, CloudTable.Name);
}

[Fact]
public void CreateAsync_WhenTableNameIsNull_ThrowsException()
{
var exception = Assert.Throws<ArgumentNullException>("tableName", () => GetCloudTable(null));
Assert.Equal(new ArgumentNullException("tableName").Message, exception.Message);
}

[Fact]
public void CreateAsync_WhenTableNameIsEmpty_ThrowsException()
{
var exception = Assert.Throws<ArgumentException>("tableName", () => GetCloudTable(""));
Assert.Equal(new ArgumentException("The argument must not be empty string.", "tableName").Message, exception.Message);
}

[Fact]
public async Task ExistsAsync_WhenTableDoesNotExist_ReturnsFalse()
{
Expand Down Expand Up @@ -138,7 +124,6 @@ public async Task CreateAsync_WhenTableNameIsReserved_ThrowsException(string tab
}

[Theory]
[InlineData(" ")]
[InlineData("t")]
[InlineData("tt")]
[InlineData("testTableNameHavingALengthOf63CharactersSomeOfThemAreJustExtra1s")]
Expand Down
Loading

0 comments on commit 394aa93

Please sign in to comment.