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


C# HttpServer.RAW方法代码示例

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


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

示例1: WhenWritingToTheStreamFail_ThenTryToRespond500

        public void WhenWritingToTheStreamFail_ThenTryToRespond500()
        {
            using(var server = new HttpServer("http://*:1234/", Scheduler.CurrentThread))
            {
                server.RAW("")
                    .Subscribe(ctx =>
                                   {
                                       var mockedResponse = new Mock<Response>(ctx, 201);
                                       mockedResponse.Setup(r => r.WriteStream(It.IsAny<Stream>()))
                                                     .Returns(Observable.Throw<Stream>(new InvalidOperationException()));
                                       mockedResponse.Object.Send();
                                   });

                Executing.This(() => Browser.ExecuteGet("http://localhost:1234/"))
                    .Should().Throw<WebException>();
            }
        }
开发者ID:Amsoft-Systems,项目名称:Anna,代码行数:17,代码来源:ServerTests.cs

示例2: UseSameThreadForAllRequests

        public void UseSameThreadForAllRequests()
        {
            var bag = new ConcurrentBag<int>();

            using (var server = new HttpServer("http://*:1234/"))
            {
                server.RAW("")
                      .Subscribe(ctx =>
                                     {
                                         bag.Add(Thread.CurrentThread.ManagedThreadId);
                                         ctx.Respond(200);
                                     });
                Parallel.For(1, 1000, i => Browser.ExecuteGet("http://localhost:1234/"));

                bag.Distinct().Count()
                   .Should("The default scheduler should be Event Loop, and all subscriber run in same thread")
                   .Be.EqualTo(1);

            }
        }
开发者ID:Amsoft-Systems,项目名称:Anna,代码行数:20,代码来源:ServerTests.cs

示例3: WhenSubscribingToRaw_ThenIgnoreTheMethod

        public void WhenSubscribingToRaw_ThenIgnoreTheMethod()
        {
            using (var server = new HttpServer("http://*:1234/"))
            {
                server.RAW("customer/{name}")
                      .Subscribe(ctx => ctx.Respond(string.Format("hello {0}", ctx.Request.UriArguments.name)));

                Browser.ExecuteGet("http://localhost:1234/customer/peter")
                    .ReadAllContent().Should().Be.EqualTo("hello peter");

                Browser.ExecutePost("http://localhost:1234/customer/peter")
                    .ReadAllContent().Should().Be.EqualTo("hello peter");
            }
        }
开发者ID:Amsoft-Systems,项目名称:Anna,代码行数:14,代码来源:ServerTests.cs

示例4: CanSubscribeToRawInARawPath

        public void CanSubscribeToRawInARawPath()
        {
            using (var server = new HttpServer("http://*:1234/"))
            {
                server.RAW("website/*")
                      .Subscribe(ctx => ctx.Respond("hello master of puppets!"));

                Browser.ExecuteGet("http://localhost:1234/website/a/b/c/peter?thisQueryString=asdasdsa")
                    .ReadAllContent().Should().Be.EqualTo("hello master of puppets!");

                Browser.ExecutePost("http://localhost:1234/website/abcdeefasdasds?a=cdef")
                    .ReadAllContent().Should().Be.EqualTo("hello master of puppets!");
            }
        }
开发者ID:Amsoft-Systems,项目名称:Anna,代码行数:14,代码来源:ServerTests.cs


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