public static void DataFormatBody <T>(this BrowserContext browserContext, DataFormat format, T model)
        {
            switch (format)
            {
            case DataFormat.Json:
                browserContext.JsonBody(model);
                break;

            case DataFormat.Proto:
                var    descriptor = ProtobufResponse.GetDescriptor(typeof(T));
                object value      = SimpleValue.FromValue(model);
                if (value == null)
                {
                    value = model;
                }

                var bytes = descriptor.Write(value);
                browserContext.Body(new MemoryStream(bytes), "application/x-protobuf");
                browserContext.Header("Content-Length", bytes.Length.ToString());
                break;

            default:
                throw new NotImplementedException();
            }
        }
Exemplo n.º 2
0
 public static BrowserContext JsonBrowserContext(this BrowserContext context, object request)
 {
     context.Body(JsonConvert.SerializeObject(request));
     context.Header("Content-Type", "application/json");
     return(context);
 }
Exemplo n.º 3
0
 public static void BodyJson <T>(this BrowserContext context, T data)
 {
     context.Body(JsonConvert.SerializeObject(data), "application/json");
     context.Accept(new MediaRange("application/json"));
 }