diff --git a/test/Riok.Mapperly.Tests/Mapping/InstantiableMapperWithStaticMethodsTest.cs b/test/Riok.Mapperly.Tests/Mapping/InstantiableMapperWithStaticMethodsTest.cs index b4101c2e8a..bc448c3ce0 100644 --- a/test/Riok.Mapperly.Tests/Mapping/InstantiableMapperWithStaticMethodsTest.cs +++ b/test/Riok.Mapperly.Tests/Mapping/InstantiableMapperWithStaticMethodsTest.cs @@ -126,6 +126,63 @@ class B { public string StringValue { get; set; } } return TestHelper.VerifyGenerator(source); } + [Fact] + public Task UseStaticGenericMapperStaticMethod() + { + var source = TestSourceBuilder.CSharp( + """ + using Riok.Mapperly.Abstractions; + + record A(AExternal Value); + record B(BExternal Value); + record AExternal(); + record BExternal(); + + class OtherMapper { + public static BExternal ToBExternal(AExternal source) => new BExternal(); + } + + [Mapper] + [UseStaticMapper] + public partial class Mapper + { + static partial B Map(A source); + } + """ + ); + + return TestHelper.VerifyGenerator(source); + } + + [Fact] + public Task IgnoreInstanceMethodFromStaticMapper() + { + var source = TestSourceBuilder.CSharp( + """ + using Riok.Mapperly.Abstractions; + using Riok.Mapperly.Abstractions.ReferenceHandling; + + record A(AExternal Value); + record B(BExternal Value); + record AExternal(); + record BExternal(); + + class OtherMapper { + public BExternal ToBExternal(AExternal source) => new BExternal(); + } + + [Mapper] + [UseStaticMapper] + public partial class Mapper + { + static partial B Map(A source); + } + """ + ); + + return TestHelper.VerifyGenerator(source); + } + [Fact] public void MixedStaticMethodWithPartialInstanceMethod() { diff --git a/test/Riok.Mapperly.Tests/_snapshots/InstantiableMapperWithStaticMethodsTest.IgnoreInstanceMethodFromStaticMapper#Mapper.g.verified.cs b/test/Riok.Mapperly.Tests/_snapshots/InstantiableMapperWithStaticMethodsTest.IgnoreInstanceMethodFromStaticMapper#Mapper.g.verified.cs new file mode 100644 index 0000000000..890d6024f6 --- /dev/null +++ b/test/Riok.Mapperly.Tests/_snapshots/InstantiableMapperWithStaticMethodsTest.IgnoreInstanceMethodFromStaticMapper#Mapper.g.verified.cs @@ -0,0 +1,17 @@ +//HintName: Mapper.g.cs +// +#nullable enable +public partial class Mapper +{ + static partial global::B Map(global::A source) + { + var target = new global::B(MapToBExternal(source.Value)); + return target; + } + + private static global::BExternal MapToBExternal(global::AExternal source) + { + var target = new global::BExternal(); + return target; + } +} diff --git a/test/Riok.Mapperly.Tests/_snapshots/InstantiableMapperWithStaticMethodsTest.UseStaticGenericMapperStaticMethod#Mapper.g.verified.cs b/test/Riok.Mapperly.Tests/_snapshots/InstantiableMapperWithStaticMethodsTest.UseStaticGenericMapperStaticMethod#Mapper.g.verified.cs new file mode 100644 index 0000000000..a8b59243f4 --- /dev/null +++ b/test/Riok.Mapperly.Tests/_snapshots/InstantiableMapperWithStaticMethodsTest.UseStaticGenericMapperStaticMethod#Mapper.g.verified.cs @@ -0,0 +1,11 @@ +//HintName: Mapper.g.cs +// +#nullable enable +public partial class Mapper +{ + static partial global::B Map(global::A source) + { + var target = new global::B(global::OtherMapper.ToBExternal(source.Value)); + return target; + } +}