Skip to content

Commit 4dbb4ca

Browse files
author
Chris Santero
committed
add test for primitive attribute value converte
1 parent 5013fef commit 4dbb4ca

2 files changed

Lines changed: 53 additions & 0 deletions

File tree

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using FluentAssertions;
2+
using JSONAPI.Core;
3+
using Microsoft.VisualStudio.TestTools.UnitTesting;
4+
using Newtonsoft.Json.Linq;
5+
6+
namespace JSONAPI.Tests.Core
7+
{
8+
[TestClass]
9+
public class PrimitiveTypeAttributeValueConverterTests
10+
{
11+
private class Class1
12+
{
13+
public int? NullableIntValue { get; set; }
14+
}
15+
16+
[TestMethod]
17+
public void GetValue_for_null()
18+
{
19+
// Arrange
20+
var property = typeof (Class1).GetProperty("NullableIntValue");
21+
var obj = new Class1
22+
{
23+
NullableIntValue = null
24+
};
25+
26+
// Act
27+
var converter = new PrimitiveTypeAttributeValueConverter<int?>(property);
28+
var actualValue = (JValue)converter.GetValue(obj);
29+
30+
// Assert
31+
((object)actualValue).Should().Be(null);
32+
}
33+
34+
[TestMethod]
35+
public void SetValue_for_null()
36+
{
37+
// Arrange
38+
var property = typeof(Class1).GetProperty("NullableIntValue");
39+
var obj = new Class1
40+
{
41+
NullableIntValue = 4
42+
};
43+
44+
// Act
45+
var converter = new PrimitiveTypeAttributeValueConverter<int?>(property);
46+
converter.SetValue(obj, JValue.CreateNull());
47+
48+
// Assert
49+
obj.NullableIntValue.Should().Be(null);
50+
}
51+
}
52+
}

JSONAPI.Tests/JSONAPI.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
<Compile Include="ActionFilters\DefaultSortingTransformerTests.cs" />
8686
<Compile Include="ActionFilters\DefaultFilteringTransformerTests.cs" />
8787
<Compile Include="Core\DefaultNamingConventionsTests.cs" />
88+
<Compile Include="Core\PrimitiveTypeAttributeValueConverterTests.cs" />
8889
<Compile Include="Core\EnumAttributeValueConverterTests.cs" />
8990
<Compile Include="Core\ResourceTypeRegistrarTests.cs" />
9091
<Compile Include="Core\ResourceTypeRegistryTests.cs" />

0 commit comments

Comments
 (0)