Skip to content

Commit 24c2b46

Browse files
committed
bug fix
1 parent 5f61dae commit 24c2b46

File tree

4 files changed

+105
-5
lines changed

4 files changed

+105
-5
lines changed

src/TableStorage.Abstractions.TableEntityConverters/EntityConvert.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public static T FromTableEntity<T, TP, TR>(this DynamicTableEntity entity,
9595
var val = entity.Properties[propertyInfo.Name].PropertyAsObject;
9696

9797

98-
if (val != null && propertyInfo.PropertyType == typeof(DateTimeOffset))
98+
if (val != null && (propertyInfo.PropertyType == typeof(DateTimeOffset) || propertyInfo.PropertyType == typeof(DateTimeOffset?)))
9999
val = entity.Properties[propertyInfo.Name].DateTimeOffsetValue;
100100
if (val != null && propertyInfo.PropertyType == typeof(double))
101101
val = entity.Properties[propertyInfo.Name].DoubleValue;

src/TableStorage.Abstractions.TableEntityConverters/TableStorage.Abstractions.TableEntityConverters.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
<PropertyGroup>
44
<TargetFrameworks>netstandard2.0;netcoreapp2.0;net462</TargetFrameworks>
5-
<Version>1.1.2</Version>
5+
<Version>1.1.3</Version>
66
<Authors>Giovanni Galbo</Authors>
77
<Company>Giovanni Galbo</Company>
88
<Description>Easily convert POCOs (Plain Old CLR Objects) to Azure Table Storage TableEntities and vice versa. This version is for .net core</Description>
9-
<Copyright>Giovanni Galbo © 2017</Copyright>
9+
<Copyright>Giovanni Galbo © 2018</Copyright>
1010
<PackageLicenseUrl>https://github.com/giometrix/TableStorage.Abstractions.TableEntityConverters/blob/master/LICENSE</PackageLicenseUrl>
1111
<PackageProjectUrl>https://github.com/giometrix/TableStorage.Abstractions.TableEntityConverters</PackageProjectUrl>
1212
<RepositoryUrl>https://github.com/giometrix/TableStorage.Abstractions.TableEntityConverters</RepositoryUrl>
1313
<PackageTags>table-storage azure-table-storage poco table-entities</PackageTags>
14-
<PackageReleaseNotes>This release introduces the ability to ignore properties when converting to an TableEntity. You'd do this if you don't want to save certain properties to Azure Table Storage. This release also was updated to .net standard 2.0.</PackageReleaseNotes>
14+
<PackageReleaseNotes>Bug fix with nullable datetimeoffset</PackageReleaseNotes>
1515
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
1616
</PropertyGroup>
1717

src/TableStorage.Abstractions.UnitTests/Employee.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,10 @@ public Employee()
2626
public DateTimeOffset HireDate { get; set; }
2727
public DateTimeOffset? TermDate { get; set; }
2828
public Department Department { get; set; }
29+
30+
// extra stuff
31+
public DateTime ADateTime { get; set; }
32+
public DateTime? ANullableDateTime { get; set; }
33+
public int? ANullableInt { get; set; }
2934
}
3035
}

src/TableStorage.Abstractions.UnitTests/EntityConvertTests.cs

Lines changed: 96 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ public void convert_to_entity_table()
3131
Assert.Equal(true, tableEntity.Properties.ContainsKey("DepartmentJson"));
3232
}
3333

34-
3534
[Fact]
3635
public void convert_to_entity_table_explicit_keys()
3736
{
@@ -74,6 +73,102 @@ public void convert_from_entity_table()
7473
Assert.Equal(Guid.Parse("12ae85a4-7131-4e8c-af63-074b066412e0"), employee.Department.OptionalId);
7574
}
7675

