本文整理汇总了C#中ConcreteApiController.BadRequest方法的典型用法代码示例。如果您正苦于以下问题:C# ConcreteApiController.BadRequest方法的具体用法?C# ConcreteApiController.BadRequest怎么用?C# ConcreteApiController.BadRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConcreteApiController
的用法示例。
在下文中一共展示了ConcreteApiController.BadRequest方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ApiController_BadRequest
public void ApiController_BadRequest()
{
// Arrange
var controller = new ConcreteApiController();
// Act
var result = controller.BadRequest();
// Assert
Assert.Equal(StatusCodes.Status400BadRequest, Assert.IsType<BadRequestResult>(result).StatusCode);
}
示例2: ApiController_BadRequest_Message
public void ApiController_BadRequest_Message()
{
// Arrange
var controller = new ConcreteApiController();
// Act
var result = controller.BadRequest("Error");
// Assert
var badRequest = Assert.IsType<BadRequestErrorMessageResult>(result);
Assert.Equal("Error", badRequest.Message);
var httpError = Assert.IsType<HttpError>(badRequest.Value);
Assert.Equal("Error", httpError.Message);
}
示例3: ApiController_BadRequest_ModelState
public void ApiController_BadRequest_ModelState()
{
// Arrange
var controller = new ConcreteApiController();
var modelState = new ModelStateDictionary();
modelState.AddModelError("product.Name", "Name is required");
// Act
var result = controller.BadRequest(modelState);
// Assert
var badRequest = Assert.IsType<InvalidModelStateResult>(result);
var modelError = Assert.IsType<HttpError>(badRequest.Value).ModelState;
Assert.Equal(new string[] { "Name is required" }, modelError["product.Name"]);
}