File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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" />
You can’t perform that action at this time.
0 commit comments