@@ -46,6 +46,37 @@ public void ObjectCanBeSerializedToXml()
46
46
. StatusCode ( 201 ) ;
47
47
}
48
48
49
+ public record BlogPostRecord ( int id , string title , string body )
50
+ {
51
+ /// <summary>
52
+ /// Initializes a new instance of the <see cref="BlogPostRecord"/> class.
53
+ /// </summary>
54
+ public BlogPostRecord ( )
55
+ : this ( 0 , string . Empty , string . Empty )
56
+ {
57
+ }
58
+ }
59
+
60
+ /// <summary>
61
+ /// A test demonstrating RestAssuredNet syntax for serializing
62
+ /// and sending an XML request body when performing an HTTP POST.
63
+ /// </summary>
64
+ [ Test ]
65
+ public void RecordCanBeSerializedToXml ( )
66
+ {
67
+ this . CreateStubForXmlRequestBodyFromRecord ( ) ;
68
+
69
+ var post = new BlogPostRecord ( 123 , "My blog post title" , "My blog post body" ) ;
70
+
71
+ Given ( )
72
+ . ContentType ( "application/xml" )
73
+ . Body ( post )
74
+ . When ( )
75
+ . Post ( $ "{ MOCK_SERVER_BASE_URL } /xml-serialization-from-record")
76
+ . Then ( )
77
+ . StatusCode ( 201 ) ;
78
+ }
79
+
49
80
/// <summary>
50
81
/// Verifies that the correct exception is thrown when the request body
51
82
/// cannot be serialized based on the Content-Type header value.
@@ -79,5 +110,16 @@ private void CreateStubForXmlRequestBody()
79
110
. RespondWith ( Response . Create ( )
80
111
. WithStatusCode ( 201 ) ) ;
81
112
}
113
+
114
+ /// <summary>
115
+ /// Creates the stub response for the XML request body example using a record.
116
+ /// </summary>
117
+ private void CreateStubForXmlRequestBodyFromRecord ( )
118
+ {
119
+ this . Server ? . Given ( Request . Create ( ) . WithPath ( "/xml-serialization-from-record" ) . UsingPost ( )
120
+ . WithBody ( new XPathMatcher ( "//BlogPostRecord/id[text()='123']" ) ) )
121
+ . RespondWith ( Response . Create ( )
122
+ . WithStatusCode ( 201 ) ) ;
123
+ }
82
124
}
83
125
}
0 commit comments