Skip to content

Commit 89c3f00

Browse files
committed
When_an_extension_methods_contraints_fail
1 parent 478fa21 commit 89c3f00

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/UnitTests/ExtensionMethods.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,24 @@
88
namespace AutoMapper.UnitTests
99
{
1010
interface IGeneric<T> { }
11+
public class When_an_extension_methods_contraints_fail : NonValidatingSpecBase
12+
{
13+
class Source : IGeneric<int>
14+
{
15+
}
16+
class Destination
17+
{
18+
public int Count { get; set; }
19+
}
20+
protected override MapperConfiguration CreateConfiguration() => new(c =>
21+
{
22+
c.IncludeSourceExtensionMethods(typeof(GenericExtensions));
23+
c.CreateMap<Source, Destination>();
24+
});
25+
[Fact]
26+
public void It_should_fail_validation() => new Action(AssertConfigurationIsValid).ShouldThrow<AutoMapperConfigurationException>()
27+
.Errors[0].UnmappedPropertyNames[0].ShouldBe(nameof(Destination.Count));
28+
}
1129
public class When_an_extension_method_is_for_a_base_interface : AutoMapperSpecBase
1230
{
1331
class Source : IGeneric<int>
@@ -27,7 +45,8 @@ class Destination
2745
}
2846
public static class GenericExtensions
2947
{
30-
private static int GetValue(this IGeneric<int> obj) => 12;
48+
private static int GetValue(this IGeneric<int> _) => 12;
49+
private static int Count<T>(this IGeneric<T> _) where T : IDisposable => 12;
3150
}
3251
public class When_an_extension_method_is_for_a_base_class : AutoMapperSpecBase
3352
{

0 commit comments

Comments
 (0)