XMapper.Testing 3.0.4

.NET 6.0
NuGet\Install-Package XMapper.Testing -Version 3.0.4
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.
dotnet add package XMapper.Testing --version 3.0.4
<PackageReference Include="XMapper.Testing" Version="3.0.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add XMapper.Testing --version 3.0.4
#r "nuget: XMapper.Testing, 3.0.4"
#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=3.0.4

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


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.


  1. Assign your mappers to static fields or static properties:
using XMapper;

namespace DummyAssembly1;

public class Class1
    private static readonly XMapper<DummyA, DummyB> MapperField =
        new XMapper<DummyA, DummyB>(PropertyList.Target)
        .IgnoreTargetProperty(x => x.Id);
  1. Test all mappers via a single method call inside a unit test:
using XMapper.Testing;
using Xunit;
using Xunit.Abstractions;

public class XMapperTests
    private readonly ITestOutputHelper _testOutputHelper;
    public XMapperTests(ITestOutputHelper testOutputHelper)
        _testOutputHelper = testOutputHelper;

    public void AllAreValid()
        new XMapperValidator(_testOutputHelper.WriteLine).AllAreValidInAssembly("DummyAssembly1", TestCases.All);

In case the unit test passes, the Standard Output in Visual Studio's Test Explorer will show something like:

Start collecting XMapper instance storage locations (static fields/properties).
Found 2 XMapper instance storage locations to test.
Validating 'DummyAssembly4.Class1.MyValidMapper1'.
Test case: AppDefaults
Test case: NotNullDefaults
Test case: TargetNullDefaults
Test case: NullDefaults
Test case: NoPublicFields
Validating 'DummyAssembly4.Class1.MyValidMapper2'.
Test case: AppDefaults
Test case: NotNullDefaults
Test case: TargetNullDefaults
Test case: NullDefaults
Test case: NoPublicFields
Finished validating all XMapper instances.

All assert options

AllAreValidInAssembly("Project1", TestCases.All);

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

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

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

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

// exclude one test case:
AllAreValidInAssembly("Project1", TestCases.All & ~TestCases.NoPublicFields);

// only validate specific mappers:
IsValid(MyProject1.Class1._someStaticFieldWithMapper, TestCases.All);

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

Product Versions
.NET 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 89 4/24/2022
3.0.3 86 4/23/2022
3.0.2 94 4/20/2022
3.0.1 95 4/19/2022
3.0.0 86 4/17/2022
2.0.2 79 4/16/2022
2.0.1 83 4/16/2022
2.0.0 98 4/13/2022
1.0.0 87 4/11/2022

IMPORTANT: major and minor version are a copy of the `XMapper` package's major and minor version.
     Only the revision number of `XMapper.Testing` is independent of `XMapper`.
     See https://github.com/XMapper/XMapper.Testing/blob/main/CHANGELOG.md for release notes.