22
33public static class RequestBuilderExtension
44{
5+ /// <summary>
6+ /// Configures the RequestBuilder to use the HTTP GET method and the specified request URI pattern.
7+ /// </summary>
8+ /// <param name="builder">The RequestBuilder to configure.</param>
9+ /// <param name="pattern">The request URI or URI template to apply to the builder.</param>
10+ /// <exception cref="System.ArgumentNullException">when the builder or pattern is null</exception>
11+ /// <returns>The configured RequestBuilder.</returns>
512 public static RequestBuilder Get ( this RequestBuilder builder , string pattern )
613 {
714 Guard . ThrowIfNull ( builder ) ;
815 return builder . WithMethod ( HttpMethod . Get ) . WithRequestUri ( pattern ) ;
916 }
1017
18+ /// <summary>
19+ /// Configures the RequestBuilder to use the HTTP POST method, the specified request URI pattern and content.
20+ /// </summary>
21+ /// <param name="builder">The RequestBuilder to configure.</param>
22+ /// <param name="pattern">The request URI or URI template to apply to the builder.</param>
23+ /// <param name="content">The expected content, supports wildcards.</param>
24+ /// <exception cref="System.ArgumentNullException">when the builder or pattern is null</exception>
25+ /// <returns>The configured RequestBuilder.</returns>
1126 public static RequestBuilder Post ( this RequestBuilder builder , string pattern , string content )
1227 {
1328 Guard . ThrowIfNull ( builder ) ;
1429 return builder . WithMethod ( HttpMethod . Post ) . WithRequestUri ( pattern ) . WithContent ( content ) ;
1530 }
1631
32+ /// <summary>
33+ /// Creates a POST request with the specified request URI pattern and JSON content.
34+ /// </summary>
35+ /// <param name="builder">The RequestBuilder to configure.</param>
36+ /// <param name="pattern">The request URI or route pattern.</param>
37+ /// <param name="content">The object to serialize to JSON for the request body, or null.</param>
38+ /// <exception cref="System.ArgumentNullException">when the builder or pattern is null</exception>
39+ /// <returns>The configured RequestBuilder.</returns>
1740 public static RequestBuilder PostAsJson ( this RequestBuilder builder , string pattern , object ? content )
1841 {
1942 Guard . ThrowIfNull ( builder ) ;
2043
2144 return builder . WithMethod ( HttpMethod . Post ) . WithRequestUri ( pattern ) . WithJsonContent ( content ) ;
2245 }
2346
47+ /// <summary>
48+ /// Asserts whether requests are made with specific json content.
49+ /// </summary>
50+ /// <param name="builder">The implementation that hold all the request messages.</param>
51+ /// <param name="content">The object representation of the expected request content.</param>
52+ /// <returns>The <seealso cref="RequestBuilder"/> for further assertions.</returns>
2453 public static RequestBuilder WithJsonContent ( this RequestBuilder builder , object ? content ) => builder . WithJsonContent ( content , null ) ;
2554
55+ /// <summary>
56+ /// Asserts whether requests are made with specific json content.
57+ /// </summary>
58+ /// <param name="builder">The implementation that hold all the request messages.</param>
59+ /// <param name="content">The object representation of the expected request content.</param>
60+ /// <param name="options">The serializer options that should be used for serializing te content.</param>
61+ /// <returns>The <seealso cref="RequestBuilder"/> for further assertions.</returns>
2662 public static RequestBuilder WithJsonContent ( this RequestBuilder builder , object ? content , JsonSerializerOptions ? options )
2763 {
2864 Guard . ThrowIfNull ( builder ) ;
@@ -32,6 +68,12 @@ public static RequestBuilder WithJsonContent(this RequestBuilder builder, object
3268 return builder . WithContent ( jsonContent ) . WithHeader ( "Content-Type" , "application/json*" ) ;
3369 }
3470
71+ /// <summary>
72+ /// Asserts whether requests are made with specific url encoded content.
73+ /// </summary>
74+ /// <param name="builder">The implementation that hold all the request messages.</param>
75+ /// <param name="formValues">The collection of key/value pairs that should be url encoded.</param>
76+ /// <returns>The <seealso cref="IHttpRequestMessagesCheck"/> for further assertions.</returns>
3577 public static RequestBuilder WithFormUrlEncodedContent ( this RequestBuilder builder , IEnumerable < KeyValuePair < string ? , string ? > > formValues )
3678 {
3779 Guard . ThrowIfNull ( builder ) ;
0 commit comments