Skip to content

Commit

Permalink
Update UseStaticGenericMapperStaticMethodFromAnotherAssembly
Browse files Browse the repository at this point in the history
  • Loading branch information
trejjam committed Jul 26, 2024
1 parent 1b2d702 commit b5ee4f9
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions test/Riok.Mapperly.Tests/Mapping/UseStaticMapperTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,8 @@ public partial class Mapper
}

[Theory]
[InlineData(true)]
[InlineData(false)]
[InlineData(true)] // Usually when your IDE runs the source generator (references are other syntax trees)
[InlineData(false)] // When compiler produces final assembly (references are compiled assemblies)
public void UseStaticGenericMapperStaticMethodFromAnotherAssembly(bool asCompilationReference)
{
var testDependencySource = TestSourceBuilder.SyntaxTree(
Expand Down Expand Up @@ -416,20 +416,39 @@ public class Target
}
"""
);
TestHelper
var result = TestHelper
.GenerateMapper(source, TestHelperOptions.AllowDiagnostics, additionalAssemblies: [testDependencyAssembly])
.Should()
.HaveDiagnostic(DiagnosticDescriptors.QueryableProjectionMappingCannotInline)
.HaveMethodBody(
.Should();

if (asCompilationReference)
{
result.HaveMethodBody(
"ProjectToTarget",
"""
#nullable disable
return System.Linq.Queryable.Select(source, x => new global::Mapper.Target()
{
DateTime = global::Riok.Mapperly.TestDependency.Mapper.DateTimeMapper.MapToDateTimeOffset(x.DateTime),
DateTime = new global::System.DateTimeOffset(x.DateTime, global::System.TimeSpan.Zero),
});
#nullable enable
"""
);
}
else
{
result
.HaveDiagnostic(DiagnosticDescriptors.QueryableProjectionMappingCannotInline)
.HaveMethodBody(
"ProjectToTarget",
"""
#nullable disable
return System.Linq.Queryable.Select(source, x => new global::Mapper.Target()
{
DateTime = global::Riok.Mapperly.TestDependency.Mapper.DateTimeMapper.MapToDateTimeOffset(x.DateTime),
});
#nullable enable
"""
);
}
}
}

0 comments on commit b5ee4f9

Please sign in to comment.