当前位置: 首页>>代码示例>>C#>>正文


C# IHttpServer.WhatDoIHave方法代码示例

本文整理汇总了C#中IHttpServer.WhatDoIHave方法的典型用法代码示例。如果您正苦于以下问题:C# IHttpServer.WhatDoIHave方法的具体用法?C# IHttpServer.WhatDoIHave怎么用?C# IHttpServer.WhatDoIHave使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IHttpServer的用法示例。


在下文中一共展示了IHttpServer.WhatDoIHave方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Should_return_expected_ok_response

        public void Should_return_expected_ok_response()
        {
            _stubHttp = HttpMockRepository.At(_hostUrl);

            _stubHttp
                .Stub(x => x.Get("/api2/status"))
                .Return("Hello")
                .OK();

            _stubHttp
                .Stub(x => x.Get("/api2/echo"))
                .Return("Echo")
                .NotFound();

            _stubHttp
                .Stub(x => x.Get("/api2/echo2"))
                .Return("Nothing")
                .WithStatus(HttpStatusCode.Unauthorized);

            Console.WriteLine(_stubHttp.WhatDoIHave());

            var wc = new WebClient();

            Assert.That(wc.DownloadString(string.Format("{0}/api2/status", _hostUrl)), Is.EqualTo("Hello"));

            try
            {
                Console.WriteLine(wc.DownloadString(_hostUrl + "/api2/echo"));
            }
            catch (Exception ex)
            {
                Assert.That(ex, Is.InstanceOf(typeof (WebException)));
                Assert.That(((WebException) ex).Status, Is.EqualTo(WebExceptionStatus.ProtocolError));
            }

            try
            {
                wc.DownloadString(_hostUrl + "/api2/echo2");
            }
            catch (Exception ex)
            {
                Assert.That(ex, Is.InstanceOf(typeof (WebException)));
                Assert.That(((WebException) ex).Status, Is.EqualTo(WebExceptionStatus.ProtocolError));
            }
        }
开发者ID:TimGebhardt,项目名称:HttpMock,代码行数:45,代码来源:HttpEndPointTests.cs

示例2: Should_hit_the_same_url_multiple_times

        public void Should_hit_the_same_url_multiple_times()
        {
            string endpoint = "Http://localhost:9191";
            _stubHttp = HttpMockRepository.At(endpoint);

            _stubHttp
                .Stub(x => x.Get("/api2/echo"))
                .Return("Echo")
                .NotFound();

            _stubHttp
                .Stub(x => x.Get("/api2/echo2"))
                .Return("Nothing")
                .WithStatus(HttpStatusCode.Unauthorized);

            Console.WriteLine(_stubHttp.WhatDoIHave());

            for (int count = 0; count < 6; count++) {
                RequestEcho(endpoint);
            }
        }
开发者ID:knocte,项目名称:HttpMock,代码行数:21,代码来源:HttpEndPointTests.cs

示例3: SUT_should_return_stubbed_response

        public void SUT_should_return_stubbed_response()
        {
            _stubHttp = HttpMockRepository.At("http://localhost:9191");

            const string expected = "<xml><>response>Hello World</response></xml>";
            _stubHttp.Stub(x => x.Get("/endpoint"))
                .Return(expected)
                .OK();

            Console.WriteLine(_stubHttp.WhatDoIHave());

            string result = 	new WebClient().DownloadString("http://localhost:9191/endpoint");

            Console.WriteLine("RESPONSE: {0}", result);
            Assert.That(result, Is.EqualTo(expected));
        }
开发者ID:knocte,项目名称:HttpMock,代码行数:16,代码来源:HttpEndPointTests.cs

