SparkyTestHelpers.Mapping
1.2.0
See the version list below for details.
dotnet add package SparkyTestHelpers.Mapping --version 1.2.0
NuGet\Install-Package SparkyTestHelpers.Mapping -Version 1.2.0
<PackageReference Include="SparkyTestHelpers.Mapping" Version="1.2.0" />
<PackageVersion Include="SparkyTestHelpers.Mapping" Version="1.2.0" />
<PackageReference Include="SparkyTestHelpers.Mapping" />
paket add SparkyTestHelpers.Mapping --version 1.2.0
#r "nuget: SparkyTestHelpers.Mapping, 1.2.0"
#addin nuget:?package=SparkyTestHelpers.Mapping&version=1.2.0
#tool nuget:?package=SparkyTestHelpers.Mapping&version=1.2.0
see also:
- SparkyTestHelpers.AutoMapper: Additional SparkyTestHelpers.Mapping extension methods for AutoMapper
- the rest of the "Sparky suite" of .NET utilities and test helpers
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)
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);
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 Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
.NET Core | netcoreapp1.0 was computed. netcoreapp1.1 was computed. netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard1.5 is compatible. netstandard1.6 was computed. netstandard2.0 was computed. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen30 was computed. tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 1.5
- NETStandard.Library (>= 1.6.1)
- SparkyTestHelpers (>= 1.2.0)
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 | 12,909 | 6/12/2022 |
1.12.1 | 77,069 | 7/27/2019 |
1.12.0 | 21,388 | 1/15/2019 |
1.11.0 | 724 | 1/3/2019 |
1.10.2 | 718 | 12/12/2018 |
1.10.1 | 1,499 | 12/2/2018 |
1.10.0 | 1,549 | 11/22/2018 |
1.9.0 | 810 | 10/20/2018 |
1.8.0 | 872 | 7/31/2018 |
1.7.2 | 6,798 | 6/2/2018 |
1.7.1 | 1,043 | 5/28/2018 |
1.7.0 | 1,933 | 5/17/2018 |
1.6.2 | 2,539 | 5/14/2018 |
1.6.1 | 1,094 | 5/14/2018 |
1.6.0 | 4,152 | 5/11/2018 |
1.5.2 | 1,800 | 5/3/2018 |
1.5.1 | 1,133 | 5/1/2018 |
1.5.0 | 1,790 | 4/27/2018 |
1.4.0 | 2,309 | 4/21/2018 |
1.3.0 | 1,165 | 4/21/2018 |
1.2.2 | 50,228 | 3/12/2018 |
1.2.1 | 1,803 | 2/21/2018 |
1.2.0 | 1,914 | 2/14/2018 |
1.0.0 | 1,848 | 2/13/2018 |
v1.2.0: Target .NET Standard 1.5