SparkyTestHelpers.AutoMapper 1.2.0

.NET Standard 1.5
There is a newer version of this package available.
See the version list below for details.
Install-Package SparkyTestHelpers.AutoMapper -Version 1.2.0
dotnet add package SparkyTestHelpers.AutoMapper --version 1.2.0
<PackageReference Include="SparkyTestHelpers.AutoMapper" Version="1.2.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SparkyTestHelpers.AutoMapper --version 1.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: SparkyTestHelpers.AutoMapper, 1.2.0"
#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 SparkyTestHelpers.AutoMapper as a Cake Addin
#addin nuget:?package=SparkyTestHelpers.AutoMapper&version=1.2.0

// Install SparkyTestHelpers.AutoMapper as a Cake Tool
#tool nuget:?package=SparkyTestHelpers.AutoMapper&version=1.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

see also:


This package extends SparkyTestHelpers.Mapping with some additional extension methods specifically for use with AutoMapper.


MapTester<TSource, TDestination>

class SparkyTestHelpers.Mapping.MapTester<TSource, TDestination>

This class is for testing that properties were successfully "mapped" from one type to another.

Methods

  • MapTester<TSource, TDestination> WithLogging ([Action<String> action])
    • (optional) log property values when asserting. If called without an action, defaults to Console.WriteLine.
  • MapTester<TSource, TDestination> IgnoringMember (Expression<Func<TDestination, Object>> destExpression)
  • MapMemberTester<TSource, TDestination> WhereMember (Expression<Func<TDestination, Object>> destExpression)
  • void AssertMappedValues (TSource source, TDestination dest)

Extension Methods for AutoMapper

  • TDestination AssertAutoMappedValues (TSource source)
    • calls Mapper.Map<TSource, TDestination>(source), then AssertMappedValues()
  • TDestination AssertAutoMappedRandomValues ()
    • uses RandomValuesHelper to create a new TSource instance, calls Mapper.Map<TSource, TDestination>(source), then AssertMappedValues()

Static Methods

  • MapTester<TSource, TDestination> ForMap ()

Examples

using SparkyTestHelpers.Mapping;
    Foo foo = CreateAndPopulateTestFoo();
    Bar bar = Mapper.Map<Foo, Bar>(foo); 

    MapTester.ForMap<Foo, Bar>()
        .WithLogging()
        .IgnoringMember(dest => dest.DestOnlyProperty)
        .WhereMember(dest => dest.StatusCode).ShouldEqual(src => src.Status)
        .WhereMember(dest => dest.IsValid).ShouldEqualValue(true)
        .WhereMember(dest => dest.Percent).IsTestedBy((src, dest) => 
            Assert.AreEqual(src.Rate / 100, dest.Percent))
        .AssertMappedValues(foo, bar);

AutoMapper-specific methods:

using SparkyTestHelpers.AutoMapper;
    Baz baz = CreateAndPopulateTestBax();
    Qux qux = MapTester.ForMap<Baz, Qux>.AssertAutoMappedValues(baz);
    // Create & populate Baz, map to Qux, assert success all in one statement!
    MapTester.ForMap<Baz, Qux>.AssertAutoMappedRandomValues();

As with AutoMapper, you don't have to configure anything for properties with the same name/type in the source and destination instances. AssertMappedValues considers those successful if the source/destination values matter.

Use IgnoringMember for destination properties that are not mapped or which you need to test in another way.

Use WhereMember to "dot" to the ShouldEqual, ShouldEqualValue and IsTestedBy functions.


MapMemberTester<TSource, TDestination>

class SparkyTestHelpers.Mapping.MapMemberTester<TSource, TDestination>

This class is for testing that a property was successfully "mapped" from one type to another.

Methods

  • MapTester<TSource, TDestination> ShouldEqual (Expression<Func<TSource, Object>> sourceExpression)
    • use to verify destination property mapped from differently named source property(s)
  • MapTester<TSource, TDestination> ShouldEqualValue (Object value)
    • use to verify destination property using a constant or some other value not derived from the source
  • MapTester<TSource, TDestination> IsTestedBy (Action<TSource, TDestination> customTest)
    • use for custom complex validation that doesn't fit one of the other verification methods

RandomValuesHelper

class SparkyTestHelpers.Mapping.RandomValuesHelper

Test helper for updating class instance properties with random values (so you can fill a "source" instance without writing a lot of code).

Methods

  • T CreateInstanceWithRandomValues ()
  • T UpdatePropertiesWithRandomValues (T instance)

Example

using SparkyTestHelpers.Mapping;
    Foo foo = new RandomValuesHelper().CreateInstanceWithRandomValues<Foo>();

    var bar = new Bar();
    new RandomValuesHelper().UpdatePropertiesWithRandomValues(bar);
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
.NET Core netcoreapp1.0 netcoreapp1.1 netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard1.5 netstandard1.6 netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen30 tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
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
2.1.1 13,005 1/15/2019
2.1.0 466 1/15/2019
2.0.1 493 12/2/2018
2.0.0 462 11/22/2018
1.8.2 339 7/27/2019
1.8.1 1,105 1/15/2019
1.8.0 510 1/15/2019
1.7.1 5,681 6/2/2018
1.7.0 826 5/17/2018
1.6.3 716 5/16/2018
1.6.2 719 5/14/2018
1.6.0 698 5/11/2018
1.5.2 675 5/4/2018
1.5.1 794 4/27/2018
1.5.0 782 4/27/2018
1.4.0 648 4/21/2018
1.3.1 34,958 4/14/2018
1.3.0 783 4/14/2018
1.2.2 766 3/12/2018
1.2.1 610 2/21/2018
1.2.0 604 2/14/2018
1.0.0 643 2/13/2018

v1.2.0: Target .NET Standard 1.5