Skip to content

Commit 81060a5

Browse files
author
Roman Rusov
committed
Fix mapping to Nullable<Guid>
1 parent 25b6b9c commit 81060a5

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ TestResults
88
## Ignore Visual Studio temporary files, build results, and
99
## files generated by popular Visual Studio add-ons.
1010

11+
# Visual Studio cache/options directory
12+
.vs/
13+
1114
# User-specific files
1215
*.suo
1316
*.user
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
using NUnit.Framework;
3+
using static Slapper.AutoMapper.Configuration;
4+
5+
namespace Slapper.Tests.ConvertersTests
6+
{
7+
[TestFixture]
8+
public class GuidConverterTests
9+
{
10+
private readonly GuidConverter converter = new GuidConverter();
11+
12+
[TestCase(typeof(Guid))]
13+
[TestCase(typeof(Guid?))]
14+
public void Can_Convert_To_Type(Type targetType)
15+
{
16+
// Act + Assert
17+
Assert.True(this.converter.CanConvert(null, targetType)); // Input value does not matter, null is enough for the test.
18+
}
19+
}
20+
}

Slapper.AutoMapper.Tests/Slapper.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
<ItemGroup>
4646
<Compile Include="ArrayTests.cs" />
4747
<Compile Include="ComplexMapsParentsAndChlidTest.cs" />
48+
<Compile Include="ConvertersTests\GuidConverterTests.cs" />
4849
<Compile Include="EmptyList.cs" />
4950
<Compile Include="HashCollisionTests.cs" />
5051
<Compile Include="MapCollectionsTypedTest.cs" />

Slapper.AutoMapper/Slapper.AutoMapper.Configuration.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ public object Convert(object value, Type type)
192192
/// <returns>Boolean response.</returns>
193193
public bool CanConvert(object value, Type type)
194194
{
195-
return type == typeof(Guid);
195+
var conversionType = Nullable.GetUnderlyingType(type) ?? type;
196+
return conversionType == typeof(Guid);
196197
}
197198

198199
/// <summary>

0 commit comments

Comments
 (0)