当前位置: 首页>>代码示例>>C#>>正文


C# TestableController.Json方法代码示例

本文整理汇总了C#中TestableController.Json方法的典型用法代码示例。如果您正苦于以下问题:C# TestableController.Json方法的具体用法?C# TestableController.Json怎么用?C# TestableController.Json使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TestableController的用法示例。


在下文中一共展示了TestableController.Json方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Controller_Json_WithParameterValue_SetsRespectiveProperty

        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);
        }
开发者ID:xuchrist,项目名称:Mvc,代码行数:14,代码来源:ControllerTest.cs

示例2: Controller_Json_WithParameterValue_SetsResultData

        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);
        }
开发者ID:xuchrist,项目名称:Mvc,代码行数:13,代码来源:ControllerTest.cs

示例3: Controller_JsonWithParameterValueAndSerializerSettings_IDisposableObject_RegistersForDispose

        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());
        }
开发者ID:RehanSaeed,项目名称:Mvc,代码行数:25,代码来源:ControllerTests.cs

示例4: Controller_Json_IDisposableObject_RegistersForDispose

        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());
        }
开发者ID:RehanSaeed,项目名称:Mvc,代码行数:22,代码来源:ControllerTests.cs

示例5: Controller_Json_WithParameterValueAndSerializerSettings_SetsRespectiveValues

        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);
        }
开发者ID:RehanSaeed,项目名称:Mvc,代码行数:16,代码来源:ControllerTests.cs

示例6: Controller_JsonWithParameterValueAndSerializerSettings_IDisposableObject_RegistersForDispose

        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());
        }
开发者ID:phinq19,项目名称:git_example,代码行数:22,代码来源:ControllerTest.cs


注:本文中的TestableController.Json方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。