Skip to content

Commit

Permalink
feat: update integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TimothyMakkison committed Jul 16, 2023
1 parent 89ceb22 commit 0edb879
Show file tree
Hide file tree
Showing 15 changed files with 82 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private static IEnumerable<ITypeMapping> GetUserMappingCandidates(MappingBuilder
foreach (var userMapping in ctx.UserMappings)
{
// exclude runtime target type mappings
if (userMapping is UserDefinedNewInstanceRuntimeTargetTypeMapping)
if (userMapping is UserDefinedNewInstanceRuntimeTargetTypeMapping or UserImplementedExistingTargetMethodMapping)
continue;

if (userMapping.CallableByOtherMappings)
Expand Down
11 changes: 5 additions & 6 deletions src/Riok.Mapperly/Descriptors/MappingCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,12 @@ public void Add(ITypeMapping mapping)
_methodMappings.Add(methodMapping);
}

if (
mapping.CallableByOtherMappings
&& mapping is UserImplementedExistingTargetMethodMapping existingMapping
&& FindExistingInstanceMapping(mapping.SourceType, mapping.TargetType) is null
)
if (mapping.CallableByOtherMappings && mapping is UserImplementedExistingTargetMethodMapping existingMapping)
{
_existingTargetMappings.Add(new TypeMappingKey(mapping), existingMapping);
if (FindExistingInstanceMapping(mapping.SourceType, mapping.TargetType) is null)
{
_existingTargetMappings.Add(new TypeMappingKey(mapping), existingMapping);
}
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ public UserImplementedExistingTargetMethodMapping(
public bool IsSynthetic => false;

Check warning on line 37 in src/Riok.Mapperly/Descriptors/Mappings/UserMappings/UserImplementedExistingTargetMethodMapping.cs

View check run for this annotation

Codecov / codecov/patch

src/Riok.Mapperly/Descriptors/Mappings/UserMappings/UserImplementedExistingTargetMethodMapping.cs#L37

Added line #L37 was not covered by tests

public ExpressionSyntax Build(TypeMappingBuildContext ctx) =>
throw new InvalidOperationException($"{nameof(UserDefinedExistingTargetMethodMapping)} does not support {nameof(Build)}");
throw new InvalidOperationException(
$"{nameof(UserImplementedExistingTargetMethodMapping)} {ctx.Source}, {ctx.ReferenceHandler} does not support {nameof(Build)}"
);

Check warning on line 42 in src/Riok.Mapperly/Descriptors/Mappings/UserMappings/UserImplementedExistingTargetMethodMapping.cs

View check run for this annotation

Codecov / codecov/patch

src/Riok.Mapperly/Descriptors/Mappings/UserMappings/UserImplementedExistingTargetMethodMapping.cs#L40-L42

Added lines #L40 - L42 were not covered by tests

public override IEnumerable<StatementSyntax> Build(TypeMappingBuildContext ctx, ExpressionSyntax target)
{
Expand Down
1 change: 1 addition & 0 deletions test/Riok.Mapperly.IntegrationTests/BaseMapperTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public static TestObject NewTestObj()
ExistingISet = { "1", "2", "3", },
ExistingHashSet = { "1", "2", "3", },
ExistingSortedSet = { "1", "2", "3", },
ExistingList = { "1", "2", "3", },
ISet = new HashSet<string> { "1", "2", "3", },
#if NET5_0_OR_GREATER
IReadOnlySet = new HashSet<string> { "1", "2", "3", },
Expand Down
6 changes: 4 additions & 2 deletions test/Riok.Mapperly.IntegrationTests/Dto/TestObjectDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,11 @@ public TestObjectDto(int ctorValue, int unknownValue = 10, int ctorValue2 = 100)

public ISet<int> ExistingISet { get; } = new HashSet<int>();

public HashSet<int> ExistingHashSet { get; } = new HashSet<int>();
public HashSet<int> ExistingHashSet { get; } = new();

public SortedSet<int> ExistingSortedSet { get; } = new SortedSet<int>();
public SortedSet<int> ExistingSortedSet { get; } = new();

public List<int> ExistingList { get; } = new();

public ISet<int> ISet { get; set; } = new HashSet<int>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ public static TestObjectDto MapToDto(TestObject src)
return target;
}

public static void MapExistingList(List<string> src, List<int> dst)
{
dst.EnsureCapacity(src.Count + dst.Count);
foreach (var item in src)
{
dst.Add(int.Parse(item));
}
}

// disable obsolete warning, as the obsolete attribute should still be tested.
#pragma warning disable CS0618
[MapperIgnore(nameof(TestObjectDto.IgnoredStringValue))]
Expand Down
6 changes: 4 additions & 2 deletions test/Riok.Mapperly.IntegrationTests/Models/TestObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,11 @@ public TestObject(int ctorValue, int unknownValue = 10, int ctorValue2 = 100)

public ISet<string> ExistingISet { get; } = new HashSet<string>();

public HashSet<string> ExistingHashSet { get; } = new HashSet<string>();
public HashSet<string> ExistingHashSet { get; } = new();

public SortedSet<string> ExistingSortedSet { get; } = new SortedSet<string>();
public SortedSet<string> ExistingSortedSet { get; } = new();

public List<string> ExistingList { get; } = new();

public ISet<string> ISet { get; set; } = new HashSet<string>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
ImmutableArrayValue: null,
ImmutableQueueValue: [],
ImmutableStackValue: [],
EnumReverseStringValue:
EnumReverseStringValue:
},
NullableReadOnlyObjectCollection: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@
2,
3
],
ExistingList: [
1,
2,
3
],
ISet: [
1,
2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ public static partial class DeepCloningMapper
target.ExistingSortedSet.Add(item2);
}

target.ExistingList.EnsureCapacity(src.ExistingList.Count + target.ExistingList.Count);
foreach (var item3 in src.ExistingList)
{
target.ExistingList.Add(item3);
}

target.ISet = global::System.Linq.Enumerable.ToHashSet(src.ISet);
target.IReadOnlySet = global::System.Linq.Enumerable.ToHashSet(src.IReadOnlySet);
target.HashSet = global::System.Linq.Enumerable.ToHashSet(src.HashSet);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@
2,
3
],
ExistingList: [
1,
2,
3
],
ISet: [
1,
2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ public partial int ParseableInt(string value)
target.ExistingSortedSet.Add(ParseableInt(item2));
}

