Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/Mapster.Tests/WhenMappingWithOpenGenerics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,23 @@ public void Setting_From_OpenGeneric_Has_No_SideEffect()
var cCopy = c.Adapt<C>(config);
}

/// <summary>
/// https://github.com/MapsterMapper/Mapster/issues/925
/// </summary>
[TestMethod]
public void Compile_With_Open_Generic_Mapping_Does_Not_Throw()
{
var config = new TypeAdapterConfig();
config.ForType(typeof(ClassA<>), typeof(ClassB<>));

Should.NotThrow(() => config.Compile());

var classA = new ClassA<int> { Variable = 15 };
var classB = classA.Adapt<ClassB<int>>(config);

classB.Variable.ShouldBe(15);
}

[TestMethod]
public void MapOpenGenericsUseInherits()
{
Expand Down Expand Up @@ -102,5 +119,15 @@ class A<T> { public string AProperty { get; set; } }
class B<T> { public string BProperty { get; set; } }

class C { public string BProperty { get; set; } }

class ClassA<T>
{
public T? Variable { get; set; }
}

class ClassB<T>
{
public T? Variable { get; set; }
}
}
}