Skip to content

Commit 25b6b9c

Browse files
committed
Make Cache public again && changed GetInstanceCache to internal + Add new test
1 parent 9a41ffb commit 25b6b9c

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using NUnit.Framework;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Dynamic;
5+
using System.Linq;
6+
using System.Text;
7+
8+
namespace Slapper.Tests
9+
{
10+
[TestFixture]
11+
class MapUniqueChildsIdTest
12+
{
13+
public class NameValue
14+
{
15+
public int Id { get; set; }
16+
public string Name { get; set; }
17+
18+
public IEnumerable<NameValue> Phones { get; set; }
19+
public IEnumerable<NameValue> Emails { get; set; }
20+
}
21+
22+
[Test]
23+
public void Can_Map_DifferentsRows_to_Same_object()
24+
{
25+
dynamic dynamicCustomer = new ExpandoObject();
26+
dynamicCustomer.Id = 1;
27+
dynamicCustomer.Name = "Clark";
28+
dynamicCustomer.Phones_Id = 1;
29+
dynamicCustomer.Phones_Name = "88888";
30+
dynamicCustomer.Emails_Id = "1";
31+
dynamicCustomer.Emails_Name = "[email protected]";
32+
33+
dynamic dynamicCustomer2 = new ExpandoObject();
34+
dynamicCustomer2.Id = 1;
35+
dynamicCustomer2.Name = "Clark";
36+
dynamicCustomer2.Phones_Id = 2;
37+
dynamicCustomer2.Phones_Name = "99999";
38+
dynamicCustomer2.Emails_Id = "2";
39+
dynamicCustomer2.Emails_Name = "[email protected]";
40+
41+
var list = new List<dynamic> { dynamicCustomer, dynamicCustomer2 };
42+
var customer = Slapper.AutoMapper.MapDynamic<NameValue>(list).FirstOrDefault();
43+
44+
Assert.NotNull(customer);
45+
Assert.AreNotEqual(customer.Emails.FirstOrDefault(e => e.Id == 1).Name, customer.Phones.FirstOrDefault(p => p.Id == 1).Name);
46+
}
47+
}
48+
}

Slapper.AutoMapper.Tests/Slapper.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
<Compile Include="MappingToGuidTests.cs" />
5252
<Compile Include="MappingToNullableTypesTests.cs" />
5353
<Compile Include="MappingToEnumTests.cs" />
54+
<Compile Include="MapUniqueChildsIdTest.cs" />
5455
<Compile Include="MatchingChildNameTests.cs" />
5556
<Compile Include="NoIdentifierTests.cs" />
5657
<Compile Include="NullTests.cs" />

Slapper.AutoMapper/Slapper.AutoMapper.Cache.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public static partial class AutoMapper
4343
/// <summary>
4444
/// Contains the methods and members responsible for this libraries caching concerns.
4545
/// </summary>
46-
internal static class Cache
46+
public static class Cache
4747
{
4848
/// <summary>
4949
/// The name of the instance cache stored in the logical call context.
@@ -115,7 +115,7 @@ public static void ClearInstanceCache()
115115
/// unique cache.
116116
/// </remarks>
117117
/// <returns>Instance Cache</returns>
118-
public static Dictionary<InternalHelpers.InstanceKey,object> GetInstanceCache()
118+
internal static Dictionary<InternalHelpers.InstanceKey,object> GetInstanceCache()
119119
{
120120
var instanceCache = InternalHelpers.ContextStorage.Get<Dictionary<InternalHelpers.InstanceKey, object>>(InstanceCacheContextStorageKey);
121121

0 commit comments

Comments
 (0)