@@ -35,6 +35,7 @@ public void FindsIdNamedId()
3535 {
3636 // Arrange
3737 var mm = new ModelManager ( new PluralizationService ( ) ) ;
38+ mm . RegisterResourceType ( typeof ( Author ) ) ;
3839
3940 // Act
4041 PropertyInfo idprop = mm . GetIdProperty ( typeof ( Author ) ) ;
@@ -44,27 +45,30 @@ public void FindsIdNamedId()
4445 }
4546
4647 [ TestMethod ]
47- [ ExpectedException ( typeof ( InvalidOperationException ) ) ]
48- public void DoesntFindMissingId ( )
48+ public void Cant_register_model_with_missing_id ( )
4949 {
5050 // Arrange
5151 var mm = new ModelManager ( new PluralizationService ( ) ) ;
5252
5353 // Act
54- PropertyInfo idprop = mm . GetIdProperty ( typeof ( InvalidModel ) ) ;
54+ Action action = ( ) => mm . RegisterResourceType ( typeof ( InvalidModel ) ) ;
5555
5656 // Assert
57- Assert . Fail ( "An InvalidOperationException should be thrown and we shouldn't get here!" ) ;
57+ action . ShouldThrow < InvalidOperationException > ( )
58+ . Which . Message . Should ( )
59+ . Be ( "Unable to determine Id property for type JSONAPI.Tests.Core.ModelManagerTests+InvalidModel" ) ;
5860 }
5961
6062 [ TestMethod ]
6163 public void FindsIdFromAttribute ( )
6264 {
6365 // Arrange
6466 var mm = new ModelManager ( new PluralizationService ( ) ) ;
67+ mm . RegisterResourceType ( typeof ( CustomIdModel ) ) ;
6568
6669 // Act
6770 PropertyInfo idprop = mm . GetIdProperty ( typeof ( CustomIdModel ) ) ;
71+
6872 // Assert
6973 Assert . AreSame ( typeof ( CustomIdModel ) . GetProperty ( "Uuid" ) , idprop ) ;
7074 }
@@ -194,17 +198,22 @@ public void GetPropertyForJsonKeyTest()
194198 var pluralizationService = new PluralizationService ( ) ;
195199 var mm = new ModelManager ( pluralizationService ) ;
196200 Type authorType = typeof ( Author ) ;
201+ mm . RegisterResourceType ( authorType ) ;
197202
198203 // Act
199204 var idProp = mm . GetPropertyForJsonKey ( authorType , "id" ) ;
200205 var nameProp = mm . GetPropertyForJsonKey ( authorType , "name" ) ;
201206 var postsProp = mm . GetPropertyForJsonKey ( authorType , "posts" ) ;
202207
203208 // Assert
204- Assert . AreSame ( authorType . GetProperty ( "Id" ) , idProp ) ;
205- Assert . AreSame ( authorType . GetProperty ( "Name" ) , nameProp ) ;
206- Assert . AreSame ( authorType . GetProperty ( "Posts" ) , postsProp ) ;
209+ idProp . Property . Should ( ) . BeSameAs ( authorType . GetProperty ( "Id" ) ) ;
210+ idProp . Should ( ) . BeOfType < FieldModelProperty > ( ) ;
211+
212+ nameProp . Property . Should ( ) . BeSameAs ( authorType . GetProperty ( "Name" ) ) ;
213+ nameProp . Should ( ) . BeOfType < FieldModelProperty > ( ) ;
207214
215+ postsProp . Property . Should ( ) . BeSameAs ( authorType . GetProperty ( "Posts" ) ) ;
216+ postsProp . Should ( ) . BeOfType < RelationshipModelProperty > ( ) ;
208217 }
209218
210219 [ TestMethod ]
0 commit comments