Beispiel #1
0
        public void Should_not_redirect_from_model_when_no_redirect_specified()
        {
            var result = WebClient.GetJson <Handler.RedirectModel>("RedirectModel?redirect=false");

            result.Status.ShouldEqual(HttpStatusCode.OK);
            result.Data.Value.ShouldEqual("value");
        }
Beispiel #2
0
        public void Should_create_url_alias()
        {
            var result = WebClient.GetJson <Handler.OutputModel>("SomeAlias");

            result.Status.ShouldEqual(HttpStatusCode.OK);
            result.Data.Value.ShouldEqual("fark");
        }
Beispiel #3
0
        public void Should_get_with_no_response()
        {
            var result = WebClient.GetString("WithNoResponse");

            result.Status.ShouldEqual(HttpStatusCode.NoContent);
            result.Data.ShouldBeEmpty();
        }
Beispiel #4
0
        public void Should_get_xml()
        {
            var result = WebClient.GetXml <Handler.OutputModel>("WithResponse");

            result.Status.ShouldEqual(HttpStatusCode.OK);
            result.Data.Value.ShouldEqual("fark");
        }
Beispiel #5
0
        public void Should_post_and_return_string()
        {
            var result = WebClient.PostString("String", "fark");

            result.Status.ShouldEqual(HttpStatusCode.OK);
            result.Data.ShouldEqual("fark");
        }
Beispiel #6
0
        public void Should_include_path_in_namespace()
        {
            var result = WebClient.GetJson <Handler.OutputModel>("SomeNamespace/SomeMethod");

            result.Status.ShouldEqual(HttpStatusCode.OK);
            result.Data.Value.ShouldEqual("fark");
        }
Beispiel #7
0
        public void Should_get_with_wildcard_parameters()
        {
            var result = WebClient.GetJson <Handler.OutputModel>(
                "WithSingleValueWildcard/1/2/3/4/5");

            result.Status.ShouldEqual(HttpStatusCode.OK);
            result.Data.UrlWildcard.ShouldEqual("1/2/3/4/5");
        }
Beispiel #8
0
        public void Should_redirect([Values("Redirect",
                                            "RedirectModel?redirect=true")] string url)
        {
            var result = WebClient.GetString(url);

            result.Status.ShouldEqual(HttpStatusCode.OK);
            result.Data.ShouldContain("google");
        }
Beispiel #9
0
        public void Should_post_form_url_encoded_multi_params_to_model()
        {
            var result = WebClient.PostForm <Handler.OutputModel>("WithResponse",
                                                                  "multiform1=forma&multiform2=6&multiform1=formb&multiform2=7");

            result.Status.ShouldEqual(HttpStatusCode.OK);
            result.Data.MultiForm1.ShouldOnlyContain("forma", "formb");
            result.Data.MultiForm2.ShouldOnlyContain(6, 7);
        }
Beispiel #10
0
        public void Should_post_form_url_encoded_to_model()
        {
            var result = WebClient.PostForm <Handler.OutputModel>("WithResponse",
                                                                  "form1=forma&form2=6&form1=formb&form2=7");

            result.Status.ShouldEqual(HttpStatusCode.OK);
            result.Data.Form1.ShouldEqual("forma");
            result.Data.Form2.ShouldEqual(6);
        }
Beispiel #11
0
        public void Should_post_form_url_encoded_multi_to_params()
        {
            var result = WebClient.PostForm <Handler.OutputModel>("WithMultiQueryParams",
                                                                  "query1=querya&query2=6&query1=queryb&query2=7");

            result.Status.ShouldEqual(HttpStatusCode.OK);
            result.Data.MultiQuery1.ShouldOnlyContain("querya", "queryb");
            result.Data.MultiQuery2.ShouldOnlyContain(6, 7);
        }
Beispiel #12
0
        public void Should_return_400_when_there_is_a_param_parsing_error()
        {
            var result = WebClient.GetJson <Handler.OutputModel>(
                "WithQueryParam?query=fark");

            result.Status.ShouldEqual(HttpStatusCode.BadRequest);
            result.StatusText.ShouldContain("query");
            result.StatusText.ShouldContain("fark");
        }
Beispiel #13
0
        public void Should_get_multi_wildcard_parameters(
            [Values("WithParamsWildcard", "WithAttriubteWildcard")] string url)
        {
            var result = WebClient.GetJson <Handler.OutputModel>(
                $"{url}/1/2/3/4/5");

            result.Status.ShouldEqual(HttpStatusCode.OK);
            result.Data.UrlMultiWildcard.ShouldOnlyContain(1, 2, 3, 4, 5);
        }
Beispiel #14
0
        public void Should_get_with_response_multiple_querystring_parameters()
        {
            var result = WebClient.GetJson <Handler.OutputModel>(
                "WithMultiQueryParams?query1=querya&query2=6&query1=queryb&query2=7");

            result.Status.ShouldEqual(HttpStatusCode.OK);
            result.Data.MultiQuery1.ShouldOnlyContain("querya", "queryb");
            result.Data.MultiQuery2.ShouldOnlyContain(6, 7);
        }
Beispiel #15
0
        public void Should_post_form_url_encoded_to_params(
            [Values("", "&query1=query1b&query2=7")] string querystring)
        {
            var result = WebClient.PostForm <Handler.OutputModel>(
                "WithQueryParams", $"query1=query1&query2=6{querystring}");

            result.Status.ShouldEqual(HttpStatusCode.OK);
            result.Data.Query1.ShouldEqual("query1");
            result.Data.Query2.ShouldEqual(6);
        }
Beispiel #16
0
        public void Should_post_and_return_xml()
        {
            var result = WebClient.PostXml <Handler.InputModel, Handler.OutputModel>("WithResponse",
                                                                                     new Handler.InputModel {
                Value = "fark"
            });

            result.Status.ShouldEqual(HttpStatusCode.OK);
            result.Data.Value.ShouldEqual("fark");
        }
Beispiel #17
0
        public void Should_post_stream(string url, string mimetype, string filename, int?length)
        {
            var result = WebClient.PostStream <Handler.StreamInfoModel>(url,
                                                                        new MemoryStream(Encoding.UTF8.GetBytes("fark")),
                                                                        "application/video", "weddingsinger.mp4");

            result.Data.Filename.ShouldEqual(filename);
            result.Data.MimeType.ShouldEqual(mimetype);
            result.Data.Length.ShouldEqual(length);
        }
Beispiel #18
0
        public void Should_get_stream([Values("Stream1", "Stream2")] string url)
        {
            var result = WebClient.GetStream(url, data =>
            {
                data.ReadAllText().ShouldEqual("fark");
            });

            result.Status.ShouldEqual(HttpStatusCode.OK);
            result.Filename.ShouldEqual("weddingsinger.mp4");
            result.ContentType.ShouldEqual("application/video");
        }
Beispiel #19
0
        public void Should_get_with_response_querystring_and_url_parameters(
            [Values("", "&query1=query1b&query2=7")] string querystring)
        {
            var result = WebClient.GetJson <Handler.OutputModel>(
                $"WithResponseUrlAndQueryParams/url1/segment/5?query1=query1&query2=6{querystring}");

            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);
        }
Beispiel #20
0
        public void Should_delete_with_response([Values("",
                                                        "&query1=query1b&query2=7")] string querystring)
        {
            var result = WebClient.DeleteJson <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);
        }
        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");
        }
Beispiel #22
0
 public void Should_delete_with_no_response()
 {
     WebClient.DeleteJson("WithNoResponse", new Handler.InputModel())
     .Status.ShouldEqual(HttpStatusCode.NoContent);
 }