-
-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: resolve correct mapper defaults for roslyn versions <= 4.4 (#958)
- Loading branch information
Showing
8 changed files
with
77 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using Riok.Mapperly.Abstractions; | ||
|
||
// is used to test mapper defaults | ||
namespace Riok.Mapperly.IntegrationTests.Mapper | ||
{ | ||
[Mapper] | ||
public static partial class EnumMapper | ||
{ | ||
public static partial Enum2 Map(Enum1 e); | ||
} | ||
|
||
public enum Enum1 | ||
{ | ||
Value1 = 4, | ||
Value2 = 7, | ||
} | ||
|
||
public enum Enum2 | ||
{ | ||
Value1, | ||
Value2, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
using Riok.Mapperly.Abstractions; | ||
|
||
// this is tested with EnumMapper in MapperDefaultsTest | ||
[assembly: MapperDefaults(EnumMappingStrategy = EnumMappingStrategy.ByName)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System.Threading.Tasks; | ||
using FluentAssertions; | ||
using Riok.Mapperly.IntegrationTests.Mapper; | ||
using VerifyXunit; | ||
using Xunit; | ||
|
||
namespace Riok.Mapperly.IntegrationTests | ||
{ | ||
[UsesVerify] | ||
public class MapperDefaultsTest : BaseMapperTest | ||
{ | ||
[Fact] | ||
public Task SnapshotGeneratedSource() | ||
{ | ||
var path = GetGeneratedMapperFilePath(nameof(EnumMapper)); | ||
return Verifier.VerifyFile(path); | ||
} | ||
|
||
[Fact] | ||
public void RunMappingShouldWork() | ||
{ | ||
var enum2 = EnumMapper.Map(Enum1.Value1); | ||
enum2.Should().Be(Enum2.Value1); | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...pperly.IntegrationTests/_snapshots/MapperDefaultsTest.SnapshotGeneratedSource.verified.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// <auto-generated /> | ||
#nullable enable | ||
namespace Riok.Mapperly.IntegrationTests.Mapper | ||
{ | ||
public static partial class EnumMapper | ||
{ | ||
public static partial global::Riok.Mapperly.IntegrationTests.Mapper.Enum2 Map(global::Riok.Mapperly.IntegrationTests.Mapper.Enum1 e) | ||
{ | ||
return e switch | ||
{ | ||
global::Riok.Mapperly.IntegrationTests.Mapper.Enum1.Value1 => global::Riok.Mapperly.IntegrationTests.Mapper.Enum2.Value1, | ||
global::Riok.Mapperly.IntegrationTests.Mapper.Enum1.Value2 => global::Riok.Mapperly.IntegrationTests.Mapper.Enum2.Value2, | ||
_ => throw new System.ArgumentOutOfRangeException(nameof(e), e, "The value of enum Enum1 is not supported"), | ||
}; | ||
} | ||
} | ||
} |