-
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.
Added support for the import from json capabilities
- Loading branch information
Showing
8 changed files
with
287 additions
and
221 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
63 changes: 63 additions & 0 deletions
63
CoreHelpers.WindowsAzure.Storage.Table.Tests/ITS017ImportFromJson.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,63 @@ | ||
using System.Text; | ||
using CoreHelpers.WindowsAzure.Storage.Table.Tests.Contracts; | ||
using CoreHelpers.WindowsAzure.Storage.Table.Tests.Extensions; | ||
using CoreHelpers.WindowsAzure.Storage.Table.Tests.Models; | ||
using Newtonsoft.Json.Linq; | ||
using Xunit.DependencyInjection; | ||
|
||
namespace CoreHelpers.WindowsAzure.Storage.Table.Tests | ||
{ | ||
[Startup(typeof(Startup))] | ||
[Collection("Sequential")] | ||
public class ITS017ImportFromJson | ||
{ | ||
private readonly IStorageContext _rootContext; | ||
|
||
public ITS017ImportFromJson(IStorageContext context) | ||
{ | ||
_rootContext = context; | ||
} | ||
|
||
[Fact] | ||
public async Task VerifyImportFromJson() | ||
{ | ||
await Task.CompletedTask; | ||
|
||
// Import Table | ||
using (var storageContext = _rootContext.CreateChildContext()) | ||
{ | ||
// set the tablename context | ||
storageContext.SetTableContext(); | ||
|
||
// ensure we have a model registered in the correct table | ||
var tableName1 = $"BU".Replace("-", ""); | ||
storageContext.AddAttributeMapper(typeof(DemoModel2), tableName1); | ||
|
||
// define the import data | ||
var staticExportData = "[{\"RowKey\":\"2\",\"PartitionKey\":\"1\",\"Properties\":[{\"PropertyName\":\"P\",\"PropertyType\":0,\"PropertyValue\":\"1\"},{\"PropertyName\":\"R\",\"PropertyType\":0,\"PropertyValue\":\"2\"}]}]"; | ||
var staticExportDataStream = new MemoryStream(Encoding.UTF8.GetBytes(staticExportData ?? "")); | ||
|
||
// check if we have an empty tabel before import | ||
Assert.Empty(await storageContext.EnableAutoCreateTable().Query<DemoModel2>().Now()); | ||
|
||
// open the data stream | ||
using (var streamReader = new StreamReader(staticExportDataStream)) | ||
{ | ||
// read the data | ||
await storageContext.ImportFromJsonAsync(tableName1, streamReader, (ImportExportOperation) => { }); | ||
} | ||
|
||
// check if we have the dara correctly imported | ||
Assert.Single(await storageContext.Query<DemoModel2>().Now()); | ||
|
||
// get the data | ||
var data = await storageContext.Query<DemoModel2>().Now(); | ||
Assert.Equal("1", data.First().P); | ||
Assert.Equal("2", data.First().R); | ||
|
||
// drop table | ||
await storageContext.DropTableAsync<DemoModel2>(); | ||
} | ||
} | ||
} | ||
} |
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
44 changes: 44 additions & 0 deletions
44
CoreHelpers.WindowsAzure.Storage.Table/Extensions/TypeExtensions.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,44 @@ | ||
using System; | ||
namespace CoreHelpers.WindowsAzure.Storage.Table.Extensions | ||
{ | ||
public enum ExportEdmType | ||
{ | ||
String, | ||
Binary, | ||
Boolean, | ||
DateTime, | ||
Double, | ||
Guid, | ||
Int32, | ||
Int64 | ||
} | ||
|
||
public static class TypeExtensions | ||
{ | ||
public static ExportEdmType GetEdmPropertyType(this Type type) | ||
{ | ||
if (type == typeof(string)) | ||
return ExportEdmType.String; | ||
else if (type == typeof(byte[])) | ||
return ExportEdmType.Binary; | ||
else if (type == typeof(Boolean) || type == typeof(bool)) | ||
return ExportEdmType.Boolean; | ||
else if (type == typeof(DateTime) || type == typeof(DateTimeOffset)) | ||
return ExportEdmType.DateTime; | ||
else if (type == typeof(Double)) | ||
return ExportEdmType.Double; | ||
else if (type == typeof(Guid)) | ||
return ExportEdmType.Guid; | ||
else if (type == typeof(Int32) || type == typeof(int)) | ||
return ExportEdmType.Int32; | ||
else if (type == typeof(Int64)) | ||
return ExportEdmType.Int64; | ||
else | ||
throw new NotImplementedException($"Datatype {type.ToString()} not supporter"); | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
|
131 changes: 0 additions & 131 deletions
131
CoreHelpers.WindowsAzure.Storage.Table/Services/DataImportService.cs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.