Example #1
0
        public void CreateWithSingleJsonPostRequest_WriteTo_ResultIsAsExpected()
        {
            string boundary = "theBoundary";
            string host     = "http://www.ya.ru:9090/";
            string query    = "myquery";

            var vm = new VmMock
            {
                Age  = 42,
                Name = "Foo"
            };

            var    getRequest       = HttpClientRequest.CreatePost(query).SetJsonContent(vm);
            var    multipartContent = new MultipartContent(new[] { getRequest }, boundary);
            string parsed           = GetContentString(host, multipartContent);


            string vmSerialized = JsonHelper.Serialize(vm);

            string expected = "--" + boundary + "\r\n" +
                              "Content-Type: application/http; msgtype=request\r\n\r\n" +
                              $"POST /{query} HTTP/1.1\r\n" +
                              "Host: www.ya.ru:9090\r\n" +
                              "Content-Type: application/json; charset=utf-8\r\n\r\n" +
                              vmSerialized + "\r\n" +
                              "--" + boundary + "--";

            Assert.AreEqual(expected, parsed);
        }