本文整理汇总了C#中Server.OnGet方法的典型用法代码示例。如果您正苦于以下问题:C# Server.OnGet方法的具体用法?C# Server.OnGet怎么用?C# Server.OnGet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Server
的用法示例。
在下文中一共展示了Server.OnGet方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SpecificPortNumberCanBeProvided
public void SpecificPortNumberCanBeProvided()
{
var firstServerWithoutPort = new Server(8765);
firstServerWithoutPort.OnGet("/").RespondWith("Rocking");
Assert.That(new Uri(firstServerWithoutPort.BaseUri).Port, Is.EqualTo(8765));
var response = new HttpClient().GetAsync(firstServerWithoutPort.BaseUri).Result.Content.ReadAsStringAsync().Result;
Assert.That(response, Is.EqualTo("Rocking"));
}
示例2: RandomPortNumberIsChosenWhenOmitted
public void RandomPortNumberIsChosenWhenOmitted()
{
var firstServerWithoutPort = new Server();
firstServerWithoutPort.OnGet("/").RespondWith("No problem");
var secondServerWithoutPort = new Server();
secondServerWithoutPort.OnGet("/").RespondWith("Still no problem");
Assert.That(firstServerWithoutPort.BaseUri, Is.Not.EqualTo(secondServerWithoutPort.BaseUri));
var client = new HttpClient();
var firstResponse = client.GetAsync(firstServerWithoutPort.BaseUri).Result.Content.ReadAsStringAsync().Result;
Assert.That(firstResponse, Is.EqualTo("No problem"));
var secondResponse = client.GetAsync(secondServerWithoutPort.BaseUri).Result.Content.ReadAsStringAsync().Result;
Assert.That(secondResponse, Is.EqualTo("Still no problem"));
}