SparkyTestHelpers.Mapping
1.12.2
Install-Package SparkyTestHelpers.Mapping -Version 1.12.2
dotnet add package SparkyTestHelpers.Mapping --version 1.12.2
<PackageReference Include="SparkyTestHelpers.Mapping" Version="1.12.2" />
paket add SparkyTestHelpers.Mapping --version 1.12.2
#r "nuget: SparkyTestHelpers.Mapping, 1.12.2"
// Install SparkyTestHelpers.Mapping as a Cake Addin
#addin nuget:?package=SparkyTestHelpers.Mapping&version=1.12.2
// Install SparkyTestHelpers.Mapping as a Cake Tool
#tool nuget:?package=SparkyTestHelpers.Mapping&version=1.12.2
see also:
MapTester<TSource, TDestination>
class SparkyTestHelpers.Mapping.MapTester<TSource, TDestination>
This class is for testing that properties were successfully "mapped" from one type to another, either via AutoMapper or another automatic mapping framework, or by hand-written "destination.X = source.X;" code.
See SparkyTestHelpers.AutoMapper for additional extension methods specifically for working with AutoMapper.
Methods
- MapTester<TSource, TDestination> WithLogging(Action<String> action)
(optional) "Callback" action to log property values when asserting. If called without an action, defaults to Console.WriteLine. - MapTester<TSource, TDestination> IgnoringMember(Expression<Func<TDestination, Object>> destExpression)
- MapTester<TSource, TDestination> IgnoringMembers(params Expression<Func<TDestination, Object>>[] destExpressions)
- MapTester<TSource, TDestination> IgnoringMemberNamesStartingWith(string prefix)
- MapMemberTester<TSource, TDestination> WhereMember(Expression<Func<TDestination, Object>> destExpression)
- MapMemberTester<TSource, TDestination> WhereMember(Expression<Func<TDestination, Object>> destExpression)
- void AssertMappedValues(TSource source, TDestination dest)
throws exception if any source/destination map validation specifications fail, or if any destination properties aren�t either tested or IgnoreMember�d.
Static Methods
- MapTester<TSource, TDestination> ForMap()
Example
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);
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 match.
Use IgnoringMember, IgnoringMembers or IgnoringMemberNamesStartingWith 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> ShouldBeStringMatchFor(Expression<Func<TSource, Object>> sourceExpression)
use to verify the ".ToString()" values of the source and destination properties (useful for testing Enum mapping where the source/destination Enum types have the same names) - 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
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 |
-
.NETFramework 4.6.1
- SparkyTestHelpers (>= 1.5.3)
- SparkyTestHelpers.Populater (>= 1.3.3)
-
.NETStandard 1.5
- NETStandard.Library (>= 1.6.1)
- SparkyTestHelpers (>= 1.5.3)
- SparkyTestHelpers.Populater (>= 1.3.3)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on SparkyTestHelpers.Mapping:
Package | Downloads |
---|---|
SparkyTestHelpers.AutoMapper
Additional AutoMapper extension methods for SparkyTestHelpers.Mapping (Unit test helpers for asserting public properties on class instances "mapped" from one type to another have the correct values.) Version 1.x supports .NET Standard 1.5 and .NET Framework 4.5 Version 2.x supports .NET Standard 2.0 and .NET Framework 4.6 |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.12.2 | 76 | 6/12/2022 |
1.12.1 | 48,800 | 7/27/2019 |
1.12.0 | 14,529 | 1/15/2019 |
1.11.0 | 482 | 1/3/2019 |
1.10.2 | 465 | 12/12/2018 |
1.10.1 | 561 | 12/2/2018 |
1.10.0 | 581 | 11/22/2018 |
1.9.0 | 530 | 10/20/2018 |
1.8.0 | 575 | 7/31/2018 |
1.7.2 | 5,747 | 6/2/2018 |
1.7.1 | 671 | 5/28/2018 |
1.7.0 | 857 | 5/17/2018 |
1.6.2 | 876 | 5/14/2018 |
1.6.1 | 698 | 5/14/2018 |
1.6.0 | 755 | 5/11/2018 |
1.5.2 | 824 | 5/3/2018 |
1.5.1 | 739 | 5/1/2018 |
1.5.0 | 738 | 4/27/2018 |
1.4.0 | 802 | 4/21/2018 |
1.3.0 | 785 | 4/21/2018 |
1.2.2 | 32,266 | 3/12/2018 |
1.2.1 | 748 | 2/21/2018 |
1.2.0 | 839 | 2/14/2018 |
1.0.0 | 741 | 2/13/2018 |