Skip to content

Commit a8f9ab1

Browse files
committed
Add tests for dictionaries of complex types.
1 parent 2807a59 commit a8f9ab1

4 files changed

Lines changed: 34 additions & 1 deletion

File tree

AutoMapper.OData.EFCore.Tests/AirVinylData/AirVinylDatabaseInitializer.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,10 +302,16 @@ public static void SeedDatabase(AirVinylDbContext context)
302302

303303
context.DynamicVinylRecordProperties.Add(new DynamicProperty()
304304
{
305-
VinylRecordId = vinylRecords.First(r => r.Title == "Nevermind").VinylRecordId,//1,
305+
VinylRecordId = vinylRecords.First(r => r.Title == "Nevermind").VinylRecordId,//1
306306
Key = "Publisher",
307307
Value = "Geffen"
308308
});
309+
context.DynamicVinylRecordProperties.Add(new DynamicProperty()
310+
{
311+
VinylRecordId = vinylRecords.First(r => r.Title == "Nevermind").VinylRecordId,//1
312+
Key = "SomeData",
313+
Value = new { TestProp = "value" }
314+
});
309315
context.SaveChanges();
310316

311317
context.DoorManufacturers.AddRange(
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace AutoMapper.OData.EFCore.Tests.AirVinylModel
2+
{
3+
public class VinylLinkModel
4+
{
5+
public string Href { get; set; }
6+
}
7+
}

AutoMapper.OData.EFCore.Tests/AirVinylModel/VinylRecordModel.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,22 @@ public class VinylRecordModel
3333
= new List<DynamicPropertyModel>();
3434

3535
public IDictionary<string, object> Properties { get; set; }
36+
37+
private Dictionary<string, VinylLinkModel> _links;
38+
public IDictionary<string, VinylLinkModel> Links {
39+
get
40+
{
41+
if (_links is null)
42+
{
43+
_links = new Dictionary<string, VinylLinkModel>()
44+
{
45+
{ "buyingLink", new VinylLinkModel { Href = $"http://test/buy/{VinylRecordId}" } },
46+
{ "reviewLink", new VinylLinkModel { Href = $"http://test/review/{VinylRecordId}" } }
47+
};
48+
}
49+
50+
return _links;
51+
}
52+
}
3653
}
3754
}

AutoMapper.OData.EFCore.Tests/ExpansionTests.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using AutoMapper.AspNet.OData;
22
using AutoMapper.OData.EFCore.Tests.AirVinylData;
33
using AutoMapper.OData.EFCore.Tests.AirVinylModel;
4+
using LogicBuilder.Expressions.Utils;
45
using Microsoft.AspNetCore.Builder;
56
using Microsoft.AspNetCore.OData;
67
using Microsoft.AspNetCore.OData.Query;
@@ -58,7 +59,9 @@ void Test(ICollection<VinylRecordModel> collection)
5859

5960
//Complex types
6061
Assert.Contains(collection, vinyl => vinyl.Properties.Count != 0);
62+
Assert.Contains(collection, vinyl => vinyl.Properties.Any(p => !p.Value.GetType().IsLiteralType()));
6163
Assert.Contains(collection, vinyl => vinyl.DynamicVinylRecordProperties.Count != 0);
64+
Assert.Contains(collection, vinyl => vinyl.Links.Count != 0);
6265
}
6366
}
6467

0 commit comments

Comments
 (0)