From 1bec4fbc6474404bf630c32dbd03b485c3b2f30e Mon Sep 17 00:00:00 2001 From: Mohammadreza Taikandi Date: Fri, 2 Jul 2021 09:24:46 +0100 Subject: [PATCH] Fix tests. --- .../Extensions/RoslynExtensions.cs | 2 +- .../Extensions/ShouldlyExtensions.cs | 2 +- .../IgnorePropertyAttributeTests.cs | 4 +- test/MapTo.Tests/MapPropertyTests.cs | 4 +- test/MapTo.Tests/MapToTests.cs | 53 +++++++++---------- test/MapTo.Tests/MapTypeConverterTests.cs | 4 +- 6 files changed, 33 insertions(+), 36 deletions(-) diff --git a/test/MapTo.Tests/Extensions/RoslynExtensions.cs b/test/MapTo.Tests/Extensions/RoslynExtensions.cs index e21be73..ea3394e 100644 --- a/test/MapTo.Tests/Extensions/RoslynExtensions.cs +++ b/test/MapTo.Tests/Extensions/RoslynExtensions.cs @@ -28,7 +28,7 @@ namespace MapTo.Tests.Extensions .AppendLine(); var lines = s.ToString().Split(Environment.NewLine); - var lineNumber = 1; + var lineNumber = 0; foreach (var line in lines) { builder.AppendFormat("{0:00}: {1}", lineNumber, line).AppendLine(); diff --git a/test/MapTo.Tests/Extensions/ShouldlyExtensions.cs b/test/MapTo.Tests/Extensions/ShouldlyExtensions.cs index 0daa7a7..1ad43d4 100644 --- a/test/MapTo.Tests/Extensions/ShouldlyExtensions.cs +++ b/test/MapTo.Tests/Extensions/ShouldlyExtensions.cs @@ -41,7 +41,7 @@ namespace MapTo.Tests.Extensions internal static void ShouldBeSuccessful(this IEnumerable diagnostics, Compilation? compilation = null, IEnumerable? ignoreDiagnosticsIds = null) { var actual = diagnostics - .Where(d => (ignoreDiagnosticsIds is null || ignoreDiagnosticsIds.All(i => !d.Id.StartsWith(i) )) && (d.Severity == DiagnosticSeverity.Warning || d.Severity == DiagnosticSeverity.Error)) + .Where(d => (ignoreDiagnosticsIds is null || ignoreDiagnosticsIds.All(i => !d.Id.StartsWith(i) )) && (d.Severity is DiagnosticSeverity.Warning or DiagnosticSeverity.Error)) .Select(c => $"{c.Severity}: {c.Location.GetLineSpan()} - {c.GetMessage()}").ToArray(); if (!actual.Any()) diff --git a/test/MapTo.Tests/IgnorePropertyAttributeTests.cs b/test/MapTo.Tests/IgnorePropertyAttributeTests.cs index a28f9c0..a1dddb6 100644 --- a/test/MapTo.Tests/IgnorePropertyAttributeTests.cs +++ b/test/MapTo.Tests/IgnorePropertyAttributeTests.cs @@ -52,10 +52,10 @@ namespace MapTo var expectedResult = @" partial class Foo { - public Foo(Baz baz) + public Foo(Test.Models.Baz baz) : this(new MappingContext(), baz) { } - private protected Foo(MappingContext context, Baz baz) + private protected Foo(MappingContext context, Test.Models.Baz baz) { if (context == null) throw new ArgumentNullException(nameof(context)); if (baz == null) throw new ArgumentNullException(nameof(baz)); diff --git a/test/MapTo.Tests/MapPropertyTests.cs b/test/MapTo.Tests/MapPropertyTests.cs index 9bf8ca5..634818e 100644 --- a/test/MapTo.Tests/MapPropertyTests.cs +++ b/test/MapTo.Tests/MapPropertyTests.cs @@ -62,10 +62,10 @@ namespace MapTo var expectedResult = @" partial class Foo { - public Foo(Baz baz) + public Foo(Test.Models.Baz baz) : this(new MappingContext(), baz) { } - private protected Foo(MappingContext context, Baz baz) + private protected Foo(MappingContext context, Test.Models.Baz baz) { if (context == null) throw new ArgumentNullException(nameof(context)); if (baz == null) throw new ArgumentNullException(nameof(baz)); diff --git a/test/MapTo.Tests/MapToTests.cs b/test/MapTo.Tests/MapToTests.cs index c5e3d2f..4130e77 100644 --- a/test/MapTo.Tests/MapToTests.cs +++ b/test/MapTo.Tests/MapToTests.cs @@ -75,16 +75,16 @@ namespace MapTo var expectedExtension = @" internal static partial class BazToFooExtensions { - internal static Foo ToFoo(this Baz baz) + internal static Foo ToFoo(this Test.Models.Baz baz) { return baz == null ? null : new Foo(baz); } }".Trim(); var expectedFactory = @" - internal static Foo From(Baz baz) + internal static Foo From(Test.Models.Baz baz) { - return baz == null ? null : MappingContext.Create(baz); + return baz == null ? null : MappingContext.Create(baz); }".Trim(); // Act @@ -129,10 +129,10 @@ namespace Test partial class Foo { - public Foo(Baz baz) + public Foo(Test.Baz baz) : this(new MappingContext(), baz) { } - private protected Foo(MappingContext context, Baz baz) + private protected Foo(MappingContext context, Test.Baz baz) { if (context == null) throw new ArgumentNullException(nameof(context)); if (baz == null) throw new ArgumentNullException(nameof(baz)); @@ -205,10 +205,10 @@ namespace Test partial class Foo { - public Foo(Baz baz) + public Foo(Test.Baz baz) : this(new MappingContext(), baz) { } - private protected Foo(MappingContext context, Baz baz) + private protected Foo(MappingContext context, Test.Baz baz) { if (context == null) throw new ArgumentNullException(nameof(context)); if (baz == null) throw new ArgumentNullException(nameof(baz)); @@ -262,7 +262,6 @@ namespace Test // namespace Test { - using Bazaar; using MapTo; using System; "; @@ -284,10 +283,10 @@ namespace Test const string expectedResult = @" partial class Foo { - public Foo(Baz baz) + public Foo(Test.Models.Baz baz) : this(new MappingContext(), baz) { } - private protected Foo(MappingContext context, Baz baz) + private protected Foo(MappingContext context, Test.Models.Baz baz) { if (context == null) throw new ArgumentNullException(nameof(context)); if (baz == null) throw new ArgumentNullException(nameof(baz)); @@ -315,9 +314,9 @@ namespace Test var source = GetSourceText(); const string expectedResult = @" - public static Foo From(Baz baz) + public static Foo From(Test.Models.Baz baz) { - return baz == null ? null : MappingContext.Create(baz); + return baz == null ? null : MappingContext.Create(baz); } "; @@ -338,7 +337,7 @@ namespace Test const string expectedResult = @" public static partial class BazToFooExtensions { - public static Foo ToFoo(this Baz baz) + public static Foo ToFoo(this Test.Models.Baz baz) { return baz == null ? null : new Foo(baz); } @@ -375,10 +374,10 @@ namespace Test var expectedResult = @" partial class Foo { - public Foo(Baz baz) + public Foo(Test.Baz baz) : this(new MappingContext(), baz) { } - private protected Foo(MappingContext context, Baz baz) + private protected Foo(MappingContext context, Test.Baz baz) { if (context == null) throw new ArgumentNullException(nameof(context)); if (baz == null) throw new ArgumentNullException(nameof(baz)); @@ -388,7 +387,7 @@ namespace Test Prop1 = baz.Prop1; Prop2 = baz.Prop2; Prop3 = baz.Prop3; - InnerProp1 = context.MapFromWithContext(baz.InnerProp1); + InnerProp1 = context.MapFromWithContext(baz.InnerProp1); } ".Trim(); @@ -467,10 +466,10 @@ namespace Test const string expectedResult = @" partial class Foo { - public Foo(Baz baz) + public Foo(Test.Models.Baz baz) : this(new MappingContext(), baz) { } - private protected Foo(MappingContext context, Baz baz) + private protected Foo(MappingContext context, Test.Models.Baz baz) { if (context == null) throw new ArgumentNullException(nameof(context)); if (baz == null) throw new ArgumentNullException(nameof(baz)); @@ -499,7 +498,7 @@ namespace Test var sources = GetEmployeeManagerSourceText(); const string expectedResult = @" -private protected ManagerViewModel(MappingContext context, Manager manager) : base(context, manager) +private protected ManagerViewModel(MappingContext context, Test.Data.Models.Manager manager) : base(context, manager) { if (context == null) throw new ArgumentNullException(nameof(context)); if (manager == null) throw new ArgumentNullException(nameof(manager)); @@ -507,7 +506,7 @@ private protected ManagerViewModel(MappingContext context, Manager manager) : ba context.Register(manager, this); Level = manager.Level; - Employees = manager.Employees.Select(context.MapFromWithContext).ToList(); + Employees = manager.Employees.Select(context.MapFromWithContext).ToList(); } "; @@ -533,14 +532,13 @@ namespace Test.ViewModels using System; using System.Collections.Generic; using System.Linq; - using Test.Data.Models; partial class ManagerViewModel { - public ManagerViewModel(Manager manager) + public ManagerViewModel(Test.Data.Models.Manager manager) : this(new MappingContext(), manager) { } - private protected ManagerViewModel(MappingContext context, Manager manager) : base(context, manager) + private protected ManagerViewModel(MappingContext context, Test.Data.Models.Manager manager) : base(context, manager) { if (context == null) throw new ArgumentNullException(nameof(context)); if (manager == null) throw new ArgumentNullException(nameof(manager)); @@ -548,7 +546,7 @@ namespace Test.ViewModels context.Register(manager, this); Level = manager.Level; - Employees = manager.Employees.Select(context.MapFromWithContext).ToList(); + Employees = manager.Employees.Select(context.MapFromWithContext).ToList(); } "; @@ -573,15 +571,14 @@ namespace Test.ViewModels2 using System; using System.Collections.Generic; using System.Linq; - using Test.Data.Models; using Test.ViewModels; partial class ManagerViewModel { - public ManagerViewModel(Manager manager) + public ManagerViewModel(Test.Data.Models.Manager manager) : this(new MappingContext(), manager) { } - private protected ManagerViewModel(MappingContext context, Manager manager) : base(context, manager) + private protected ManagerViewModel(MappingContext context, Test.Data.Models.Manager manager) : base(context, manager) { if (context == null) throw new ArgumentNullException(nameof(context)); if (manager == null) throw new ArgumentNullException(nameof(manager)); @@ -589,7 +586,7 @@ namespace Test.ViewModels2 context.Register(manager, this); Level = manager.Level; - Employees = manager.Employees.Select(context.MapFromWithContext).ToList(); + Employees = manager.Employees.Select(context.MapFromWithContext).ToList(); } "; diff --git a/test/MapTo.Tests/MapTypeConverterTests.cs b/test/MapTo.Tests/MapTypeConverterTests.cs index c7a4720..abe0511 100644 --- a/test/MapTo.Tests/MapTypeConverterTests.cs +++ b/test/MapTo.Tests/MapTypeConverterTests.cs @@ -219,10 +219,10 @@ namespace Test var expectedResult = @" partial class Foo { - public Foo(Baz baz) + public Foo(Test.Models.Baz baz) : this(new MappingContext(), baz) { } - private protected Foo(MappingContext context, Baz baz) + private protected Foo(MappingContext context, Test.Models.Baz baz) { if (context == null) throw new ArgumentNullException(nameof(context)); if (baz == null) throw new ArgumentNullException(nameof(baz));