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