Skip to content

Commit 3bee61a

Browse files
committed
Fixed datetime conversion when writing
1 parent 1138e79 commit 3bee61a

3 files changed

Lines changed: 5 additions & 5 deletions

File tree

CoreHelpers.WindowsAzure.Storage.Table.Tests/ITS016ExportToJson.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Text;
1+
using System.Text;
22
using CoreHelpers.WindowsAzure.Storage.Table.Tests.Contracts;
33
using CoreHelpers.WindowsAzure.Storage.Table.Tests.Extensions;
44
using CoreHelpers.WindowsAzure.Storage.Table.Tests.Models;
@@ -32,7 +32,7 @@ public async Task VerifyExportToJson()
3232
storageContext.AddAttributeMapper(typeof(DemoModel2), tableName1);
3333

3434
// create model with data in list
35-
var model = new DemoModel2() { P = "1", R = "2" };
35+
var model = new DemoModel2() { P = "1", R = "2", CreatedAt = DateTime.Parse("2023-11-10T19:09:50.065462+00:00").ToUniversalTime()};
3636

3737
// inser the model
3838
await storageContext.EnableAutoCreateTable().MergeOrInsertAsync<DemoModel2>(new List<DemoModel2>() { model });
@@ -46,7 +46,7 @@ public async Task VerifyExportToJson()
4646

4747
// verify the targetstream
4848
var parsedStream = Encoding.Default.GetString(targetStream.GetBuffer()).Split("\0")[0];
49-
var expectedStreamValue = "[{\"RowKey\":\"2\",\"PartitionKey\":\"1\",\"Properties\":[{\"PropertyName\":\"P\",\"PropertyType\":0,\"PropertyValue\":\"1\"},{\"PropertyName\":\"R\",\"PropertyType\":0,\"PropertyValue\":\"2\"}]}]";
49+
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\"}]}]";
5050
Assert.Equal(expectedStreamValue, parsedStream);
5151

5252
// drop table

CoreHelpers.WindowsAzure.Storage.Table.Tests/Models/DemoModel2.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class DemoModel2
1313
[RowKey]
1414
public string R { get; set; } = "R1";
1515

16-
public DateTime CreatedAt { get; set; } = DateTime.MinValue;
16+
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
1717
}
1818
}
1919

CoreHelpers.WindowsAzure.Storage.Table/StorageContextImportExport.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public async Task ExportToJsonAsync(string tableName, TextWriter writer, Action<
6767
switch (propertyKvp.Value.GetType().GetEdmPropertyType())
6868
{
6969
case ExportEdmType.DateTime:
70-
wr.WriteValue(((DateTime)propertyKvp.Value).ToUniversalTime());
70+
wr.WriteValue(((DateTimeOffset)propertyKvp.Value).ToUniversalTime());
7171
break;
7272
default:
7373
wr.WriteValue(propertyKvp.Value);

0 commit comments

Comments
 (0)