示例4: Should_support_range_requests

        public void Should_support_range_requests()
        {
            string host = "http://localhost:9191";
            _stubHttp = HttpMockRepository.At(host);
            string query = "/path/file";
            int fileSize = 2048;
            string pathToFile = CreateFile(fileSize);

            try
            {
                _stubHttp.Stub(x => x.Get(query))
                    .ReturnFileRange(pathToFile, 0, 1023)
                    .WithStatus(HttpStatusCode.PartialContent);

                Console.WriteLine(_stubHttp.WhatDoIHave());

                HttpWebRequest request = (HttpWebRequest) HttpWebRequest.Create(host + query);
                request.Method = "GET";
                request.AddRange(0, 1023);
                HttpWebResponse response = (HttpWebResponse) request.GetResponse();
                byte[] downloadData = new byte[response.ContentLength];
                using (response)
                {

                    response.GetResponseStream().Read(downloadData, 0, downloadData.Length);
                }
                Assert.That(downloadData.Length, Is.EqualTo(1024));

            } finally {
                try
                {
                    File.Delete(pathToFile);
                } catch (Exception ex) //IOException (or other) can happen
                {
                    Console.WriteLine("WARNING: TearDown of test couldn't be complete: " + ex);
                }
            }
        }
开发者ID:knocte,项目名称:HttpMock,代码行数:38,代码来源:HttpEndPointTests.cs

示例5: SUT_should_return_stubbed_response_for_custom_verbs

        public void SUT_should_return_stubbed_response_for_custom_verbs()
        {
            _stubHttp = HttpMockRepository.At(_hostUrl);

            const string expected = "<xml><>response>Hello World</response></xml>";
            _stubHttp.Stub(x => x.CustomVerb("/endpoint", "PURGE"))
                .Return(expected)
                .OK();

            Console.WriteLine(_stubHttp.WhatDoIHave());

            var request = (HttpWebRequest) WebRequest.Create(string.Format("{0}/endpoint", _hostUrl));
            request.Method = "PURGE";
            request.Host = "nonstandard.host";
            request.Headers.Add("X-Go-Faster", "11");
            using (var response = request.GetResponse())
            using (var stream = response.GetResponseStream())
            {
                var responseBody = new StreamReader(stream).ReadToEnd();
                Assert.That(responseBody, Is.EqualTo(expected));
            }
        }
开发者ID:TimGebhardt,项目名称:HttpMock,代码行数:22,代码来源:HttpEndPointTests.cs

示例6: SUT_should_return_stubbed_response

        public void SUT_should_return_stubbed_response()
        {
            _stubHttp = HttpMockRepository.At(_hostUrl);

            const string expected = "<xml><>response>Hello World</response></xml>";
            _stubHttp.Stub(x => x.Get("/endpoint"))
                .Return(expected)
                .OK();

            Console.WriteLine(_stubHttp.WhatDoIHave());

            string result = new WebClient().DownloadString(string.Format("{0}/endpoint", _hostUrl));

            Assert.That(result, Is.EqualTo(expected));
        }
开发者ID:TimGebhardt,项目名称:HttpMock,代码行数:15,代码来源:HttpEndPointTests.cs

示例7: Should_support_range_requests

        public void Should_support_range_requests()
        {
            _stubHttp = HttpMockRepository.At(_hostUrl);
            string query = "/path/file";
            int fileSize = 2048;
            string pathToFile = CreateFile(fileSize);

            try
            {
                _stubHttp.Stub(x => x.Get(query))
                    .ReturnFileRange(pathToFile, 0, 1023)
                    .WithStatus(HttpStatusCode.PartialContent);

                Console.WriteLine(_stubHttp.WhatDoIHave());

                HttpWebRequest request = (HttpWebRequest) HttpWebRequest.Create(_hostUrl + query);
                request.Method = "GET";
                request.AddRange(0, 1023);
                HttpWebResponse response = (HttpWebResponse) request.GetResponse();
                byte[] downloadData = new byte[response.ContentLength];
                using (response)
                {
                    response.GetResponseStream().Read(downloadData, 0, downloadData.Length);
                }
                Assert.That(downloadData.Length, Is.EqualTo(1024));
            }
            finally
            {
                try
                {
                    File.Delete(pathToFile);
                }
                catch
                {
                }
            }
        }
开发者ID:TimGebhardt,项目名称:HttpMock,代码行数:37,代码来源:HttpEndPointTests.cs


注:本文中的IHttpServer.WhatDoIHave方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。