target.ExistingList.EnsureCapacity(testObject.ExistingList.Count + target.ExistingList.Count);
foreach (var item3 in testObject.ExistingList)
{
target.ExistingList.Add(ParseableInt(item3));
}

target.ISet = global::System.Linq.Enumerable.ToHashSet(global::System.Linq.Enumerable.Select(testObject.ISet, x => ParseableInt(x)));
target.IReadOnlySet = global::System.Linq.Enumerable.ToHashSet(global::System.Linq.Enumerable.Select(testObject.IReadOnlySet, x => ParseableInt(x)));
target.HashSet = global::System.Linq.Enumerable.ToHashSet(global::System.Linq.Enumerable.Select(testObject.HashSet, x => ParseableInt(x)));
Expand Down Expand Up @@ -211,6 +217,12 @@ public partial int ParseableInt(string value)
target.ExistingSortedSet.Add(item2.ToString());
}

target.ExistingList.EnsureCapacity(dto.ExistingList.Count + target.ExistingList.Count);
foreach (var item3 in dto.ExistingList)
{
target.ExistingList.Add(item3.ToString());
}

target.ISet = global::System.Linq.Enumerable.ToHashSet(global::System.Linq.Enumerable.Select(dto.ISet, x => x.ToString()));
target.IReadOnlySet = global::System.Linq.Enumerable.ToHashSet(global::System.Linq.Enumerable.Select(dto.IReadOnlySet, x => x.ToString()));
target.HashSet = global::System.Linq.Enumerable.ToHashSet(global::System.Linq.Enumerable.Select(dto.HashSet, x => x.ToString()));
Expand Down Expand Up @@ -296,6 +308,12 @@ public partial void UpdateDto(global::Riok.Mapperly.IntegrationTests.Models.Test
target.ExistingSortedSet.Add(ParseableInt(item2));
}

