Esempio n. 1
0
 public static Task <HttpResponseMessage> PutAsJsonAsync <TEntity>(this RequestBuilder requestBuilder, TEntity entity)
 {
     return(requestBuilder.And(message =>
     {
         var body = JsonSerializer.Serialize(entity, options: _serializerOptions);
         message.Content = new StringContent(body, Encoding.UTF8, "application/json");
     }).SendAsync(HttpMethods.Put));
 }
 public static RequestBuilder WithJsonBody <TEntity>(this RequestBuilder builder, TEntity entity) where TEntity : class
 {
     return(builder.And(configure =>
     {
         var json = JsonConvert.SerializeObject(entity);
         configure.Content = new StringContent(json, Encoding.UTF8, "application/json");
     }));
 }
Esempio n. 3
0
        public static RequestBuilder WithJsonBody <TContent>(this RequestBuilder builder, TContent content, string contentType = "application/json")
        {
            var json = JsonConvert.SerializeObject(content);

            return(builder.And(message =>
            {
                message.Content = new StringContent(json, Encoding.UTF8, contentType);
            }));
        }
 public static Task <HttpResponseMessage> PatchAsJsonAsync <TEntity>(this RequestBuilder requestBuilder, JsonPatchDocument <TEntity> entity)
     where TEntity : class
 {
     return(requestBuilder.And(message =>
     {
         var body = JsonSerializer.Serialize(entity.Operations, options: _serializerOptions);
         message.Content = new StringContent(body, Encoding.UTF8, "application/json");
     }).SendAsync(HttpMethods.Patch));
 }
Esempio n. 5
0
        private static void AddFromHeaderArgumentsToRequestForm(
            RequestBuilder requestBuilder,
            TestServerAction action)
        {
            var fromHeaderArguments = action.ArgumentValues.Values.Where(x => x.IsFromHeader);

            foreach (var fromHeaderArgument in fromHeaderArguments)
            {
                requestBuilder.And(x => x.Headers.Add(fromHeaderArgument.HeaderName, fromHeaderArgument.Instance.ToString()));
            }
        }
Esempio n. 6
0
 public static RequestBuilder WithJsonBody(
     this RequestBuilder builder,
     object body)
 {
     return(builder.And(configure =>
     {
         configure.Content = new StringContent(
             content: JsonConvert.SerializeObject(body),
             encoding: Encoding.UTF8,
             mediaType: "application/json");
     }));
 }
        private static void AddFromBodyArgumentsToRequestBody(
            RequestBuilder requestBuilder,
            TestServerAction action,
            RequestContentOptions contentOptions)
        {
            var fromBodyArgument = action.ArgumentValues.Values.SingleOrDefault(x => x.IsBody);

            if (fromBodyArgument != null)
            {
                requestBuilder.And(x => x.Content =
                                       contentOptions.ContentBuilder(fromBodyArgument.Instance));
            }
        }