76+
[Fact]
77+
public void convert_from_entity_table_with_nullable_datetimeoffset_with_value()
78+
{
79+
var emp = new Employee()
80+
{
81+
Company = "Microsoft",
82+
Name = "John Smith",
83+
Department = new Department
84+
{
85+
Name = "QA",
86+
Id = 1,
87+
OptionalId = Guid.Parse("12ae85a4-7131-4e8c-af63-074b066412e0")
88+
},
89+
Id = 42,
90+
ExternalId = Guid.Parse("e3bf64f4-0537-495c-b3bf-148259d7ed36"),
91+
HireDate = DateTimeOffset.Parse("Thursday, January 31, 2008 "),
92+
TermDate = DateTimeOffset.Parse("Wednesday, January 31, 2018")
93+
};
94+
var tableEntity = emp.ToTableEntity(e => e.Company, e => e.Id);
95+
var employee = tableEntity.FromTableEntity<Employee, string, int>(e => e.Company, e => e.Id);
96+
Assert.Equal(Guid.Parse("12ae85a4-7131-4e8c-af63-074b066412e0"), employee.Department.OptionalId);
97+
}
98+
99+
100+
[Fact]
101+
public void convert_from_entity_table_with_datetime()
102+
{
103+
var emp = new Employee()
104+
{
105+
Company = "Microsoft",
106+
Name = "John Smith",
107+
Department = new Department
108+
{
109+
Name = "QA",
110+
Id = 1,
111+
OptionalId = Guid.Parse("12ae85a4-7131-4e8c-af63-074b066412e0")
112+
},
113+
Id = 42,
114+
ExternalId = Guid.Parse("e3bf64f4-0537-495c-b3bf-148259d7ed36"),
115+
HireDate = DateTimeOffset.Parse("Thursday, January 31, 2008 "),
116+
ADateTime = DateTime.Parse("Wednesday, January 31, 2018")
117+
};
118+
var tableEntity = emp.ToTableEntity(e => e.Company, e => e.Id);
119+
var employee = tableEntity.FromTableEntity<Employee, string, int>(e => e.Company, e => e.Id);
120+
Assert.Equal(Guid.Parse("12ae85a4-7131-4e8c-af63-074b066412e0"), employee.Department.OptionalId);
121+
}
122+
123+
124+
[Fact]
125+
public void convert_from_entity_table_with_nullable_datetime_with_value()
126+
{
127+
var emp = new Employee()
128+
{
129+
Company = "Microsoft",
130+
Name = "John Smith",
131+
Department = new Department
132+
{
133+
Name = "QA",
134+
Id = 1,
135+
OptionalId = Guid.Parse("12ae85a4-7131-4e8c-af63-074b066412e0")
136+
},
137+
Id = 42,
138+
ExternalId = Guid.Parse("e3bf64f4-0537-495c-b3bf-148259d7ed36"),
139+
HireDate = DateTimeOffset.Parse("Thursday, January 31, 2008 "),
140+
ANullableDateTime = DateTime.Parse("Wednesday, January 31, 2018")
141+
};
142+
var tableEntity = emp.ToTableEntity(e => e.Company, e => e.Id);
143+
var employee = tableEntity.FromTableEntity<Employee, string, int>(e => e.Company, e => e.Id);
144+
Assert.Equal(Guid.Parse("12ae85a4-7131-4e8c-af63-074b066412e0"), employee.Department.OptionalId);
145+
}
146+
147+
148+
[Fact]
149+
public void convert_from_entity_table_with_nullable_int_with_value()
150+
{
151+
var emp = new Employee()
152+
{
153+
Company = "Microsoft",
154+
Name = "John Smith",
155+
Department = new Department
156+
{
157+
Name = "QA",
158+
Id = 1,
159+
OptionalId = Guid.Parse("12ae85a4-7131-4e8c-af63-074b066412e0")
160+
},
161+
Id = 42,
162+
ExternalId = Guid.Parse("e3bf64f4-0537-495c-b3bf-148259d7ed36"),
163+
HireDate = DateTimeOffset.Parse("Thursday, January 31, 2008 "),
164+
ANullableDateTime = DateTime.Parse("Wednesday, January 31, 2018"),
165+
ANullableInt = 42
166+
};
167+
var tableEntity = emp.ToTableEntity(e => e.Company, e => e.Id);
168+
var employee = tableEntity.FromTableEntity<Employee, string, int>(e => e.Company, e => e.Id);
169+
Assert.Equal(Guid.Parse("12ae85a4-7131-4e8c-af63-074b066412e0"), employee.Department.OptionalId);
170+
}
171+
77172
[Fact]
78173
public void convert_from_entity_table_complex_key()
79174
{

0 commit comments

Comments
 (0)