target.ExistingList.EnsureCapacity(source.ExistingList.Count + target.ExistingList.Count);
foreach (var item3 in source.ExistingList)
{
target.ExistingList.Add(ParseableInt(item3));
}

target.ISet = global::System.Linq.Enumerable.ToHashSet(global::System.Linq.Enumerable.Select(source.ISet, x => ParseableInt(x)));
target.IReadOnlySet = global::System.Linq.Enumerable.ToHashSet(global::System.Linq.Enumerable.Select(source.IReadOnlySet, x => ParseableInt(x)));
target.HashSet = global::System.Linq.Enumerable.ToHashSet(global::System.Linq.Enumerable.Select(source.HashSet, x => ParseableInt(x)));
Expand Down Expand Up @@ -444,4 +462,4 @@ private string MapToString1(global::Riok.Mapperly.IntegrationTests.Dto.TestEnumD
return target;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@
2,
3
],
ExistingList: [
1,
2,
3
],
ISet: [
1,
2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@
2,
3
],
ExistingList: [
1,
2,
3
],
ISet: [
1,
2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ public static partial int ParseableInt(string value)
target.ExistingSortedSet.Add(ParseableInt(item2));
}

MapExistingList(src.ExistingList, target.ExistingList);
target.ISet = global::System.Linq.Enumerable.ToHashSet(global::System.Linq.Enumerable.Select(src.ISet, x => ParseableInt(x)));
target.IReadOnlySet = global::System.Linq.Enumerable.ToHashSet(global::System.Linq.Enumerable.Select(src.IReadOnlySet, x => ParseableInt(x)));
target.HashSet = global::System.Linq.Enumerable.ToHashSet(global::System.Linq.Enumerable.Select(src.HashSet, x => ParseableInt(x)));
Expand Down Expand Up @@ -222,6 +223,7 @@ public static partial int ParseableInt(string value)
target.ExistingSortedSet.Add(ParseableInt(item2));
}

MapExistingList(testObject.ExistingList, target.ExistingList);
target.ISet = global::System.Linq.Enumerable.ToHashSet(global::System.Linq.Enumerable.Select(testObject.ISet, x => ParseableInt(x)));
target.IReadOnlySet = global::System.Linq.Enumerable.ToHashSet(global::System.Linq.Enumerable.Select(testObject.IReadOnlySet, x => ParseableInt(x)));
target.HashSet = global::System.Linq.Enumerable.ToHashSet(global::System.Linq.Enumerable.Select(testObject.HashSet, x => ParseableInt(x)));
Expand Down Expand Up @@ -306,6 +308,12 @@ public static partial int ParseableInt(string value)
target.ExistingSortedSet.Add(item2.ToString());
}

target.ExistingList.EnsureCapacity(dto.ExistingList.Count + target.ExistingList.Count);
foreach (var item3 in dto.ExistingList)
{
target.ExistingList.Add(item3.ToString());
}

target.ISet = global::System.Linq.Enumerable.ToHashSet(global::System.Linq.Enumerable.Select(dto.ISet, x => x.ToString()));
target.IReadOnlySet = global::System.Linq.Enumerable.ToHashSet(global::System.Linq.Enumerable.Select(dto.IReadOnlySet, x => x.ToString()));
target.HashSet = global::System.Linq.Enumerable.ToHashSet(global::System.Linq.Enumerable.Select(dto.HashSet, x => x.ToString()));
Expand Down Expand Up @@ -391,6 +399,7 @@ public static partial void UpdateDto(global::Riok.Mapperly.IntegrationTests.Mode
target.ExistingSortedSet.Add(ParseableInt(item2));
}

MapExistingList(source.ExistingList, target.ExistingList);
target.ISet = global::System.Linq.Enumerable.ToHashSet(global::System.Linq.Enumerable.Select(source.ISet, x => ParseableInt(x)));
target.IReadOnlySet = global::System.Linq.Enumerable.ToHashSet(global::System.Linq.Enumerable.Select(source.IReadOnlySet, x => ParseableInt(x)));
target.HashSet = global::System.Linq.Enumerable.ToHashSet(global::System.Linq.Enumerable.Select(source.HashSet, x => ParseableInt(x)));
Expand Down

0 comments on commit 0edb879

Please sign in to comment.