-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
296 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
CoreHelpers.WindowsAzure.Storage.Table.Tests/Extensions/StorageContextExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System; | ||
namespace CoreHelpers.WindowsAzure.Storage.Table.Tests.Extensions | ||
{ | ||
public static class StorageContextExtensions | ||
{ | ||
public static string BuildTableContext() | ||
{ | ||
return $"T{Guid.NewGuid().ToString().Replace("-", "").Substring(0, 8)}"; | ||
} | ||
|
||
public static string SetTableContext(this StorageContext context) | ||
{ | ||
var contextValue = BuildTableContext(); | ||
context.SetTableNamePrefix(contextValue); | ||
return contextValue; | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
using System; | ||
using CoreHelpers.WindowsAzure.Storage.Table.Delegates; | ||
using CoreHelpers.WindowsAzure.Storage.Table.Tests.Contracts; | ||
using CoreHelpers.WindowsAzure.Storage.Table.Tests.Extensions; | ||
using CoreHelpers.WindowsAzure.Storage.Table.Tests.Models; | ||
using Xunit.DependencyInjection; | ||
|
||
|
@@ -22,8 +23,11 @@ public async Task VerifyStaticEntityMapperOperations() | |
{ | ||
using (var scp = new StorageContext(env.ConnectionString)) | ||
{ | ||
// unification uuid | ||
var runId = Guid.NewGuid().ToString(); | ||
// set the tablename context | ||
scp.SetTableContext(); | ||
|
||
// unification uuid | ||
var runId = Guid.NewGuid().ToString(); | ||
|
||
// create a new user | ||
var user = new UserModel() { FirstName = "Egon", LastName = "Mueller", Contact = "[email protected]" }; | ||
|
@@ -50,11 +54,9 @@ public async Task VerifyStaticEntityMapperOperations() | |
Assert.Equal("Mueller", result.First().LastName); | ||
Assert.Equal($"[email protected].{runId}", result.First().Contact); | ||
|
||
// Clean up | ||
await scp.DeleteAsync<UserModel>(result); | ||
result = await scp.QueryAsync<UserModel>(); | ||
Assert.NotNull(result); | ||
Assert.Equal(0, result.Count()); | ||
// Clean up | ||
await scp.DropTableAsync<UserModel>(); | ||
Assert.False(await scp.ExistsTableAsync<UserModel>()); | ||
} | ||
} | ||
|
||
|
@@ -63,8 +65,11 @@ public async Task VerifyVirtualKeysPOCOModel() | |
{ | ||
using (var scp = new StorageContext(env.ConnectionString)) | ||
{ | ||
// create model | ||
var vpmodel = new VirtualPartitionKeyDemoModelPOCO() { Value1 = "abc", Value2 = "def", Value3 = "ghi" }; | ||
// set the tablename context | ||
scp.SetTableContext(); | ||
|
||
// create model | ||
var vpmodel = new VirtualPartitionKeyDemoModelPOCO() { Value1 = "abc", Value2 = "def", Value3 = "ghi" }; | ||
|
||
// configure the entity mapper | ||
scp.AddEntityMapper(typeof(VirtualPartitionKeyDemoModelPOCO), new DynamicTableEntityMapper() { TableName = "VirtualPartitionKeyDemoModelPOCO", PartitionKeyFormat = "{{Value1}}-{{Value2}}", RowKeyFormat = "{{Value2}}-{{Value3}}" }); | ||
|
@@ -88,10 +93,8 @@ public async Task VerifyVirtualKeysPOCOModel() | |
Assert.Equal("ghi", result.First().Value3); | ||
|
||
// Clean up | ||
await scp.DeleteAsync<VirtualPartitionKeyDemoModelPOCO>(result); | ||
result = await scp.QueryAsync<VirtualPartitionKeyDemoModelPOCO>(); | ||
Assert.NotNull(result); | ||
Assert.Equal(0, result.Count()); | ||
await scp.DropTableAsync<VirtualPartitionKeyDemoModelPOCO>(); | ||
Assert.False(await scp.ExistsTableAsync<VirtualPartitionKeyDemoModelPOCO>()); | ||
} | ||
} | ||
|
||
|
@@ -100,8 +103,11 @@ public async Task VerifyStatsDelegate() | |
{ | ||
using (var scp = new StorageContext(env.ConnectionString)) | ||
{ | ||
// set the delegate | ||
var stats = new StorageContextStatsDelegate(); | ||
// set the tablename context | ||
scp.SetTableContext(); | ||
|
||
// set the delegate | ||
var stats = new StorageContextStatsDelegate(); | ||
scp.SetDelegate(stats); | ||
|
||
// unification uuid | ||
|
@@ -133,7 +139,11 @@ public async Task VerifyStatsDelegate() | |
// verify stats | ||
Assert.Equal(1, stats.QueryOperations); | ||
Assert.Equal(2, stats.StoreOperations.Values.Sum()); | ||
} | ||
|
||
// Drop the table | ||
await scp.DropTableAsync<UserModel>(); | ||
Assert.False(await scp.ExistsTableAsync<UserModel>()); | ||
} | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
using System; | ||
using CoreHelpers.WindowsAzure.Storage.Table.Tests.Contracts; | ||
using CoreHelpers.WindowsAzure.Storage.Table.Tests.Extensions; | ||
using CoreHelpers.WindowsAzure.Storage.Table.Tests.Models; | ||
using Xunit.DependencyInjection; | ||
|
||
|
@@ -20,7 +21,10 @@ public ITS002StoreWithAttributeMapper(ITestEnvironment env) | |
public async Task VerifyAttributeMapper() | ||
{ | ||
using (var storageContext = new StorageContext(env.ConnectionString)) | ||
{ | ||
{ | ||
// set the tablename context | ||
storageContext.SetTableContext(); | ||
|
||
// create a new user | ||
var user = new UserModel2() { FirstName = "Egon", LastName = "Mueller", Contact = "[email protected]" }; | ||
|
||
|
@@ -44,7 +48,9 @@ public async Task VerifyAttributeMapper() | |
await storageContext.DeleteAsync<UserModel2>(result); | ||
result = await storageContext.QueryAsync<UserModel2>(); | ||
Assert.NotNull(result); | ||
Assert.Equal(0, result.Count()); | ||
Assert.Equal(0, result.Count()); | ||
|
||
await storageContext.DropTableAsync<UserModel2>(); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
using System.Threading.Tasks; | ||
using CoreHelpers.WindowsAzure.Storage.Table.Tests; | ||
using CoreHelpers.WindowsAzure.Storage.Table.Tests.Contracts; | ||
using CoreHelpers.WindowsAzure.Storage.Table.Tests.Extensions; | ||
using CoreHelpers.WindowsAzure.Storage.Table.Tests.Models; | ||
using Xunit.DependencyInjection; | ||
|
||
|
@@ -22,9 +23,12 @@ public ITS003StoreWithAttributeMapperManualRegistration(ITestEnvironment env) | |
public async Task VerifyManualRegistration() | ||
{ | ||
using (var storageContext = new StorageContext(env.ConnectionString)) | ||
{ | ||
// create a new user | ||
var user = new UserModel2() { FirstName = "Egon", LastName = "Mueller", Contact = "[email protected]" }; | ||
{ | ||
// set the tablename context | ||
storageContext.SetTableContext(); | ||
|
||
// create a new user | ||
var user = new UserModel2() { FirstName = "Egon", LastName = "Mueller", Contact = "[email protected]" }; | ||
var vpmodel = new VirtualPartKeyDemoModel() { Value1 = "abc", Value2 = "def", Value3 = "ghi" }; | ||
|
||
// ensure we are using the attributes | ||
|
@@ -64,6 +68,9 @@ public async Task VerifyManualRegistration() | |
resultVP = await storageContext.QueryAsync<VirtualPartKeyDemoModel>(); | ||
Assert.NotNull(resultVP); | ||
Assert.Equal(0, resultVP.Count()); | ||
|
||
await storageContext.DropTableAsync<UserModel2>(); | ||
await storageContext.DropTableAsync<VirtualPartKeyDemoModel>(); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.