From 3bee61a304d5543bea0f3ff0f896bb3b68d80439 Mon Sep 17 00:00:00 2001 From: Dirk Eisenberg Date: Fri, 10 Nov 2023 20:11:58 +0100 Subject: [PATCH] Fixed datetime conversion when writing --- .../ITS016ExportToJson.cs | 6 +++--- .../Models/DemoModel2.cs | 2 +- .../StorageContextImportExport.cs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CoreHelpers.WindowsAzure.Storage.Table.Tests/ITS016ExportToJson.cs b/CoreHelpers.WindowsAzure.Storage.Table.Tests/ITS016ExportToJson.cs index 51a7984..5aac8fb 100644 --- a/CoreHelpers.WindowsAzure.Storage.Table.Tests/ITS016ExportToJson.cs +++ b/CoreHelpers.WindowsAzure.Storage.Table.Tests/ITS016ExportToJson.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; @@ -32,7 +32,7 @@ public async Task VerifyExportToJson() storageContext.AddAttributeMapper(typeof(DemoModel2), tableName1); // create model with data in list - var model = new DemoModel2() { P = "1", R = "2" }; + var model = new DemoModel2() { P = "1", R = "2", CreatedAt = DateTime.Parse("2023-11-10T19:09:50.065462+00:00").ToUniversalTime()}; // inser the model await storageContext.EnableAutoCreateTable().MergeOrInsertAsync(new List() { model }); @@ -46,7 +46,7 @@ public async Task VerifyExportToJson() // verify the targetstream var parsedStream = Encoding.Default.GetString(targetStream.GetBuffer()).Split("\0")[0]; - var expectedStreamValue = "[{\"RowKey\":\"2\",\"PartitionKey\":\"1\",\"Properties\":[{\"PropertyName\":\"P\",\"PropertyType\":0,\"PropertyValue\":\"1\"},{\"PropertyName\":\"R\",\"PropertyType\":0,\"PropertyValue\":\"2\"}]}]"; + var expectedStreamValue = "[{\"RowKey\":\"2\",\"PartitionKey\":\"1\",\"Properties\":[{\"PropertyName\":\"CreatedAt\",\"PropertyType\":3,\"PropertyValue\":\"2023-11-10T19:09:50.065462+00:00\"},{\"PropertyName\":\"P\",\"PropertyType\":0,\"PropertyValue\":\"1\"},{\"PropertyName\":\"R\",\"PropertyType\":0,\"PropertyValue\":\"2\"}]}]"; Assert.Equal(expectedStreamValue, parsedStream); // drop table diff --git a/CoreHelpers.WindowsAzure.Storage.Table.Tests/Models/DemoModel2.cs b/CoreHelpers.WindowsAzure.Storage.Table.Tests/Models/DemoModel2.cs index c780777..c0ea986 100644 --- a/CoreHelpers.WindowsAzure.Storage.Table.Tests/Models/DemoModel2.cs +++ b/CoreHelpers.WindowsAzure.Storage.Table.Tests/Models/DemoModel2.cs @@ -13,7 +13,7 @@ public class DemoModel2 [RowKey] public string R { get; set; } = "R1"; - public DateTime CreatedAt { get; set; } = DateTime.MinValue; + public DateTime CreatedAt { get; set; } = DateTime.UtcNow; } } diff --git a/CoreHelpers.WindowsAzure.Storage.Table/StorageContextImportExport.cs b/CoreHelpers.WindowsAzure.Storage.Table/StorageContextImportExport.cs index 4e5f39d..ccb1778 100644 --- a/CoreHelpers.WindowsAzure.Storage.Table/StorageContextImportExport.cs +++ b/CoreHelpers.WindowsAzure.Storage.Table/StorageContextImportExport.cs @@ -67,7 +67,7 @@ public async Task ExportToJsonAsync(string tableName, TextWriter writer, Action< switch (propertyKvp.Value.GetType().GetEdmPropertyType()) { case ExportEdmType.DateTime: - wr.WriteValue(((DateTime)propertyKvp.Value).ToUniversalTime()); + wr.WriteValue(((DateTimeOffset)propertyKvp.Value).ToUniversalTime()); break; default: wr.WriteValue(propertyKvp.Value);