Web Api 的单元测试
public void TestNewGreetingAdd(){//准备var greetingName = "testName";var greetingMessage = "Hello test";var fakeRequest = new HttpRequestMessage(HttpMethod.Post,"http://localhost:XXXX/api/greeting");var greeting = new Greeting { Name = greetingName , Message = greetingMessage };var service = new GreetingController();service.Request = fakeRequest;// 操作
var response = service.PostGreeting(greeting);//这是一个方法,方法提交谓词POST,需要参数greeting。//断言
Assert.NotNull(response);Assert.Equal(HttpStatusCode.Created,response.StatusCode);Assert.Equal(new Uri("Http://localhost:XXXX/api/greeting/newgreeting"),response.Headers.Location);
}
支持分享
页:
[1]