XMapper.Testing 2.0.1

.NET 5.0
There is a newer version of this package available.
See the version list below for details.
dotnet add package XMapper.Testing --version 2.0.1
NuGet\Install-Package XMapper.Testing -Version 2.0.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="XMapper.Testing" Version="2.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add XMapper.Testing --version 2.0.1
#r "nuget: XMapper.Testing, 2.0.1"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install XMapper.Testing as a Cake Addin
#addin nuget:?package=XMapper.Testing&version=2.0.1

// Install XMapper.Testing as a Cake Tool
#tool nuget:?package=XMapper.Testing&version=2.0.1

XMapper.Testing

Automate the testing of all your object-to-object mappers with one line of unit test code. <p align="center"> <img src="https://avatars.githubusercontent.com/u/103217522?s=150&v=4" alt="XMapper logo"/> </p>

Available via NuGet.

For more information about creating and using a mapper, see XMapper.

Example

  1. Define your mappers as static fields or static properties:
using XMapper;

namespace DummyAssembly1;

public class Class1 // An example of an incomplete setup: DummyB.XStringB has no match.
{ 
    public static XMapper<DummyA, DummyB> MapperField =
        new XMapper<DummyA, DummyB>(PropertyList.Target)
        .IgnoreTargetProperty(x => x.XStringA);
}

public class DummyA
{
    public int XInt { get; set; } = 1;
}

public class DummyB
{
    public int XInt { get; set; } = 2;
    public string XStringA { get; set; } = "A";
    public string XStringB { get; set; } = "B";
}
  1. Test all mappers via a single method call inside a unit test:
using XMapper.Testing;
using Xunit;

public class MyXMapperTests
{
    [Fact]
    public void AllAreValid()
    {
        AssertXMapper.AllAreValidInAssembly("DummyAssembly1", TestCases.All);
    }
}

All assert options

using XMapper.Testing;


// and inside a unit test method, call one of these:

AssertXMapper.AllAreValidInAssembly("Project1", TestCases.All);

AssertXMapper.AllAreValidInAssemblies(new [] { "MyProject1", "MyProject2" }, TestCases.All);

AssertXMapper.AllAreValidInAssembly(Assembly.Load("AnotherAssembly"), TestCases.All); 

AssertXMapper.AllAreValidInAssemblies(new [] { Assembly.Load("MyAssembly1"), Assembly.Load("MyAssembly2") }, TestCases.All);


// or only validate specific mappers:

AssertXMapper.IsValid(mapper, TestCases.All);

mapper.IsValid(TestCases.All)); // extension method


// or specify only specific test cases from the TestCases flags enum:
AssertXMapper.AllAreValidInAssembly("Project1", TestCases.NullDefaults | TestCases.NotNullDefaults | TestCases.TargetReferenceTypeMembersNull);

Hovering over methods and TestCases enum values in your editor will provide guiding documentation.

Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.0.4 171 4/24/2022
3.0.3 169 4/23/2022
3.0.2 177 4/20/2022
3.0.1 177 4/19/2022
3.0.0 168 4/17/2022
2.0.2 163 4/16/2022
2.0.1 167 4/16/2022
2.0.0 175 4/13/2022
1.0.0 170 4/11/2022

See CHANGELOG.md at GitHub for release notes.