diff --git a/Source/Boxed.Mapping/AsyncImmutableMapperExtensions.cs b/Source/Boxed.Mapping/AsyncImmutableMapperExtensions.cs index 17ddaab9..0ea0ca11 100644 --- a/Source/Boxed.Mapping/AsyncImmutableMapperExtensions.cs +++ b/Source/Boxed.Mapping/AsyncImmutableMapperExtensions.cs @@ -2,6 +2,9 @@ namespace Boxed.Mapping { using System; using System.Collections.Generic; +#if NET5_0 + using System.Collections.Immutable; +#endif using System.Collections.ObjectModel; using System.Linq; using System.Runtime.CompilerServices; @@ -793,6 +796,160 @@ public static async Task> MapHashSetAsync + /// Maps the list of into an immutable array of + /// . + /// + /// The type of the source objects. + /// The type of the destination objects. + /// The mapper. + /// The source objects. + /// The cancellation token. + /// An immutable array of . + /// The or is + /// null. + public static async Task> MapImmutableArrayAsync( + this IAsyncImmutableMapper mapper, + List source, + CancellationToken cancellationToken = default) + where TDestination : new() => + ImmutableArray.Create(await mapper.MapArrayAsync(source, cancellationToken).ConfigureAwait(false)); + + /// + /// Maps the collection of into an immutable array of + /// . + /// + /// The type of the source objects. + /// The type of the destination objects. + /// The mapper. + /// The source objects. + /// The cancellation token. + /// An immutable array of . + /// The or is + /// null. + public static async Task> MapImmutableArrayAsync( + this IAsyncImmutableMapper mapper, + Collection source, + CancellationToken cancellationToken = default) + where TDestination : new() => + ImmutableArray.Create(await mapper.MapArrayAsync(source, cancellationToken).ConfigureAwait(false)); + + /// + /// Maps the array of into an immutable array of + /// . + /// + /// The type of the source objects. + /// The type of the destination objects. + /// The mapper. + /// The source objects. + /// The cancellation token. + /// An immutable array of . + /// The or is + /// null. + public static async Task> MapImmutableArrayAsync( + this IAsyncImmutableMapper mapper, + TSource[] source, + CancellationToken cancellationToken = default) + where TDestination : new() => + ImmutableArray.Create(await mapper.MapArrayAsync(source, cancellationToken).ConfigureAwait(false)); + + /// + /// Maps the enumerable of into an immutable array of + /// . + /// + /// The type of the source objects. + /// The type of the destination objects. + /// The mapper. + /// The source objects. + /// The cancellation token. + /// An immutable array of . + /// The or is + /// null. + public static async Task> MapImmutableArrayAsync( + this IAsyncImmutableMapper mapper, + IEnumerable source, + CancellationToken cancellationToken = default) + where TDestination : new() => + ImmutableArray.Create(await mapper.MapArrayAsync(source, cancellationToken).ConfigureAwait(false)); + + /// + /// Maps the list of into an immutable list of + /// . + /// + /// The type of the source objects. + /// The type of the destination objects. + /// The mapper. + /// The source objects. + /// The cancellation token. + /// An immutable list of . + /// The or is + /// null. + public static async Task> MapImmutableListAsync( + this IAsyncImmutableMapper mapper, + List source, + CancellationToken cancellationToken = default) + where TDestination : new() => + ImmutableList.Create(await mapper.MapArrayAsync(source, cancellationToken).ConfigureAwait(false)); + + /// + /// Maps the collection of into an immutable list of + /// . + /// + /// The type of the source objects. + /// The type of the destination objects. + /// The mapper. + /// The source objects. + /// The cancellation token. + /// An immutable list of . + /// The or is + /// null. + public static async Task> MapImmutableListAsync( + this IAsyncImmutableMapper mapper, + Collection source, + CancellationToken cancellationToken = default) + where TDestination : new() => + ImmutableList.Create(await mapper.MapArrayAsync(source, cancellationToken).ConfigureAwait(false)); + + /// + /// Maps the array of into an immutable list of + /// . + /// + /// The type of the source objects. + /// The type of the destination objects. + /// The mapper. + /// The source objects. + /// The cancellation token. + /// An immutable list of . + /// The or is + /// null. + public static async Task> MapImmutableListAsync( + this IAsyncImmutableMapper mapper, + TSource[] source, + CancellationToken cancellationToken = default) + where TDestination : new() => + ImmutableList.Create(await mapper.MapArrayAsync(source, cancellationToken).ConfigureAwait(false)); + + /// + /// Maps the enumerable of into an immutable list of + /// . + /// + /// The type of the source objects. + /// The type of the destination objects. + /// The mapper. + /// The source objects. + /// The cancellation token. + /// An immutable list of . + /// The or is + /// null. + public static async Task> MapImmutableListAsync( + this IAsyncImmutableMapper mapper, + IEnumerable source, + CancellationToken cancellationToken = default) + where TDestination : new() => + ImmutableList.Create(await mapper.MapArrayAsync(source, cancellationToken).ConfigureAwait(false)); +#endif + /// /// Maps the list of into a list of /// . diff --git a/Source/Boxed.Mapping/AsyncMapperExtensions.cs b/Source/Boxed.Mapping/AsyncMapperExtensions.cs index 1a3df198..87dddda3 100644 --- a/Source/Boxed.Mapping/AsyncMapperExtensions.cs +++ b/Source/Boxed.Mapping/AsyncMapperExtensions.cs @@ -2,6 +2,9 @@ namespace Boxed.Mapping { using System; using System.Collections.Generic; +#if NET5_0 + using System.Collections.Immutable; +#endif using System.Collections.ObjectModel; using System.Linq; using System.Runtime.CompilerServices; @@ -721,6 +724,160 @@ public static async Task> MapHashSetAsync + /// Maps the list of into an immutable array of + /// . + /// + /// The type of the source objects. + /// The type of the destination objects. + /// The mapper. + /// The source objects. + /// The cancellation token. + /// An immutable array of . + /// The or is + /// null. + public static async Task> MapImmutableArrayAsync( + this IAsyncMapper mapper, + List source, + CancellationToken cancellationToken = default) + where TDestination : new() => + ImmutableArray.Create(await mapper.MapArrayAsync(source, cancellationToken).ConfigureAwait(false)); + + /// + /// Maps the collection of into an immutable array of + /// . + /// + /// The type of the source objects. + /// The type of the destination objects. + /// The mapper. + /// The source objects. + /// The cancellation token. + /// An immutable array of . + /// The or is + /// null. + public static async Task> MapImmutableArrayAsync( + this IAsyncMapper mapper, + Collection source, + CancellationToken cancellationToken = default) + where TDestination : new() => + ImmutableArray.Create(await mapper.MapArrayAsync(source, cancellationToken).ConfigureAwait(false)); + + /// + /// Maps the array of into an immutable array of + /// . + /// + /// The type of the source objects. + /// The type of the destination objects. + /// The mapper. + /// The source objects. + /// The cancellation token. + /// An immutable array of . + /// The or is + /// null. + public static async Task> MapImmutableArrayAsync( + this IAsyncMapper mapper, + TSource[] source, + CancellationToken cancellationToken = default) + where TDestination : new() => + ImmutableArray.Create(await mapper.MapArrayAsync(source, cancellationToken).ConfigureAwait(false)); + + /// + /// Maps the enumerable of into an immutable array of + /// . + /// + /// The type of the source objects. + /// The type of the destination objects. + /// The mapper. + /// The source objects. + /// The cancellation token. + /// An immutable array of . + /// The or is + /// null. + public static async Task> MapImmutableArrayAsync( + this IAsyncMapper mapper, + IEnumerable source, + CancellationToken cancellationToken = default) + where TDestination : new() => + ImmutableArray.Create(await mapper.MapArrayAsync(source, cancellationToken).ConfigureAwait(false)); + + /// + /// Maps the list of into an immutable list of + /// . + /// + /// The type of the source objects. + /// The type of the destination objects. + /// The mapper. + /// The source objects. + /// The cancellation token. + /// An immutable list of . + /// The or is + /// null. + public static async Task> MapImmutableListAsync( + this IAsyncMapper mapper, + List source, + CancellationToken cancellationToken = default) + where TDestination : new() => + ImmutableList.Create(await mapper.MapArrayAsync(source, cancellationToken).ConfigureAwait(false)); + + /// + /// Maps the collection of into an immutable list of + /// . + /// + /// The type of the source objects. + /// The type of the destination objects. + /// The mapper. + /// The source objects. + /// The cancellation token. + /// An immutable list of . + /// The or is + /// null. + public static async Task> MapImmutableListAsync( + this IAsyncMapper mapper, + Collection source, + CancellationToken cancellationToken = default) + where TDestination : new() => + ImmutableList.Create(await mapper.MapArrayAsync(source, cancellationToken).ConfigureAwait(false)); + + /// + /// Maps the array of into an immutable list of + /// . + /// + /// The type of the source objects. + /// The type of the destination objects. + /// The mapper. + /// The source objects. + /// The cancellation token. + /// An immutable list of . + /// The or is + /// null. + public static async Task> MapImmutableListAsync( + this IAsyncMapper mapper, + TSource[] source, + CancellationToken cancellationToken = default) + where TDestination : new() => + ImmutableList.Create(await mapper.MapArrayAsync(source, cancellationToken).ConfigureAwait(false)); + + /// + /// Maps the enumerable of into an immutable list of + /// . + /// + /// The type of the source objects. + /// The type of the destination objects. + /// The mapper. + /// The source objects. + /// The cancellation token. + /// An immutable list of . + /// The or is + /// null. + public static async Task> MapImmutableListAsync( + this IAsyncMapper mapper, + IEnumerable source, + CancellationToken cancellationToken = default) + where TDestination : new() => + ImmutableList.Create(await mapper.MapArrayAsync(source, cancellationToken).ConfigureAwait(false)); +#endif + /// /// Maps the list of into a list of /// . diff --git a/Source/Boxed.Mapping/ImmutableMapperExtensions.cs b/Source/Boxed.Mapping/ImmutableMapperExtensions.cs index 7dd65e3d..f8f73f5e 100644 --- a/Source/Boxed.Mapping/ImmutableMapperExtensions.cs +++ b/Source/Boxed.Mapping/ImmutableMapperExtensions.cs @@ -2,6 +2,9 @@ namespace Boxed.Mapping { using System; using System.Collections.Generic; +#if NET5_0 + using System.Collections.Immutable; +#endif using System.Collections.ObjectModel; using System.Linq; using System.Runtime.CompilerServices; @@ -29,7 +32,6 @@ public static async IAsyncEnumerable MapEnumerableAsync mapper, IAsyncEnumerable source, [EnumeratorCancellation] CancellationToken cancellationToken = default) - where TDestination : new() { if (mapper is null) { @@ -62,7 +64,6 @@ public static async IAsyncEnumerable MapEnumerableAsync( this IImmutableMapper mapper, TSource source) - where TDestination : new() { if (mapper is null) { @@ -96,7 +97,6 @@ public static TDestination[] MapArray( TSourceCollection sourceCollection, TDestination[] destinationCollection) where TSourceCollection : IEnumerable - where TDestination : new() { if (mapper is null) { @@ -138,7 +138,6 @@ public static TDestination[] MapArray( public static TDestination[] MapArray( this IImmutableMapper mapper, List source) - where TDestination : new() { if (mapper is null) { @@ -175,7 +174,6 @@ public static TDestination[] MapArray( public static TDestination[] MapArray( this IImmutableMapper mapper, Collection source) - where TDestination : new() { if (mapper is null) { @@ -212,7 +210,6 @@ public static TDestination[] MapArray( public static TDestination[] MapArray( this IImmutableMapper mapper, TSource[] source) - where TDestination : new() { if (mapper is null) { @@ -249,7 +246,6 @@ public static TDestination[] MapArray( public static TDestination[] MapArray( this IImmutableMapper mapper, IEnumerable source) - where TDestination : new() { if (mapper is null) { @@ -295,7 +291,6 @@ public static TDestinationCollection MapCollection where TDestinationCollection : ICollection - where TDestination : new() { if (mapper is null) { @@ -330,7 +325,6 @@ public static TDestinationCollection MapCollection MapCollection( this IImmutableMapper mapper, List source) - where TDestination : new() { if (mapper is null) { @@ -367,7 +361,6 @@ public static Collection MapCollection( public static Collection MapCollection( this IImmutableMapper mapper, Collection source) - where TDestination : new() { if (mapper is null) { @@ -404,7 +397,6 @@ public static Collection MapCollection( public static Collection MapCollection( this IImmutableMapper mapper, TSource[] source) - where TDestination : new() { if (mapper is null) { @@ -441,7 +433,6 @@ public static Collection MapCollection( public static Collection MapCollection( this IImmutableMapper mapper, IEnumerable source) - where TDestination : new() { if (mapper is null) { @@ -477,7 +468,6 @@ public static Collection MapCollection( public static HashSet MapHashSet( this IImmutableMapper mapper, List source) - where TDestination : new() { if (mapper is null) { @@ -513,7 +503,6 @@ public static HashSet MapHashSet( public static HashSet MapHashSet( this IImmutableMapper mapper, Collection source) - where TDestination : new() { if (mapper is null) { @@ -549,7 +538,6 @@ public static HashSet MapHashSet( public static HashSet MapHashSet( this IImmutableMapper mapper, TSource[] source) - where TDestination : new() { if (mapper is null) { @@ -585,7 +573,6 @@ public static HashSet MapHashSet( public static HashSet MapHashSet( this IImmutableMapper mapper, IEnumerable source) - where TDestination : new() { if (mapper is null) { @@ -607,6 +594,136 @@ public static HashSet MapHashSet( return destination; } +#if NET5_0 + /// + /// Maps the list of into an immutable array of + /// . + /// + /// The type of the source objects. + /// The type of the destination objects. + /// The mapper. + /// The source objects. + /// An immutable array of . + /// The or is + /// null. + public static ImmutableArray MapImmutableArray( + this IImmutableMapper mapper, + List source) => + ImmutableArray.Create(mapper.MapArray(source)); + + /// + /// Maps the collection of into an immutable array of + /// . + /// + /// The type of the source objects. + /// The type of the destination objects. + /// The mapper. + /// The source objects. + /// An immutable array of . + /// The or is + /// null. + public static ImmutableArray MapImmutableArray( + this IImmutableMapper mapper, + Collection source) => + ImmutableArray.Create(mapper.MapArray(source)); + + /// + /// Maps the array of into an immutable array of + /// . + /// + /// The type of the source objects. + /// The type of the destination objects. + /// The mapper. + /// The source objects. + /// An immutable array of . + /// The or is + /// null. + public static ImmutableArray MapImmutableArray( + this IImmutableMapper mapper, + TSource[] source) => + ImmutableArray.Create(mapper.MapArray(source)); + + /// + /// Maps the enumerable of into an immutable array of + /// . + /// + /// The type of the source objects. + /// The type of the destination objects. + /// The mapper. + /// The source objects. + /// An immutable array of . + /// The or is + /// null. + public static ImmutableArray MapImmutableArray( + this IImmutableMapper mapper, + IEnumerable source) => + ImmutableArray.Create(mapper.MapArray(source)); + + /// + /// Maps the list of into an immutable list of + /// . + /// + /// The type of the source objects. + /// The type of the destination objects. + /// The mapper. + /// The source objects. + /// An immutable list of . + /// The or is + /// null. + public static ImmutableList MapImmutableList( + this IImmutableMapper mapper, + List source) => + ImmutableList.Create(mapper.MapArray(source)); + + /// + /// Maps the collection of into an immutable list of + /// . + /// + /// The type of the source objects. + /// The type of the destination objects. + /// The mapper. + /// The source objects. + /// An immutable list of . + /// The or is + /// null. + public static ImmutableList MapImmutableList( + this IImmutableMapper mapper, + Collection source) => + ImmutableList.Create(mapper.MapArray(source)); + + /// + /// Maps the array of into an immutable list of + /// . + /// + /// The type of the source objects. + /// The type of the destination objects. + /// The mapper. + /// The source objects. + /// An immutable list of . + /// The or is + /// null. + public static ImmutableList MapImmutableList( + this IImmutableMapper mapper, + TSource[] source) => + ImmutableList.Create(mapper.MapArray(source)); + + /// + /// Maps the enumerable of into an immutable list of + /// . + /// + /// The type of the source objects. + /// The type of the destination objects. + /// The mapper. + /// The source objects. + /// An immutable list of . + /// The or is + /// null. + public static ImmutableList MapImmutableList( + this IImmutableMapper mapper, + IEnumerable source) => + ImmutableList.Create(mapper.MapArray(source)); +#endif + /// /// Maps the list of into a list of /// . @@ -621,7 +738,6 @@ public static HashSet MapHashSet( public static List MapList( this IImmutableMapper mapper, List source) - where TDestination : new() { if (mapper is null) { @@ -658,7 +774,6 @@ public static List MapList( public static List MapList( this IImmutableMapper mapper, Collection source) - where TDestination : new() { if (mapper is null) { @@ -695,7 +810,6 @@ public static List MapList( public static List MapList( this IImmutableMapper mapper, TSource[] source) - where TDestination : new() { if (mapper is null) { @@ -732,7 +846,6 @@ public static List MapList( public static List MapList( this IImmutableMapper mapper, IEnumerable source) - where TDestination : new() { if (mapper is null) { @@ -768,7 +881,6 @@ public static List MapList( public static ObservableCollection MapObservableCollection( this IImmutableMapper mapper, List source) - where TDestination : new() { if (mapper is null) { @@ -805,7 +917,6 @@ public static ObservableCollection MapObservableCollection MapObservableCollection( this IImmutableMapper mapper, Collection source) - where TDestination : new() { if (mapper is null) { @@ -842,7 +953,6 @@ public static ObservableCollection MapObservableCollection MapObservableCollection( this IImmutableMapper mapper, TSource[] source) - where TDestination : new() { if (mapper is null) { @@ -879,7 +989,6 @@ public static ObservableCollection MapObservableCollection MapObservableCollection( this IImmutableMapper mapper, IEnumerable source) - where TDestination : new() { if (mapper is null) { diff --git a/Source/Boxed.Mapping/MapperExtensions.cs b/Source/Boxed.Mapping/MapperExtensions.cs index 4d8c03f6..48473ae8 100644 --- a/Source/Boxed.Mapping/MapperExtensions.cs +++ b/Source/Boxed.Mapping/MapperExtensions.cs @@ -2,6 +2,9 @@ namespace Boxed.Mapping { using System; using System.Collections.Generic; +#if NET5_0 + using System.Collections.Immutable; +#endif using System.Collections.ObjectModel; using System.Linq; using System.Runtime.CompilerServices; @@ -619,6 +622,144 @@ public static HashSet MapHashSet( return destination; } +#if NET5_0 + /// + /// Maps the list of into an immutable array of + /// . + /// + /// The type of the source objects. + /// The type of the destination objects. + /// The mapper. + /// The source objects. + /// An immutable array of . + /// The or is + /// null. + public static ImmutableArray MapImmutableArray( + this IMapper mapper, + List source) + where TDestination : new() => + ImmutableArray.Create(mapper.MapArray(source)); + + /// + /// Maps the collection of into an immutable array of + /// . + /// + /// The type of the source objects. + /// The type of the destination objects. + /// The mapper. + /// The source objects. + /// An immutable array of . + /// The or is + /// null. + public static ImmutableArray MapImmutableArray( + this IMapper mapper, + Collection source) + where TDestination : new() => + ImmutableArray.Create(mapper.MapArray(source)); + + /// + /// Maps the array of into an immutable array of + /// . + /// + /// The type of the source objects. + /// The type of the destination objects. + /// The mapper. + /// The source objects. + /// An immutable array of . + /// The or is + /// null. + public static ImmutableArray MapImmutableArray( + this IMapper mapper, + TSource[] source) + where TDestination : new() => + ImmutableArray.Create(mapper.MapArray(source)); + + /// + /// Maps the enumerable of into an immutable array of + /// . + /// + /// The type of the source objects. + /// The type of the destination objects. + /// The mapper. + /// The source objects. + /// An immutable array of . + /// The or is + /// null. + public static ImmutableArray MapImmutableArray( + this IMapper mapper, + IEnumerable source) + where TDestination : new() => + ImmutableArray.Create(mapper.MapArray(source)); + + /// + /// Maps the list of into an immutable list of + /// . + /// + /// The type of the source objects. + /// The type of the destination objects. + /// The mapper. + /// The source objects. + /// An immutable list of . + /// The or is + /// null. + public static ImmutableList MapImmutableList( + this IMapper mapper, + List source) + where TDestination : new() => + ImmutableList.Create(mapper.MapArray(source)); + + /// + /// Maps the collection of into an immutable list of + /// . + /// + /// The type of the source objects. + /// The type of the destination objects. + /// The mapper. + /// The source objects. + /// An immutable list of . + /// The or is + /// null. + public static ImmutableList MapImmutableList( + this IMapper mapper, + Collection source) + where TDestination : new() => + ImmutableList.Create(mapper.MapArray(source)); + + /// + /// Maps the array of into an immutable list of + /// . + /// + /// The type of the source objects. + /// The type of the destination objects. + /// The mapper. + /// The source objects. + /// An immutable list of . + /// The or is + /// null. + public static ImmutableList MapImmutableList( + this IMapper mapper, + TSource[] source) + where TDestination : new() => + ImmutableList.Create(mapper.MapArray(source)); + + /// + /// Maps the enumerable of into an immutable list of + /// . + /// + /// The type of the source objects. + /// The type of the destination objects. + /// The mapper. + /// The source objects. + /// An immutable list of . + /// The or is + /// null. + public static ImmutableList MapImmutableList( + this IMapper mapper, + IEnumerable source) + where TDestination : new() => + ImmutableList.Create(mapper.MapArray(source)); +#endif + /// /// Maps the list of into a list of /// . diff --git a/Tests/Boxed.Mapping.Test/AsyncImmutableMapperTest.cs b/Tests/Boxed.Mapping.Test/AsyncImmutableMapperTest.cs index eafd7e04..fc64beec 100644 --- a/Tests/Boxed.Mapping.Test/AsyncImmutableMapperTest.cs +++ b/Tests/Boxed.Mapping.Test/AsyncImmutableMapperTest.cs @@ -2,6 +2,9 @@ namespace Boxed.Mapping.Test { using System; using System.Collections.Generic; +#if NET5_0 + using System.Collections.Immutable; +#endif using System.Collections.ObjectModel; using System.Linq; using System.Threading; @@ -175,6 +178,78 @@ public async Task MapHashSetAsync_ToNewObject_MappedAsync() Assert.Equal(new int[] { 1, 2 }, to.Select(x => x.Property)); } +#if NET5_0 + [Fact] + public async Task MapImmutableArrayAsync_Empty_MappedAsync() + { + var mapper = new AsyncImmutableMapper(); + + var to = await mapper + .MapImmutableArrayAsync(Array.Empty(), this.cancellationTokenSource.Token) + .ConfigureAwait(false); + + Assert.IsType>(to); + Assert.Empty(to); + } + + [Fact] + public async Task MapImmutableArrayAsync_ToNewObject_MappedAsync() + { + var mapper = new AsyncImmutableMapper(); + + var to = await mapper + .MapImmutableArrayAsync( + new MapFrom[] + { + new MapFrom() { Property = 1 }, + new MapFrom() { Property = 2 }, + }, + this.cancellationTokenSource.Token) + .ConfigureAwait(false); + + Assert.Equal(this.cancellationTokenSource.Token, mapper.CancellationToken); + Assert.IsType>(to); + Assert.Equal(2, to.Length); + Assert.Equal(1, to[0].Property); + Assert.Equal(2, to[1].Property); + } + + [Fact] + public async Task MapImmutableListAsync_Empty_MappedAsync() + { + var mapper = new AsyncImmutableMapper(); + + var to = await mapper + .MapImmutableListAsync(Array.Empty(), this.cancellationTokenSource.Token) + .ConfigureAwait(false); + + Assert.IsType>(to); + Assert.Empty(to); + } + + [Fact] + public async Task MapImmutableListAsync_ToNewObject_MappedAsync() + { + var mapper = new AsyncImmutableMapper(); + + var to = await mapper + .MapImmutableListAsync( + new MapFrom[] + { + new MapFrom() { Property = 1 }, + new MapFrom() { Property = 2 }, + }, + this.cancellationTokenSource.Token) + .ConfigureAwait(false); + + Assert.Equal(this.cancellationTokenSource.Token, mapper.CancellationToken); + Assert.IsType>(to); + Assert.Equal(2, to.Count); + Assert.Equal(1, to[0].Property); + Assert.Equal(2, to[1].Property); + } +#endif + [Fact] public async Task MapListAsync_Empty_MappedAsync() { diff --git a/Tests/Boxed.Mapping.Test/AsyncMapperTest.cs b/Tests/Boxed.Mapping.Test/AsyncMapperTest.cs index e8e2e1da..4f51a946 100644 --- a/Tests/Boxed.Mapping.Test/AsyncMapperTest.cs +++ b/Tests/Boxed.Mapping.Test/AsyncMapperTest.cs @@ -2,6 +2,9 @@ namespace Boxed.Mapping.Test { using System; using System.Collections.Generic; +#if NET5_0 + using System.Collections.Immutable; +#endif using System.Collections.ObjectModel; using System.Linq; using System.Threading; @@ -175,6 +178,78 @@ public async Task MapHashSetAsync_ToNewObject_MappedAsync() Assert.Equal(new int[] { 1, 2 }, to.Select(x => x.Property)); } +#if NET5_0 + [Fact] + public async Task MapImmutableArrayAsync_Empty_MappedAsync() + { + var mapper = new AsyncMapper(); + + var to = await mapper + .MapImmutableArrayAsync(Array.Empty(), this.cancellationTokenSource.Token) + .ConfigureAwait(false); + + Assert.IsType>(to); + Assert.Empty(to); + } + + [Fact] + public async Task MapImmutableArrayAsync_ToNewObject_MappedAsync() + { + var mapper = new AsyncMapper(); + + var to = await mapper + .MapImmutableArrayAsync( + new MapFrom[] + { + new MapFrom() { Property = 1 }, + new MapFrom() { Property = 2 }, + }, + this.cancellationTokenSource.Token) + .ConfigureAwait(false); + + Assert.Equal(this.cancellationTokenSource.Token, mapper.CancellationToken); + Assert.IsType>(to); + Assert.Equal(2, to.Length); + Assert.Equal(1, to[0].Property); + Assert.Equal(2, to[1].Property); + } + + [Fact] + public async Task MapImmutableListAsync_Empty_MappedAsync() + { + var mapper = new AsyncMapper(); + + var to = await mapper + .MapImmutableListAsync(Array.Empty(), this.cancellationTokenSource.Token) + .ConfigureAwait(false); + + Assert.IsType>(to); + Assert.Empty(to); + } + + [Fact] + public async Task MapImmutableListAsync_ToNewObject_MappedAsync() + { + var mapper = new AsyncMapper(); + + var to = await mapper + .MapImmutableListAsync( + new MapFrom[] + { + new MapFrom() { Property = 1 }, + new MapFrom() { Property = 2 }, + }, + this.cancellationTokenSource.Token) + .ConfigureAwait(false); + + Assert.Equal(this.cancellationTokenSource.Token, mapper.CancellationToken); + Assert.IsType>(to); + Assert.Equal(2, to.Count); + Assert.Equal(1, to[0].Property); + Assert.Equal(2, to[1].Property); + } +#endif + [Fact] public async Task MapListAsync_Empty_MappedAsync() { diff --git a/Tests/Boxed.Mapping.Test/ImmutableMapperTest.cs b/Tests/Boxed.Mapping.Test/ImmutableMapperTest.cs index 4101c28b..b7645894 100644 --- a/Tests/Boxed.Mapping.Test/ImmutableMapperTest.cs +++ b/Tests/Boxed.Mapping.Test/ImmutableMapperTest.cs @@ -2,6 +2,9 @@ namespace Boxed.Mapping.Test { using System; using System.Collections.Generic; +#if NET5_0 + using System.Collections.Immutable; +#endif using System.Collections.ObjectModel; using System.Linq; using System.Threading.Tasks; @@ -145,6 +148,37 @@ public void MapHashSet_ToNewObject_Mapped() Assert.Equal(new int[] { 1, 2 }, to.Select(x => x.Property)); } +#if NET5_0 + [Fact] + public void MapImmutableArray_Empty_Mapped() + { + var mapper = new ImmutableMapper(); + + var to = mapper.MapImmutableArray(Array.Empty()); + + Assert.IsType>(to); + Assert.Empty(to); + } + + [Fact] + public void MapImmutableArray_ToNewObject_Mapped() + { + var mapper = new ImmutableMapper(); + + var to = mapper.MapImmutableArray( + new MapFrom[] + { + new MapFrom() { Property = 1 }, + new MapFrom() { Property = 2 }, + }); + + Assert.IsType>(to); + Assert.Equal(2, to.Length); + Assert.Equal(1, to[0].Property); + Assert.Equal(2, to[1].Property); + } +#endif + [Fact] public void MapList_Empty_Mapped() { diff --git a/Tests/Boxed.Mapping.Test/MapperTest.cs b/Tests/Boxed.Mapping.Test/MapperTest.cs index 92d004a2..10abf90c 100644 --- a/Tests/Boxed.Mapping.Test/MapperTest.cs +++ b/Tests/Boxed.Mapping.Test/MapperTest.cs @@ -2,6 +2,9 @@ namespace Boxed.Mapping.Test { using System; using System.Collections.Generic; +#if NET5_0 + using System.Collections.Immutable; +#endif using System.Collections.ObjectModel; using System.Linq; using System.Threading.Tasks; @@ -145,6 +148,37 @@ public void MapHashSet_ToNewObject_Mapped() Assert.Equal(new int[] { 1, 2 }, to.Select(x => x.Property)); } +#if NET5_0 + [Fact] + public void MapImmutableArray_Empty_Mapped() + { + var mapper = new Mapper(); + + var to = mapper.MapImmutableArray(Array.Empty()); + + Assert.IsType>(to); + Assert.Empty(to); + } + + [Fact] + public void MapImmutableArray_ToNewObject_Mapped() + { + var mapper = new Mapper(); + + var to = mapper.MapImmutableArray( + new MapFrom[] + { + new MapFrom() { Property = 1 }, + new MapFrom() { Property = 2 }, + }); + + Assert.IsType>(to); + Assert.Equal(2, to.Length); + Assert.Equal(1, to[0].Property); + Assert.Equal(2, to[1].Property); + } +#endif + [Fact] public void MapList_Empty_Mapped() {