Skip to content

Commit

Permalink
chore: fix integration tests (#961)
Browse files Browse the repository at this point in the history
  • Loading branch information
latonz authored Dec 4, 2023
1 parent 997b043 commit 7628cf3
Show file tree
Hide file tree
Showing 15 changed files with 608 additions and 60 deletions.
17 changes: 16 additions & 1 deletion test/Riok.Mapperly.IntegrationTests/BaseMapperTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Riok.Mapperly.IntegrationTests.Helpers;
using Riok.Mapperly.IntegrationTests.Models;
using VerifyTests;
using VerifyTests.DiffPlex;
using VerifyXunit;

namespace Riok.Mapperly.IntegrationTests
Expand All @@ -29,6 +30,7 @@ static BaseMapperTest()
#endif

VerifierSettings.DontScrubDateTimes();
VerifyDiffPlex.Initialize(OutputType.Compact);

Verifier.DerivePathInfo(
(_, _, type, method) =>
Expand All @@ -42,17 +44,30 @@ static BaseMapperTest()

protected string GetGeneratedMapperFilePath(string name)
{
#if NET8_0_OR_GREATER || NET48_OR_GREATER
// artifacts output
return Path.Combine(
_solutionDirectory,
"artifacts",
"obj",
"Riok.Mapperly.IntegrationTests",
"debug",
"generated",
"Riok.Mapperly",
"Riok.Mapperly.MapperGenerator",
name + ".g.cs"
);
#else
return Path.Combine(
_solutionDirectory,
"test",
"Riok.Mapperly.IntegrationTests",
"obj",
"generated",
"Riok.Mapperly",
"Riok.Mapperly.MapperGenerator",
name + ".g.cs"
);
#endif
}

public static TestObject NewTestObj()
Expand Down
12 changes: 10 additions & 2 deletions test/Riok.Mapperly.IntegrationTests/Mapper/TestMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,18 @@ namespace Riok.Mapperly.IntegrationTests.Mapper
public partial class TestMapper
{
[FormatProvider(Default = true)]
private readonly CultureInfo _formatDeCh = CultureInfo.GetCultureInfo("de-CH");
private readonly CultureInfo _formatDeCh = (CultureInfo)CultureInfo.GetCultureInfo("de-CH").Clone();

[FormatProvider]
private readonly CultureInfo _formatEnUs = CultureInfo.GetCultureInfo("en-US");
private readonly CultureInfo _formatEnUs = (CultureInfo)CultureInfo.GetCultureInfo("en-US").Clone();

public TestMapper()
{
// these seem to vary depending on the OS
// set them to a fixed value.
_formatDeCh.NumberFormat.CurrencyPositivePattern = 2;
_formatEnUs.NumberFormat.CurrencyPositivePattern = 2;
}

public partial int DirectInt(int value);

Expand Down
2 changes: 1 addition & 1 deletion test/Riok.Mapperly.IntegrationTests/MapperTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public Task SnapshotGeneratedSource()
}

[Fact]
[VersionedSnapshot(Versions.NET6_0)]
[VersionedSnapshot(Versions.NET6_0 | Versions.NET8_0)]
public Task RunMappingShouldWork()
{
var model = NewTestObj();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<TargetFramework>$(MapperlyIntegrationTestsTargetFramework)</TargetFramework>

<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)/generated</CompilerGeneratedFilesOutputPath>

<!-- Not supported in .NET Framework -->
<ImplicitUsings>disable</ImplicitUsings>
Expand All @@ -28,7 +29,7 @@

<!-- In the CI pipeline, we always want to use a prebuilt nuget package version, since that nuget package will then be distributed -->
<ItemGroup Condition="'$(MapperlyNugetPackageVersion)' != ''">
<PackageReference Include="Riok.Mapperly" Version="$(MapperlyNugetPackageVersion)" PrivateAssets="all" ExcludeAssets="runtime" />
<PackageReference Include="Riok.Mapperly" Version="$(MapperlyNugetPackageVersion)" PrivateAssets="all" />
</ItemGroup>

<!-- ef core tests should only run on newer .NET versions -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
IntValue: 10,
IntInitOnlyValue: 3,
RequiredValue: 4,
UnmappedValue: 10,
StringValue: fooBar,
RenamedStringValue: fooBar2,
Flattening: {
Expand All @@ -27,6 +28,7 @@
CtorValue: 5,
CtorValue2: 100,
RequiredValue: 4,
UnmappedValue: 10,
StringValue: ,
RenamedStringValue: ,
Flattening: {},
Expand All @@ -38,13 +40,15 @@
ImmutableStackValue: [],
EnumValue: Value10,
EnumName: Value30,
EnumReverseStringValue: DtoValue3
EnumReverseStringValue: DtoValue3,
ExposePrivateValue: 16
},
SourceTargetSameObjectType: {
CtorValue: 8,
CtorValue2: 100,
IntValue: 99,
RequiredValue: 98,
UnmappedValue: 10,
StringValue: ,
RenamedStringValue: ,
Flattening: {},
Expand All @@ -54,7 +58,8 @@
ImmutableArrayValue: null,
ImmutableQueueValue: [],
ImmutableStackValue: [],
EnumReverseStringValue:
EnumReverseStringValue: ,
ExposePrivateValue: 19
},
NullableReadOnlyObjectCollection: [
{
Expand Down Expand Up @@ -158,6 +163,8 @@
SubIntValue: 2,
BaseIntValue: 1
},
DateTimeValue: 2020-01-03 15:10:05 Utc,
DateTimeValueTargetDateOnly: 2020-01-03 15:10:05 Utc,
DateTimeValueTargetTimeOnly: 2020-01-03 15:10:05 Utc
DateTimeValueTargetTimeOnly: 2020-01-03 15:10:05 Utc,
ExposePrivateValue: 18
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,34 +22,66 @@ public static partial class DeepCloningMapper
{
target.NullableFlattening = Copy(src.NullableFlattening);
}
else
{
target.NullableFlattening = null;
}
if (src.NestedNullable != null)
{
target.NestedNullable = MapToTestObjectNested(src.NestedNullable);
}
else
{
target.NestedNullable = null;
}
if (src.NestedNullableTargetNotNullable != null)
{
target.NestedNullableTargetNotNullable = MapToTestObjectNested(src.NestedNullableTargetNotNullable);
}
else
{
target.NestedNullableTargetNotNullable = null;
}
if (src.TupleValue != null)
{
target.TupleValue = MapToValueTuple(src.TupleValue.Value);
}
else
{
target.TupleValue = null;
}
if (src.RecursiveObject != null)
{
target.RecursiveObject = Copy(src.RecursiveObject);
}
else
{
target.RecursiveObject = null;
}
if (src.SourceTargetSameObjectType != null)
{
target.SourceTargetSameObjectType = Copy(src.SourceTargetSameObjectType);
}
else
{
target.SourceTargetSameObjectType = null;
}
if (src.NullableReadOnlyObjectCollection != null)
{
target.NullableReadOnlyObjectCollection = MapToIReadOnlyCollection(src.NullableReadOnlyObjectCollection);
}
else
{
target.NullableReadOnlyObjectCollection = null;
}
if (src.SubObject != null)
{
target.SubObject = MapToInheritanceSubObject(src.SubObject);
}
else
{
target.SubObject = null;
}
target.IntValue = src.IntValue;
target.StringValue = src.StringValue;
target.RenamedStringValue = src.RenamedStringValue;
Expand Down Expand Up @@ -92,6 +124,7 @@ public static partial class DeepCloningMapper
target.EnumRawValue = src.EnumRawValue;
target.EnumStringValue = src.EnumStringValue;
target.EnumReverseStringValue = src.EnumReverseStringValue;
target.DateTimeValue = src.DateTimeValue;
target.DateTimeValueTargetDateOnly = src.DateTimeValueTargetDateOnly;
target.DateTimeValueTargetTimeOnly = src.DateTimeValueTargetTimeOnly;
return target;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,25 @@
EnumValue: DtoValue1,
EnumName: Value30,
EnumStringValue: 0,
EnumReverseStringValue: DtoValue3
EnumReverseStringValue: DtoValue3,
FormattedIntValue: CHF 0.00,
FormattedDateValue: Monday, January 1, 0001,
ExposePrivateValue: 26
},
SourceTargetSameObjectType: {
CtorValue: 8,
CtorValue2: 100,
IntValue: 99,
RequiredValue: 98,
UnmappedValue: 10,
StringValue: ,
RenamedStringValue: ,
Flattening: {},
ImmutableArrayValue: null,
ImmutableQueueValue: [],
ImmutableStackValue: [],
EnumReverseStringValue:
EnumReverseStringValue: ,
ExposePrivateValue: 19
},
NullableReadOnlyObjectCollection: [
{
Expand Down Expand Up @@ -175,5 +180,8 @@
BaseIntValue: 1
},
DateTimeValueTargetDateOnly: 2020-01-03,
DateTimeValueTargetTimeOnly: 3:10 PM
DateTimeValueTargetTimeOnly: 3:10 PM,
FormattedIntValue: CHF 10.00,
FormattedDateValue: Friday, January 3, 2020,
ExposePrivateValue: 28
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
EnumReverseStringValue: DtoValue3,
FormattedIntValue: CHF 0.00,
FormattedDateValue: Monday, January 1, 0001,
ExposePrivateValue: 16
ExposePrivateValue: 26
},
SourceTargetSameObjectType: {
CtorValue: 8,
Expand Down Expand Up @@ -188,5 +188,5 @@
DateTimeValueTargetTimeOnly: 3:10 PM,
FormattedIntValue: CHF 10.00,
FormattedDateValue: Friday, January 3, 2020,
ExposePrivateValue: 18
ExposePrivateValue: 28
}
Loading

0 comments on commit 7628cf3

Please sign in to comment.