Ejemplo n.º 1
0
        public void Controller_Json_WithParameterValue_SetsResultData()
        {
            // Arrange
            var controller = new TestableController();
            var data       = new object();

            // Act
            var actualJsonResult = controller.Json(data);

            // Assert
            Assert.IsType <JsonResult>(actualJsonResult);
            Assert.Same(data, actualJsonResult.Value);
        }
Ejemplo n.º 2
0
        public void Controller_Json_WithParameterValue_SetsRespectiveProperty()
        {
            // Arrange
            var controller         = new TestableController();
            var data               = new object();
            var serializerSettings = new JsonSerializerSettings();

            // Act
            var actualJsonResult = controller.Json(data, serializerSettings);

            // Assert
            Assert.IsType <JsonResult>(actualJsonResult);
            Assert.Same(data, actualJsonResult.Value);
        }
Ejemplo n.º 3
0
        public void Controller_Json_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.Json(input);

            // Assert
            Assert.IsType <JsonResult>(result);
            Assert.Same(input, result.Value);
            mockHttpContext.Verify(
                x => x.Response.RegisterForDispose(It.IsAny <IDisposable>()),
                Times.Once());
        }
Ejemplo n.º 4
0
        public void Controller_Json_WithParameterValue_SetsRespectiveProperty()
        {
            // Arrange
            var controller = new TestableController();
            var data = new object();
            var serializerSettings = new JsonSerializerSettings();

            // Act
            var actualJsonResult = controller.Json(data, serializerSettings);

            // Assert
            Assert.IsType<JsonResult>(actualJsonResult);
            Assert.Same(data, actualJsonResult.Value);
        }
Ejemplo n.º 5
0
        public void Controller_Json_WithParameterValue_SetsResultData()
        {
            // Arrange
            var controller = new TestableController();
            var data = new object();

            // Act
            var actualJsonResult = controller.Json(data);

            // Assert
            Assert.IsType<JsonResult>(actualJsonResult);
            Assert.Same(data, actualJsonResult.Value);
        }
Ejemplo n.º 6
0
        public void Controller_JsonWithParameterValueAndSerializerSettings_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();
            var serializerSettings = new JsonSerializerSettings();

            // Act
            var result = controller.Json(input, serializerSettings);

            // Assert
            Assert.IsType<JsonResult>(result);
            Assert.Same(input, result.Value);
            var jsonFormatter = result.Formatter as JsonOutputFormatter;
            Assert.Same(serializerSettings, jsonFormatter.SerializerSettings);
            mockHttpContext.Verify(
                x => x.Response.OnResponseCompleted(It.IsAny<Action<object>>(), It.IsAny<object>()),
                Times.Once());
        }
Ejemplo n.º 7
0
        public void Controller_Json_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.Json(input);

            // Assert
            Assert.IsType<JsonResult>(result);
            Assert.Same(input, result.Value);
            mockHttpContext.Verify(
                x => x.Response.OnResponseCompleted(It.IsAny<Action<object>>(), It.IsAny<object>()),
                Times.Once());
        }
Ejemplo n.º 8
0
        public void Controller_Json_WithParameterValueAndSerializerSettings_SetsRespectiveValues()
        {
            // Arrange
            var controller = new TestableController();
            var data = new object();
            var serializerSettings = new JsonSerializerSettings();

            // Act
            var actualJsonResult = controller.Json(data, serializerSettings);

            // Assert
            Assert.IsType<JsonResult>(actualJsonResult);
            Assert.Same(data, actualJsonResult.Value);
            var jsonFormatter = actualJsonResult.Formatter as JsonOutputFormatter;
            Assert.Same(serializerSettings, jsonFormatter.SerializerSettings);
        }
Ejemplo n.º 9
0
        public void Controller_JsonWithParameterValueAndSerializerSettings_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();
            var serializerSettings = new JsonSerializerSettings();

            // Act
            var result = controller.Json(input, serializerSettings);

            // Assert
            Assert.IsType<JsonResult>(result);
            Assert.Same(input, result.Value);
            mockHttpContext.Verify(
                x => x.Response.RegisterForDispose(It.IsAny<IDisposable>()),
                Times.Once());
        }