Skip to content

Commit

Permalink
Fixed datetime conversion when writing
Browse files Browse the repository at this point in the history
  • Loading branch information
dei79 committed Nov 10, 2023
1 parent 1138e79 commit 3bee61a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<DemoModel2>(new List<DemoModel2>() { model });
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 3bee61a

Please sign in to comment.