Fix tests.

This commit is contained in:
Mohammadreza Taikandi 2021-07-02 09:24:46 +01:00
parent 0ad89b0d6b
commit 1bec4fbc64
6 changed files with 33 additions and 36 deletions

View File

@ -28,7 +28,7 @@ namespace MapTo.Tests.Extensions
.AppendLine(); .AppendLine();
var lines = s.ToString().Split(Environment.NewLine); var lines = s.ToString().Split(Environment.NewLine);
var lineNumber = 1; var lineNumber = 0;
foreach (var line in lines) foreach (var line in lines)
{ {
builder.AppendFormat("{0:00}: {1}", lineNumber, line).AppendLine(); builder.AppendFormat("{0:00}: {1}", lineNumber, line).AppendLine();

View File

@ -41,7 +41,7 @@ namespace MapTo.Tests.Extensions
internal static void ShouldBeSuccessful(this IEnumerable<Diagnostic> diagnostics, Compilation? compilation = null, IEnumerable<string>? ignoreDiagnosticsIds = null) internal static void ShouldBeSuccessful(this IEnumerable<Diagnostic> diagnostics, Compilation? compilation = null, IEnumerable<string>? ignoreDiagnosticsIds = null)
{ {
var actual = diagnostics 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(); .Select(c => $"{c.Severity}: {c.Location.GetLineSpan()} - {c.GetMessage()}").ToArray();
if (!actual.Any()) if (!actual.Any())

View File

@ -52,10 +52,10 @@ namespace MapTo
var expectedResult = @" var expectedResult = @"
partial class Foo partial class Foo
{ {
public Foo(Baz baz) public Foo(Test.Models.Baz baz)
: this(new MappingContext(), 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 (context == null) throw new ArgumentNullException(nameof(context));
if (baz == null) throw new ArgumentNullException(nameof(baz)); if (baz == null) throw new ArgumentNullException(nameof(baz));

View File

@ -62,10 +62,10 @@ namespace MapTo
var expectedResult = @" var expectedResult = @"
partial class Foo partial class Foo
{ {
public Foo(Baz baz) public Foo(Test.Models.Baz baz)
: this(new MappingContext(), 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 (context == null) throw new ArgumentNullException(nameof(context));
if (baz == null) throw new ArgumentNullException(nameof(baz)); if (baz == null) throw new ArgumentNullException(nameof(baz));

View File

@ -75,16 +75,16 @@ namespace MapTo
var expectedExtension = @" var expectedExtension = @"
internal static partial class BazToFooExtensions 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); return baz == null ? null : new Foo(baz);
} }
}".Trim(); }".Trim();
var expectedFactory = @" var expectedFactory = @"
internal static Foo From(Baz baz) internal static Foo From(Test.Models.Baz baz)
{ {
return baz == null ? null : MappingContext.Create<Baz, Foo>(baz); return baz == null ? null : MappingContext.Create<Test.Models.Baz, Foo>(baz);
}".Trim(); }".Trim();
// Act // Act
@ -129,10 +129,10 @@ namespace Test
partial class Foo partial class Foo
{ {
public Foo(Baz baz) public Foo(Test.Baz baz)
: this(new MappingContext(), 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 (context == null) throw new ArgumentNullException(nameof(context));
if (baz == null) throw new ArgumentNullException(nameof(baz)); if (baz == null) throw new ArgumentNullException(nameof(baz));
@ -205,10 +205,10 @@ namespace Test
partial class Foo partial class Foo
{ {
public Foo(Baz baz) public Foo(Test.Baz baz)
: this(new MappingContext(), 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 (context == null) throw new ArgumentNullException(nameof(context));
if (baz == null) throw new ArgumentNullException(nameof(baz)); if (baz == null) throw new ArgumentNullException(nameof(baz));
@ -262,7 +262,6 @@ namespace Test
// <auto-generated /> // <auto-generated />
namespace Test namespace Test
{ {
using Bazaar;
using MapTo; using MapTo;
using System; using System;
"; ";
@ -284,10 +283,10 @@ namespace Test
const string expectedResult = @" const string expectedResult = @"
partial class Foo partial class Foo
{ {
public Foo(Baz baz) public Foo(Test.Models.Baz baz)
: this(new MappingContext(), 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 (context == null) throw new ArgumentNullException(nameof(context));
if (baz == null) throw new ArgumentNullException(nameof(baz)); if (baz == null) throw new ArgumentNullException(nameof(baz));
@ -315,9 +314,9 @@ namespace Test
var source = GetSourceText(); var source = GetSourceText();
const string expectedResult = @" const string expectedResult = @"
public static Foo From(Baz baz) public static Foo From(Test.Models.Baz baz)
{ {
return baz == null ? null : MappingContext.Create<Baz, Foo>(baz); return baz == null ? null : MappingContext.Create<Test.Models.Baz, Foo>(baz);
} }
"; ";
@ -338,7 +337,7 @@ namespace Test
const string expectedResult = @" const string expectedResult = @"
public static partial class BazToFooExtensions 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); return baz == null ? null : new Foo(baz);
} }
@ -375,10 +374,10 @@ namespace Test
var expectedResult = @" var expectedResult = @"
partial class Foo partial class Foo
{ {
public Foo(Baz baz) public Foo(Test.Baz baz)
: this(new MappingContext(), 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 (context == null) throw new ArgumentNullException(nameof(context));
if (baz == null) throw new ArgumentNullException(nameof(baz)); if (baz == null) throw new ArgumentNullException(nameof(baz));
@ -388,7 +387,7 @@ namespace Test
Prop1 = baz.Prop1; Prop1 = baz.Prop1;
Prop2 = baz.Prop2; Prop2 = baz.Prop2;
Prop3 = baz.Prop3; Prop3 = baz.Prop3;
InnerProp1 = context.MapFromWithContext<A, B>(baz.InnerProp1); InnerProp1 = context.MapFromWithContext<Test.A, B>(baz.InnerProp1);
} }
".Trim(); ".Trim();
@ -467,10 +466,10 @@ namespace Test
const string expectedResult = @" const string expectedResult = @"
partial class Foo partial class Foo
{ {
public Foo(Baz baz) public Foo(Test.Models.Baz baz)
: this(new MappingContext(), 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 (context == null) throw new ArgumentNullException(nameof(context));
if (baz == null) throw new ArgumentNullException(nameof(baz)); if (baz == null) throw new ArgumentNullException(nameof(baz));
@ -499,7 +498,7 @@ namespace Test
var sources = GetEmployeeManagerSourceText(); var sources = GetEmployeeManagerSourceText();
const string expectedResult = @" 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 (context == null) throw new ArgumentNullException(nameof(context));
if (manager == null) throw new ArgumentNullException(nameof(manager)); if (manager == null) throw new ArgumentNullException(nameof(manager));
@ -507,7 +506,7 @@ private protected ManagerViewModel(MappingContext context, Manager manager) : ba
context.Register(manager, this); context.Register(manager, this);
Level = manager.Level; Level = manager.Level;
Employees = manager.Employees.Select(context.MapFromWithContext<Employee, EmployeeViewModel>).ToList(); Employees = manager.Employees.Select(context.MapFromWithContext<Test.Data.Models.Employee, EmployeeViewModel>).ToList();
} }
"; ";
@ -533,14 +532,13 @@ namespace Test.ViewModels
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Test.Data.Models;
partial class ManagerViewModel partial class ManagerViewModel
{ {
public ManagerViewModel(Manager manager) public ManagerViewModel(Test.Data.Models.Manager manager)
: this(new MappingContext(), 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 (context == null) throw new ArgumentNullException(nameof(context));
if (manager == null) throw new ArgumentNullException(nameof(manager)); if (manager == null) throw new ArgumentNullException(nameof(manager));
@ -548,7 +546,7 @@ namespace Test.ViewModels
context.Register(manager, this); context.Register(manager, this);
Level = manager.Level; Level = manager.Level;
Employees = manager.Employees.Select(context.MapFromWithContext<Employee, EmployeeViewModel>).ToList(); Employees = manager.Employees.Select(context.MapFromWithContext<Test.Data.Models.Employee, EmployeeViewModel>).ToList();
} }
"; ";
@ -573,15 +571,14 @@ namespace Test.ViewModels2
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Test.Data.Models;
using Test.ViewModels; using Test.ViewModels;
partial class ManagerViewModel partial class ManagerViewModel
{ {
public ManagerViewModel(Manager manager) public ManagerViewModel(Test.Data.Models.Manager manager)
: this(new MappingContext(), 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 (context == null) throw new ArgumentNullException(nameof(context));
if (manager == null) throw new ArgumentNullException(nameof(manager)); if (manager == null) throw new ArgumentNullException(nameof(manager));
@ -589,7 +586,7 @@ namespace Test.ViewModels2
context.Register(manager, this); context.Register(manager, this);
Level = manager.Level; Level = manager.Level;
Employees = manager.Employees.Select(context.MapFromWithContext<Employee, EmployeeViewModel>).ToList(); Employees = manager.Employees.Select(context.MapFromWithContext<Test.Data.Models.Employee, EmployeeViewModel>).ToList();
} }
"; ";

View File

@ -219,10 +219,10 @@ namespace Test
var expectedResult = @" var expectedResult = @"
partial class Foo partial class Foo
{ {
public Foo(Baz baz) public Foo(Test.Models.Baz baz)
: this(new MappingContext(), 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 (context == null) throw new ArgumentNullException(nameof(context));
if (baz == null) throw new ArgumentNullException(nameof(baz)); if (baz == null) throw new ArgumentNullException(nameof(baz));