本文整理汇总了C#中ConcreteApiController类的典型用法代码示例。如果您正苦于以下问题:C# ConcreteApiController类的具体用法?C# ConcreteApiController怎么用?C# ConcreteApiController使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ConcreteApiController类属于命名空间,在下文中一共展示了ConcreteApiController类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AccessDependentProperties_UnsetContext
public void AccessDependentProperties_UnsetContext()
{
// Arrange
var controller = new ConcreteApiController();
// Act & Assert
Assert.Null(controller.Context);
Assert.Null(controller.ModelState);
Assert.Null(controller.User);
}
示例2: 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);
}
示例3: 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);
}
示例4: AccessDependentProperties
public void AccessDependentProperties()
{
// Arrange
var controller = new ConcreteApiController();
var httpContext = new DefaultHttpContext();
httpContext.User = new ClaimsPrincipal();
var actionContext = new ActionContext(httpContext, new RouteData(), new ControllerActionDescriptor());
// Act
controller.ControllerContext = new ControllerContext(actionContext);
// Assert
Assert.Same(httpContext, controller.Context);
Assert.Same(actionContext.ModelState, controller.ModelState);
Assert.Same(httpContext.User, controller.User);
}
示例5: ApiController_Ok
public void ApiController_Ok()
{
// Arrange
var controller = new ConcreteApiController();
// Act
var result = controller.Ok();
// Assert
Assert.Equal(200, Assert.IsType<HttpOkResult>(result).StatusCode);
}
示例6: ApiController_NotFound
public void ApiController_NotFound()
{
// Arrange
var controller = new ConcreteApiController();
// Act
var result = controller.NotFound();
// Assert
Assert.Equal(404, Assert.IsType<HttpNotFoundResult>(result).StatusCode);
}
示例7: ApiController_Json_Settings_Encoding
public void ApiController_Json_Settings_Encoding()
{
// Arrange
var controller = new ConcreteApiController();
var product = new Product();
var settings = new JsonSerializerSettings();
// Act
var result = controller.Json(product, settings, Encoding.UTF8);
// Assert
var jsonResult = Assert.IsType<JsonResult>(result);
Assert.Same(product, jsonResult.Value);
var formatter = Assert.IsType<JsonOutputFormatter>(jsonResult.Formatter);
Assert.Same(settings, formatter.SerializerSettings);
Assert.Same(Encoding.UTF8, Assert.Single(formatter.SupportedEncodings));
}
示例8: ApiController_Json
public void ApiController_Json()
{
// Arrange
var controller = new ConcreteApiController();
var product = new Product();
// Act
var result = controller.Json(product);
// Assert
var jsonResult = Assert.IsType<JsonResult>(result);
Assert.Same(product, jsonResult.Value);
}
示例9: ApiController_ResponseMessage
public void ApiController_ResponseMessage()
{
// Arrange
var controller = new ConcreteApiController();
var response = new HttpResponseMessage(HttpStatusCode.NoContent);
// Act
var result = controller.ResponseMessage(response);
// Assert
var responseResult = Assert.IsType<ResponseMessageResult>(result);
Assert.Same(response, responseResult.Response);
}
示例10: ApiController_Redirect_String
public void ApiController_Redirect_String(string uri)
{
// Arrange
var controller = new ConcreteApiController();
// Act
var result = controller.Redirect(uri);
// Assert
var redirect = Assert.IsType<RedirectResult>(result);
Assert.Equal(uri, result.Url);
}
示例11: ApiController_Conflict
public void ApiController_Conflict()
{
// Arrange
var controller = new ConcreteApiController();
// Act
var result = controller.Conflict();
// Assert
Assert.Equal(StatusCodes.Status409Conflict, Assert.IsType<ConflictResult>(result).StatusCode);
}
示例12: ApiController_Created_String
public void ApiController_Created_String(string uri)
{
// Arrange
var controller = new ConcreteApiController();
var product = new Product();
// Act
var result = controller.Created(uri, product);
// Assert
var created = Assert.IsType<CreatedResult>(result);
Assert.Same(product, created.Value);
Assert.Equal(uri, created.Location);
}
示例13: ApiController_Created_Uri
public void ApiController_Created_Uri()
{
// Arrange
var controller = new ConcreteApiController();
var uri = new Uri("http://contoso.com/");
var product = new Product();
// Act
var result = controller.Created(uri, product);
// Assert
var created = Assert.IsType<CreatedResult>(result);
Assert.Same(product, created.Value);
Assert.Equal(uri.OriginalString, created.Location);
}
示例14: ApiController_Ok_Content
public void ApiController_Ok_Content()
{
// Arrange
var controller = new ConcreteApiController();
var product = new Product();
// Act
var result = controller.Ok(product);
// Assert
var okResult = Assert.IsType<OkNegotiatedContentResult<Product>>(result);
Assert.Same(product, okResult.Content);
}
示例15: ApiController_Ok_Content
public void ApiController_Ok_Content()
{
// Arrange
var controller = new ConcreteApiController();
var product = new Product();
// Act
var result = controller.Ok(product);
// Assert
var okResult = Assert.IsType<HttpOkObjectResult>(result);
Assert.Same(product, okResult.Value);
}