public static async Task GenerateWithClassesAsync() { var code = @"using InlineMapping; public class Destination { public string Id { get; set; } } [MapTo(typeof(Destination))] public class Source { public string Id { get; set; } }"; var generatedCode = @"using System; #nullable enable public static partial class SourceMapToExtensions { public static Destination MapToDestination(this Source self) => self is null ? throw new ArgumentNullException(nameof(self)) : new Destination { Id = self.Id, }; } "; await TestAssistants.RunAsync(code, new[] { (typeof(MapGenerator), "Source_To_Destination_Map.g.cs", generatedCode) },
public static async Task MapWhenDuplicateMappingsExistAsync() { var code = @"using InlineMapping; [assembly: Map(typeof(Source), typeof(Destination))] [MapTo(typeof(Destination))] public class Source { public int Id { get; set; } } public class Destination { public int Id { get; set; } }"; var generatedCode = @"using System; #nullable enable public static partial class SourceMapToExtensions { public static Destination MapToDestination(this Source self) => self is null ? throw new ArgumentNullException(nameof(self)) : new Destination { Id = self.Id, }; } "; var duplicateDiagnostic = new DiagnosticResult(DuplicatedAttributeDiagnostic.Id, DiagnosticSeverity.Warning) .WithSpan(5, 2, 5, 28).WithArguments("Map(typeof(Source), typeof(Destination))"); await TestAssistants.RunAsync(code, new[] { (typeof(MapGenerator), "Source_To_Destination_Map.g.cs", generatedCode) },