Example #1
0
        public void CreatedAtRoute_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.CreatedAtRoute("SampleRoute", input);

            // Assert
            Assert.IsType<CreatedAtRouteResult>(result);
            Assert.Equal(StatusCodes.Status201Created, result.StatusCode);
            Assert.Equal("SampleRoute", result.RouteName);
            Assert.Same(input, result.Value);
            mockHttpContext.Verify(
                x => x.Response.OnResponseCompleted(It.IsAny<Action<object>>(), It.IsAny<object>()),
                Times.Once());
        }
Example #2
0
        public void CreatedAtRoute_WithParameterRouteName_SetsResultSameRouteName()
        {
            // Arrange
            var controller = new TestableController();
            var routeName = "SampleRoute";

            // Act
            var result = controller.CreatedAtRoute(routeName, null);

            // Assert
            Assert.IsType<CreatedAtRouteResult>(result);
            Assert.Same(routeName, result.RouteName);
        }
Example #3
0
        public void CreatedAtRoute_WithParameterRouteNameAndValues_SetsResultSameProperties()
        {
            // Arrange
            var controller = new TestableController();
            var routeName = "SampleRoute";
            var expected = new Dictionary<string, object>
                {
                    { "test", "case" },
                    { "sample", "route" },
                };

            // Act
            var result = controller.CreatedAtRoute(routeName, new RouteValueDictionary(expected), null);

            // Assert
            Assert.IsType<CreatedAtRouteResult>(result);
            Assert.Equal(StatusCodes.Status201Created, result.StatusCode);
            Assert.Same(routeName, result.RouteName);
            Assert.Equal(expected, result.RouteValues);
        }
        public void CreatedAtRoute_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.CreatedAtRoute("SampleRoute", input);

            // Assert
            Assert.IsType<CreatedAtRouteResult>(result);
            Assert.Equal(StatusCodes.Status201Created, result.StatusCode);
            Assert.Equal("SampleRoute", result.RouteName);
            Assert.Same(input, result.Value);
            mockHttpContext.Verify(
                x => x.Response.RegisterForDispose(It.IsAny<IDisposable>()),
                Times.Once());
        }