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()); }
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); }
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); }
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); }
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()); }