SparkyTestHelpers.AutoMapper
1.8.2
See the version list below for details.
dotnet add package SparkyTestHelpers.AutoMapper --version 1.8.2
NuGet\Install-Package SparkyTestHelpers.AutoMapper -Version 1.8.2
<PackageReference Include="SparkyTestHelpers.AutoMapper" Version="1.8.2" />
paket add SparkyTestHelpers.AutoMapper --version 1.8.2
#r "nuget: SparkyTestHelpers.AutoMapper, 1.8.2"
// Install SparkyTestHelpers.AutoMapper as a Cake Addin #addin nuget:?package=SparkyTestHelpers.AutoMapper&version=1.8.2 // Install SparkyTestHelpers.AutoMapper as a Cake Tool #tool nuget:?package=SparkyTestHelpers.AutoMapper&version=1.8.2
see also:
- SparkyTools.AutoMapper: AutoMapper syntax helpers
- SparkyTestHelpers.Mapping: Helpers for testing properties "mapped" from one type to another
- the rest of the "Sparky suite" of .NET utilities and test helpers
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) "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)
- 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.
Extension Methods for AutoMapper
- TDestination AssertAutoMappedValues(TSource source)
calls static Mapper.Map<TSource, TDestination>(source), then AssertMappedValues() - TDestination AssertAutoMappedValues(TSource source, IMapper mapper)
calls IMapper.Map<TSource, TDestination>(source), then AssertMappedValues() - TDestination AssertAutoMappedRandomValues()
uses RandomValuesHelper to create a new TSource instance, calls static Mapper.Map<TSource, TDestination>(source), then AssertMappedValues() - TDestination AssertAutoMappedRandomValues(IMapper mapper)
uses RandomValuesHelper to create a new TSource instance, calls IMapper.Map<TSource, TDestination>(source), then AssertMappedValues()
Static Methods
- *MapTester<TSource, TDestination> ForMap<TSource, TDestination>
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 matxh.
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> 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. |
.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 is compatible. 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. |
-
.NETFramework 4.6.1
- AutoMapper (>= 6.2.2)
- SparkyTestHelpers.Mapping (>= 1.12.0)
-
.NETStandard 1.5
- AutoMapper (>= 6.2.2)
- NETStandard.Library (>= 1.6.1)
- SparkyTestHelpers.Mapping (>= 1.12.0)
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 | 16,808 | 1/15/2019 |
2.1.0 | 1,349 | 1/15/2019 |
2.0.1 | 1,363 | 12/2/2018 |
2.0.0 | 1,319 | 11/22/2018 |
1.8.2 | 1,215 | 7/27/2019 |
1.8.1 | 1,972 | 1/15/2019 |
1.8.0 | 1,398 | 1/15/2019 |
1.7.1 | 6,619 | 6/2/2018 |
1.7.0 | 1,755 | 5/17/2018 |
1.6.3 | 1,702 | 5/16/2018 |
1.6.2 | 1,659 | 5/14/2018 |
1.6.0 | 3,197 | 5/11/2018 |
1.5.2 | 1,535 | 5/4/2018 |
1.5.1 | 1,731 | 4/27/2018 |
1.5.0 | 1,703 | 4/27/2018 |
1.4.0 | 1,507 | 4/21/2018 |
1.3.1 | 52,691 | 4/14/2018 |
1.3.0 | 1,705 | 4/14/2018 |
1.2.2 | 1,724 | 3/12/2018 |
1.2.1 | 1,466 | 2/21/2018 |
1.2.0 | 1,532 | 2/14/2018 |
1.0.0 | 1,612 | 2/13/2018 |
v1.8 - Added SparkyTools.Populater dependency for random values logic