示例#1
0
        public void Should_post_with_response(
            [Values("", "&query1=query1b&query2=7")] string querystring)
        {
            var result = WebClient.PostJson <Handler.InputModel, Handler.OutputModel>(
                $"WithResponseUrlAndQueryParams/url1/segment/5?query1=query1&query2=6{querystring}",
                new Handler.InputModel {
                Value = "fark"
            });

            result.Status.ShouldEqual(HttpStatusCode.OK);
            result.Data.Value.ShouldEqual("fark");
            result.Data.Url1.ShouldEqual("url1");
            result.Data.Url2.ShouldEqual(5);
            result.Data.Query1.ShouldEqual("query1");
            result.Data.Query2.ShouldEqual(6);
        }
示例#2
0
        public void PerformanceComparison()
        {
            var iterations = 100;

            var graphite         = new ConcurrentBag <long>();
            var graphiteAsync    = new ConcurrentBag <long>();
            var webapi           = new ConcurrentBag <long>();
            var webapiAsync      = new ConcurrentBag <long>();
            var guid             = Guid.NewGuid();
            var url              = $"performancetests/{{0}}/url1/{guid}/5?query1=query1&query2={guid}&query3=5";
            var urlAsync         = $"performancetests/{{0}}/async/url1/{guid}/5?query1=query1&query2={guid}&query3=5";
            var graphiteUrl      = string.Format(url, "graphite");
            var graphiteAsyncUrl = string.Format(urlAsync, "graphite");
            var webapiUrl        = string.Format(url, "webapi");
            var webapiAsyncUrl   = string.Format(urlAsync, "webapi");
            var inputModel       = new PerfInputModel
            {
                Value1 = "value1",
                Value2 = "value2",
                Value3 = "value3"
            };

            10.TimesParallel(() =>
            {
                Should_match_result(WebClient.PostJson <PerfInputModel, PerfOutputModel>(graphiteUrl, inputModel), guid);
                Should_match_result(WebClient.PostJson <PerfInputModel, PerfOutputModel>(webapiUrl, inputModel), guid);
                Should_match_result(WebClient.PostJson <PerfInputModel, PerfOutputModel>(graphiteAsyncUrl, inputModel), guid);
                Should_match_result(WebClient.PostJson <PerfInputModel, PerfOutputModel>(webapiAsyncUrl, inputModel), guid);
            });

            iterations.TimesParallel(() =>
            {
                graphite.Add(graphiteUrl.ElapsedMilliseconds(x => WebClient.PostJson <PerfInputModel, PerfOutputModel>(x, inputModel)));
                webapi.Add(webapiUrl.ElapsedMilliseconds(x => WebClient.PostJson <PerfInputModel, Handler.OutputModel>(x, inputModel)));
                graphiteAsync.Add(graphiteUrl.ElapsedMilliseconds(x => WebClient.PostJson <PerfInputModel, PerfOutputModel>(x, inputModel)));
                webapiAsync.Add(webapiUrl.ElapsedMilliseconds(x => WebClient.PostJson <PerfInputModel, Handler.OutputModel>(x, inputModel)));
            });

            Console.WriteLine($"Graphite :      {graphite.Average()}ms");
            Console.WriteLine($"Graphite Async: {graphiteAsync.Average()}ms");
            Console.WriteLine($"Web Api:        {webapi.Average()}ms");
            Console.WriteLine($"Web Api Async:  {webapiAsync.Average()}ms");
        }
示例#3
0
 public void Should_post_with_no_response()
 {
     WebClient.PostJson("WithNoResponse", new Handler.InputModel())
     .Status.ShouldEqual(HttpStatusCode.NoContent);
 }