本文整理汇总了C#中TestableController.CreatedAtAction方法的典型用法代码示例。如果您正苦于以下问题:C# TestableController.CreatedAtAction方法的具体用法?C# TestableController.CreatedAtAction怎么用?C# TestableController.CreatedAtAction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TestableController
的用法示例。
在下文中一共展示了TestableController.CreatedAtAction方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreatedAtAction_IDisposableObject_RegistersForDispose
public void CreatedAtAction_IDisposableObject_RegistersForDispose()
{
// Arrange
var mockHttpContext = new Mock<DefaultHttpContext>();
mockHttpContext.Setup(x => x.Response.OnResponseCompleted(It.IsAny<Action<object>>(), It.IsAny<object>()));
var controller = new TestableController()
{
ActionContext = new ActionContext(mockHttpContext.Object, new RouteData(), new ActionDescriptor())
};
var input = new DisposableObject();
// Act
var result = controller.CreatedAtAction("SampleAction", input);
// Assert
Assert.IsType<CreatedAtActionResult>(result);
Assert.Equal(StatusCodes.Status201Created, result.StatusCode);
Assert.Equal("SampleAction", result.ActionName);
Assert.Same(input, result.Value);
mockHttpContext.Verify(
x => x.Response.OnResponseCompleted(It.IsAny<Action<object>>(), It.IsAny<object>()),
Times.Once());
}
示例2: CreatedAtAction_WithActionControllerRouteValues_SetsSameValues
public void CreatedAtAction_WithActionControllerRouteValues_SetsSameValues()
{
// Arrange
var controller = new TestableController();
var expected = new Dictionary<string, object>
{
{ "test", "case" },
{ "sample", "route" },
};
// Act
var result = controller.CreatedAtAction(
"SampleAction",
"SampleController",
new RouteValueDictionary(expected), null);
// Assert
Assert.IsType<CreatedAtActionResult>(result);
Assert.Equal(StatusCodes.Status201Created, result.StatusCode);
Assert.Equal("SampleAction", result.ActionName);
Assert.Equal("SampleController", result.ControllerName);
Assert.Equal(expected, result.RouteValues);
}
示例3: CreatedAtAction_WithParameterActionName_SetsResultActionName
public void CreatedAtAction_WithParameterActionName_SetsResultActionName()
{
// Arrange
var controller = new TestableController();
// Act
var result = controller.CreatedAtAction("SampleAction", null);
// Assert
Assert.IsType<CreatedAtActionResult>(result);
Assert.Equal(StatusCodes.Status201Created, result.StatusCode);
Assert.Equal("SampleAction", result.ActionName);
}
示例4: CreatedAtAction_WithActionControllerAndNullRouteValue_SetsSameValue
public void CreatedAtAction_WithActionControllerAndNullRouteValue_SetsSameValue(
string controllerName)
{
// Arrange
var controller = new TestableController();
// Act
var result = controller.CreatedAtAction("SampleAction", controllerName, null, null);
// Assert
Assert.IsType<CreatedAtActionResult>(result);
Assert.Equal(StatusCodes.Status201Created, result.StatusCode);
Assert.Equal("SampleAction", result.ActionName);
Assert.Equal(controllerName, result.ControllerName);
}
示例5: CreatedAtAction_IDisposableObject_RegistersForDispose
public void CreatedAtAction_IDisposableObject_RegistersForDispose()
{
// Arrange
var mockHttpContext = new Mock<HttpContext>();
mockHttpContext.Setup(x => x.Response.RegisterForDispose(It.IsAny<IDisposable>()));
var controller = new TestableController();
controller.ControllerContext.HttpContext = mockHttpContext.Object;
var input = new DisposableObject();
// Act
var result = controller.CreatedAtAction("SampleAction", input);
// Assert
Assert.IsType<CreatedAtActionResult>(result);
Assert.Equal(StatusCodes.Status201Created, result.StatusCode);
Assert.Equal("SampleAction", result.ActionName);
Assert.Same(input, result.Value);
mockHttpContext.Verify(
x => x.Response.RegisterForDispose(It.IsAny<IDisposable>()),
Times.Once());
}