1- using System ;
2- using Microsoft . VisualStudio . TestTools . UnitTesting ;
1+ using Microsoft . VisualStudio . TestTools . UnitTesting ;
32using JSONAPI . Json ;
43using System . IO ;
54using JSONAPI . Tests . Models ;
@@ -11,29 +10,28 @@ namespace JSONAPI.Tests.Core
1110 public class MetadataManagerTests
1211 {
1312 [ TestMethod ]
13+ [ DeploymentItem ( @"Data\MetadataManagerPropertyWasPresentRequest.json" ) ]
1414 public void PropertyWasPresentTest ( )
1515 {
16- // Arrange
16+ using ( var inputStream = File . OpenRead ( "MetadataManagerPropertyWasPresentRequest.json" ) )
17+ {
18+ // Arrange
19+ JsonApiFormatter formatter = new JsonApiFormatter ( new PluralizationService ( ) ) ;
1720
18- JsonApiFormatter formatter = new JSONAPI . Json . JsonApiFormatter ( new JSONAPI . Core . PluralizationService ( ) ) ;
19- MemoryStream stream = new MemoryStream ( ) ;
21+ var p = ( Post ) formatter . ReadFromStreamAsync ( typeof ( Post ) , inputStream , null , null ) . Result ;
2022
21- stream = new MemoryStream ( System . Text . Encoding . ASCII . GetBytes ( @"{""posts"":{""id"":42,""links"":{""author"":""18""}}}" ) ) ;
23+ // Act
24+ bool idWasSet = MetadataManager . Instance . PropertyWasPresent ( p , p . GetType ( ) . GetProperty ( "Id" ) ) ;
25+ bool titleWasSet = MetadataManager . Instance . PropertyWasPresent ( p , p . GetType ( ) . GetProperty ( "Title" ) ) ;
26+ bool authorWasSet = MetadataManager . Instance . PropertyWasPresent ( p , p . GetType ( ) . GetProperty ( "Author" ) ) ;
27+ bool commentsWasSet = MetadataManager . Instance . PropertyWasPresent ( p , p . GetType ( ) . GetProperty ( "Comments" ) ) ;
2228
23- Post p ;
24- p = ( Post ) formatter . ReadFromStreamAsync ( typeof ( Post ) , stream , ( System . Net . Http . HttpContent ) null , ( System . Net . Http . Formatting . IFormatterLogger ) null ) . Result ;
25-
26- // Act
27- bool idWasSet = MetadataManager . Instance . PropertyWasPresent ( p , p . GetType ( ) . GetProperty ( "Id" ) ) ;
28- bool titleWasSet = MetadataManager . Instance . PropertyWasPresent ( p , p . GetType ( ) . GetProperty ( "Title" ) ) ;
29- bool authorWasSet = MetadataManager . Instance . PropertyWasPresent ( p , p . GetType ( ) . GetProperty ( "Author" ) ) ;
30- bool commentsWasSet = MetadataManager . Instance . PropertyWasPresent ( p , p . GetType ( ) . GetProperty ( "Comments" ) ) ;
31-
32- // Assert
33- Assert . IsTrue ( idWasSet , "Id was not reported as set, but was." ) ;
34- Assert . IsFalse ( titleWasSet , "Title was reported as set, but was not." ) ;
35- Assert . IsTrue ( authorWasSet , "Author was not reported as set, but was." ) ;
36- Assert . IsFalse ( commentsWasSet , "Comments was reported as set, but was not." ) ;
29+ // Assert
30+ Assert . IsTrue ( idWasSet , "Id was not reported as set, but was." ) ;
31+ Assert . IsFalse ( titleWasSet , "Title was reported as set, but was not." ) ;
32+ Assert . IsTrue ( authorWasSet , "Author was not reported as set, but was." ) ;
33+ Assert . IsFalse ( commentsWasSet , "Comments was reported as set, but was not." ) ;
34+ }
3735 }
3836 }
3937}
0 commit comments