diff --git a/CoreHelpers.WindowsAzure.Storage.Table.Tests/ITS017ImportFromJson.cs b/CoreHelpers.WindowsAzure.Storage.Table.Tests/ITS017ImportFromJson.cs index f70ca67..924d8b5 100644 --- a/CoreHelpers.WindowsAzure.Storage.Table.Tests/ITS017ImportFromJson.cs +++ b/CoreHelpers.WindowsAzure.Storage.Table.Tests/ITS017ImportFromJson.cs @@ -1,4 +1,4 @@ -using System.Text; +using System.Text; using CoreHelpers.WindowsAzure.Storage.Table.Tests.Contracts; using CoreHelpers.WindowsAzure.Storage.Table.Tests.Extensions; using CoreHelpers.WindowsAzure.Storage.Table.Tests.Models; @@ -34,7 +34,7 @@ public async Task VerifyImportFromJson() 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 staticExportData = "[{\"RowKey\":\"2\",\"PartitionKey\":\"1\",\"Properties\":[{\"PropertyName\":\"P\",\"PropertyType\":0,\"PropertyValue\":\"1\"},{\"PropertyName\":\"R\",\"PropertyType\":0,\"PropertyValue\":\"2\"},{\"PropertyName\":\"CreatedAt\",\"PropertyType\":3,\"PropertyValue\":\"2023-01-30T22:58:40.5859427+00:00\"}]}]"; var staticExportDataStream = new MemoryStream(Encoding.UTF8.GetBytes(staticExportData ?? "")); // check if we have an empty tabel before import @@ -53,7 +53,13 @@ public async Task VerifyImportFromJson() // get the data var data = await storageContext.Query().Now(); Assert.Equal("1", data.First().P); - Assert.Equal("2", data.First().R); + Assert.Equal("2", data.First().R); + + var createdAtDate = DateTime.Parse("2023-01-30T22:58:40.5859427+00:00"); + var createdAtDateFromDataLoad = data.First().CreatedAt; + + Assert.Equal(createdAtDate.ToUniversalTime(), createdAtDateFromDataLoad); + Assert.Equal(createdAtDate.ToUniversalTime(), createdAtDateFromDataLoad.ToUniversalTime()); // drop table await storageContext.DropTableAsync(); diff --git a/CoreHelpers.WindowsAzure.Storage.Table.Tests/Models/DemoModel2.cs b/CoreHelpers.WindowsAzure.Storage.Table.Tests/Models/DemoModel2.cs index ac915ef..c780777 100644 --- a/CoreHelpers.WindowsAzure.Storage.Table.Tests/Models/DemoModel2.cs +++ b/CoreHelpers.WindowsAzure.Storage.Table.Tests/Models/DemoModel2.cs @@ -12,6 +12,8 @@ public class DemoModel2 [RowKey] public string R { get; set; } = "R1"; + + public DateTime CreatedAt { get; set; } = DateTime.MinValue; } } diff --git a/CoreHelpers.WindowsAzure.Storage.Table/StorageContextImportExport.cs b/CoreHelpers.WindowsAzure.Storage.Table/StorageContextImportExport.cs index b32795d..4e5f39d 100644 --- a/CoreHelpers.WindowsAzure.Storage.Table/StorageContextImportExport.cs +++ b/CoreHelpers.WindowsAzure.Storage.Table/StorageContextImportExport.cs @@ -123,6 +123,8 @@ public async Task ImportFromJsonAsync(string tableName, StreamReader reader, Act if ((ExportEdmType)property.PropertyType == ExportEdmType.String && property.PropertyValue is DateTime) { property.PropertyValue = ((DateTime)property.PropertyValue).ToString("o"); + } else if ((ExportEdmType)property.PropertyType == ExportEdmType.DateTime) { + property.PropertyValue = ((DateTime)property.PropertyValue).ToUniversalTime(); } }