Skip to content

Commit 03d7edc

Browse files
authored
chore: Merge pull request #965 from leno23/test/compile-open-generic-mapping-925
test: ensure Compile skips open generic mapping rules (#925)
2 parents de64044 + 2c37aa1 commit 03d7edc

1 file changed

Lines changed: 28 additions & 3 deletions

File tree

src/Mapster.Tests/WhenMappingWithOpenGenerics.cs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,30 @@ public void Setting_From_OpenGeneric_Has_No_SideEffect()
2424
config
2525
.NewConfig(typeof(A<>), typeof(B<>))
2626
.Map("BProperty", "AProperty");
27-
28-
config.Compile(); // is not throw exception
29-
27+
3028
var a = new A<C> { AProperty = "A" };
3129
var c = new C { BProperty = "C" };
3230
var b = a.Adapt<B<C>>(config); // successful mapping
3331
var cCopy = c.Adapt<C>(config);
3432
}
3533

34+
/// <summary>
35+
/// https://github.com/MapsterMapper/Mapster/issues/925
36+
/// </summary>
37+
[TestMethod]
38+
public void Compile_With_Open_Generic_Mapping_Does_Not_Throw()
39+
{
40+
var config = new TypeAdapterConfig();
41+
config.ForType(typeof(ClassA<>), typeof(ClassB<>));
42+
43+
Should.NotThrow(() => config.Compile());
44+
45+
var classA = new ClassA<int> { Variable = 15 };
46+
var classB = classA.Adapt<ClassB<int>>(config);
47+
48+
classB.Variable.ShouldBe(15);
49+
}
50+
3651
[TestMethod]
3752
public void MapOpenGenericsUseInherits()
3853
{
@@ -102,5 +117,15 @@ class A<T> { public string AProperty { get; set; } }
102117
class B<T> { public string BProperty { get; set; } }
103118

104119
class C { public string BProperty { get; set; } }
120+
121+
class ClassA<T>
122+
{
123+
public T? Variable { get; set; }
124+
}
125+
126+
class ClassB<T>
127+
{
128+
public T? Variable { get; set; }
129+
}
105130
}
106131
}

0 commit comments

Comments
 (0)