本文整理汇总了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>();
}
}
示例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);
}
}
示例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");
}
}
示例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!");
}
}