public static void CreateWhenDuplicateMappingExists() { 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 information = MappingInformationTests.GetInformation(code); Assert.Multiple(() => { Assert.That(information.Maps.Count, Is.EqualTo(1)); var(key, value) = information.Maps.First(); Assert.That(key.source.Name, Is.EqualTo("Source")); Assert.That(key.destination.Name, Is.EqualTo("Destination")); Assert.That(value.diagnostics.Length, Is.EqualTo(1)); Assert.That(value.diagnostics[0].Id, Is.EqualTo(DuplicatedAttributeDiagnostic.Id)); Assert.That(value.node, Is.Not.Null); Assert.That(value.maps.Length, Is.EqualTo(1)); }); }
public static void CreateWhenConstructorWithArgumentsExist() { var code = @"using InlineMapping; [assembly: Map(typeof(Source), typeof(Destination))] public class Source { public int Id { get; set; } } public class Destination { public Destination(int id) => this.Id = id; public int Id { get; set; } }"; var information = MappingInformationTests.GetInformation(code); Assert.Multiple(() => { Assert.That(information.Maps.Count, Is.EqualTo(1)); var(key, value) = information.Maps.First(); Assert.That(key.source.Name, Is.EqualTo("Source")); Assert.That(key.destination.Name, Is.EqualTo("Destination")); Assert.That(value.diagnostics.Length, Is.EqualTo(1)); Assert.That(value.diagnostics[0].Id, Is.EqualTo(NoArgumentConstructorDiagnostic.Id)); Assert.That(value.node, Is.Not.Null); Assert.That(value.maps.Length, Is.EqualTo(1)); }); }
public static void CreateWhenNoMapsExist() { var code = @"using InlineMapping; [assembly: Map(typeof(Source), typeof(Destination))] public class Source { public int Id { get; set; } } public class Destination { public string Name { get; set; } }"; var information = MappingInformationTests.GetInformation(code); Assert.Multiple(() => { Assert.That(information.Maps.Count, Is.EqualTo(1)); var(key, value) = information.Maps.First(); Assert.That(key.source.Name, Is.EqualTo("Source")); Assert.That(key.destination.Name, Is.EqualTo("Destination")); Assert.That(value.diagnostics.Length, Is.EqualTo(3)); Assert.That(value.diagnostics.Count(_ => _.Id == NoMatchDiagnostic.Id), Is.EqualTo(2)); Assert.That(value.diagnostics.Count(_ => _.Id == NoPropertyMapsFoundDiagnostic.Id), Is.EqualTo(1)); Assert.That(value.node, Is.Not.Null); Assert.That(value.maps.Length, Is.EqualTo(0)); }); }