@@ -62,9 +62,9 @@ public void DictionaryCanBeSerializedToJson()
62
62
63
63
Dictionary < string , object > post = new Dictionary < string , object >
64
64
{
65
- { "Id " , this . blogPost . Id } ,
66
- { "Title " , this . blogPost . Title } ,
67
- { "Body " , this . blogPost . Body } ,
65
+ { "id " , this . blogPost . Id } ,
66
+ { "title " , this . blogPost . Title } ,
67
+ { "body " , this . blogPost . Body } ,
68
68
} ;
69
69
70
70
Given ( )
@@ -86,9 +86,9 @@ public void AnonymousObjectCanBeSerializedToJson()
86
86
87
87
var post = new
88
88
{
89
- Id = this . blogPost . Id ,
90
- Title = this . blogPost . Title ,
91
- Body = this . blogPost . Body ,
89
+ id = this . blogPost . Id ,
90
+ title = this . blogPost . Title ,
91
+ body = this . blogPost . Body ,
92
92
} ;
93
93
94
94
Given ( )
@@ -99,47 +99,27 @@ public void AnonymousObjectCanBeSerializedToJson()
99
99
. StatusCode ( 201 ) ;
100
100
}
101
101
102
+ private record BlogPostRecord ( int id , string title , string body ) ;
103
+
102
104
/// <summary>
103
105
/// A test demonstrating RestAssuredNet syntax for serializing
104
- /// and sending an XML request body when performing an HTTP POST.
106
+ /// a record type to JSON and sending it when performing an HTTP POST.
105
107
/// </summary>
106
108
[ Test ]
107
- public void ObjectCanBeSerializedToXml ( )
109
+ public void RecordCanBeSerializedToJson ( )
108
110
{
109
- this . CreateStubForXmlRequestBody ( ) ;
111
+ this . CreateStubForObjectSerialization ( ) ;
112
+
113
+ var post = new BlogPostRecord ( this . blogPost . Id , this . blogPost . Title , this . blogPost . Body ) ;
110
114
111
115
Given ( )
112
- . ContentType ( "application/xml" )
113
- . Body ( this . GetLocation ( ) )
116
+ . Body ( post )
114
117
. When ( )
115
- . Post ( $ "{ MOCK_SERVER_BASE_URL } /xml -serialization")
118
+ . Post ( $ "{ MOCK_SERVER_BASE_URL } /object -serialization")
116
119
. Then ( )
117
120
. StatusCode ( 201 ) ;
118
121
}
119
122
120
- /// <summary>
121
- /// Verifies that the correct exception is thrown when the request body
122
- /// cannot be serialized based on the Content-Type header value.
123
- /// </summary>
124
- [ Test ]
125
- public void UnableToSerializeThrowsTheExpectedException ( )
126
- {
127
- this . CreateStubForXmlRequestBody ( ) ;
128
-
129
- var rce = Assert . Throws < RequestCreationException > ( ( ) =>
130
- {
131
- Given ( )
132
- . ContentType ( "application/something" )
133
- . Body ( this . GetLocation ( ) )
134
- . When ( )
135
- . Post ( $ "{ MOCK_SERVER_BASE_URL } /xml-serialization")
136
- . Then ( )
137
- . StatusCode ( 201 ) ;
138
- } ) ;
139
-
140
- Assert . That ( rce ? . Message , Is . EqualTo ( "Could not determine how to serialize request based on specified content type 'application/something'" ) ) ;
141
- }
142
-
143
123
/// <summary>
144
124
/// Creates the stub response for the JSON string request body example.
145
125
/// </summary>
@@ -162,17 +142,6 @@ private void CreateStubForObjectSerialization()
162
142
. WithStatusCode ( 201 ) ) ;
163
143
}
164
144
165
- /// <summary>
166
- /// Creates the stub response for the XML request body example.
167
- /// </summary>
168
- private void CreateStubForXmlRequestBody ( )
169
- {
170
- this . Server ? . Given ( Request . Create ( ) . WithPath ( "/xml-serialization" ) . UsingPost ( )
171
- . WithBody ( new XPathMatcher ( "//Places[count(Place) = 2]" ) ) )
172
- . RespondWith ( Response . Create ( )
173
- . WithStatusCode ( 201 ) ) ;
174
- }
175
-
176
145
private string GetExpectedSerializedObject ( )
177
146
{
178
147
return this . blogPost . GetSerializedJson ( ) ;
0 commit comments