Ejemplo n.º 1
0
        public async Task CanSendAndReceiveCustomJson()
        {
            var    expectedJson = "{\"ArrayProperty\":[1,2,3],\"ModelProperty\":{\"Name\":\"Item\"},\"ObjectProperty\":{\"b\":{}}}";
            string actualJson   = null;

            using var testServer = new InProcTestServer(async content =>
            {
                actualJson = (await JsonDocument.ParseAsync(content.Request.Body)).RootElement.ToString();

                await content.Response.WriteAsync(expectedJson);
            });

            var model = new PropertyToJsonElementModel();

            model.ArrayProperty  = JsonDocument.Parse("[1, 2, 3]").RootElement;
            model.ObjectProperty = JsonDocument.Parse("{ \"b\": {} }").RootElement;
            model.ModelProperty  = JsonDocument.Parse("{ \"Name\": \"Item\" }").RootElement;

            var responseModel = await new ServiceClient(ClientDiagnostics, HttpPipeline, testServer.Address).PropertyToJsonElementModelAsync(model);

            Assert.AreEqual(expectedJson, actualJson);
            Assert.AreEqual("[1,2,3]", responseModel.Value.ArrayProperty.ToString());
            Assert.AreEqual("{\"b\":{}}", responseModel.Value.ObjectProperty.ToString());
            Assert.AreEqual("{\"Name\":\"Item\"}", responseModel.Value.ModelProperty.ToString());
        }
Ejemplo n.º 2
0
 public virtual Response <PropertyToJsonElementModel> PropertyToJsonElementModel(PropertyToJsonElementModel model, CancellationToken cancellationToken = default)
 {
     using var scope = _clientDiagnostics.CreateScope("ServiceClient.PropertyToJsonElementModel");
     scope.Start();
     try
     {
         return(RestClient.PropertyToJsonElementModel(model, cancellationToken));
     }
     catch (Exception e)
     {
         scope.Failed(e);
         throw;
     }
 }
Ejemplo n.º 3
0
 public virtual async Task <Response <PropertyToJsonElementModel> > PropertyToJsonElementModelAsync(PropertyToJsonElementModel model, CancellationToken cancellationToken = default)
 {
     using var scope = _clientDiagnostics.CreateScope("ServiceClient.PropertyToJsonElementModel");
     scope.Start();
     try
     {
         return(await RestClient.PropertyToJsonElementModelAsync(model, cancellationToken).ConfigureAwait(false));
     }
     catch (Exception e)
     {
         scope.Failed(e);
         throw;
     }
 }