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();
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();

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)
{
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())

View File

@ -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));

View File

@ -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));

View File

@ -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, Foo>(baz);
return baz == null ? null : MappingContext.Create<Test.Models.Baz, Foo>(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
// <auto-generated />
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, Foo>(baz);
return baz == null ? null : MappingContext.Create<Test.Models.Baz, Foo>(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<A, B>(baz.InnerProp1);
InnerProp1 = context.MapFromWithContext<Test.A, B>(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<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.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<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.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<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 = @"
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));