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


C# TestableController类代码示例

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


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

示例1: Raven_session_is_not_opened_before_on_action_executing

        public void Raven_session_is_not_opened_before_on_action_executing()
        {
            var store = new TestableStore();
            var controller = new TestableController(store);

            Assert.Null(controller.Session);
        }
开发者ID:bbqchickenrobot,项目名称:byteblog,代码行数:7,代码来源:RavenControllerTests.cs

示例2: If_no_exception_occurred_then_changes_are_saved

        public void If_no_exception_occurred_then_changes_are_saved()
        {
            var testDocument = new Foo { Id = "foos/123", Title = "foo" };

            var store = new TestableStore();

            var controller = new TestableController(store);

            StartActionExecuting(controller);

            using (var session = controller.Session)
            {
                session.Store(testDocument);
                session.SaveChanges();

                var doc = session.Load<Foo>(testDocument.Id);
                doc.Title = "bar";

                FinishActionExecuted(controller);
            }

            using (var session = store.OpenSession())
            {
                var doc = session.Load<Foo>(testDocument.Id);
                Assert.Equal("bar", doc.Title);
            }
        }
开发者ID:bbqchickenrobot,项目名称:byteblog,代码行数:27,代码来源:RavenControllerTests.cs

示例3: Redirect_WithParameter_NullOrEmptyUrl_Throws

        public void Redirect_WithParameter_NullOrEmptyUrl_Throws(string url)
        {
            // Arrange
            var controller = new TestableController();

            // Act & Assert
            ExceptionAssert.ThrowsArgumentNullOrEmpty(
                () => controller.Redirect(url: url), "url");
        }
开发者ID:phinq19,项目名称:git_example,代码行数:9,代码来源:ControllerBaseTest.cs

示例4: RedirectPermanent_WithParameterUrl_SetsRedirectResultPermanentAndSameUrl

        public void RedirectPermanent_WithParameterUrl_SetsRedirectResultPermanentAndSameUrl()
        {
            // Arrange
            var controller = new TestableController();
            var url = "/test/url";

            // Act
            var result = controller.RedirectPermanent(url);

            // Assert
            Assert.IsType<RedirectResult>(result);
            Assert.True(result.Permanent);
            Assert.Same(url, result.Url);
        }
开发者ID:RehanSaeed,项目名称:Mvc,代码行数:14,代码来源:ControllerTests.cs

示例5: Controller_View_WithoutParameter_SetsResultNullViewNameAndNullViewDataModelAndSameTempData

        public void Controller_View_WithoutParameter_SetsResultNullViewNameAndNullViewDataModelAndSameTempData()
        {
            // Arrange
            var controller = new TestableController()
            {
                ViewData = new ViewDataDictionary(new EmptyModelMetadataProvider()),
                TempData = new TempDataDictionary(new DefaultHttpContext(), Mock.Of<ITempDataProvider>()),
            };

            // Act
            var actualViewResult = controller.View();

            // Assert
            Assert.IsType<ViewResult>(actualViewResult);
            Assert.Null(actualViewResult.ViewName);
            Assert.Same(controller.ViewData, actualViewResult.ViewData);
            Assert.Same(controller.TempData, actualViewResult.TempData);
            Assert.Null(actualViewResult.ViewData.Model);
        }
开发者ID:xuchrist,项目名称:Mvc,代码行数:19,代码来源:ControllerTest.cs

示例6: SettingViewData_AlsoUpdatesViewBag

        public void SettingViewData_AlsoUpdatesViewBag()
        {
            // Arrange
            var metadataProvider = TestModelMetadataProvider.CreateDefaultProvider();
            var controller = new TestableController();
            var originalViewData = controller.ViewData = new ViewDataDictionary<object>(metadataProvider);
            var replacementViewData = new ViewDataDictionary<object>(metadataProvider);

            // Act
            controller.ViewBag.Hello = "goodbye";
            controller.ViewData = replacementViewData;
            controller.ViewBag.Another = "property";

            // Assert
            Assert.NotSame(originalViewData, controller.ViewData);
            Assert.Same(replacementViewData, controller.ViewData);
            Assert.Null(controller.ViewBag.Hello);
            Assert.Equal("property", controller.ViewBag.Another);
            Assert.Equal("property", controller.ViewData["Another"]);
        }
开发者ID:xuchrist,项目名称:Mvc,代码行数:20,代码来源:ControllerTest.cs

示例7: Controller_Content_WithParameterContentString_SetsResultContent

        public void Controller_Content_WithParameterContentString_SetsResultContent()
        {
            // Arrange
            var controller = new TestableController();

            // Act
            var actualContentResult = controller.Content("TestContent");

            // Assert
            Assert.IsType<ContentResult>(actualContentResult);
            Assert.Equal("TestContent", actualContentResult.Content);
            Assert.Null(actualContentResult.ContentType);
        }
开发者ID:RehanSaeed,项目名称:Mvc,代码行数:13,代码来源:ControllerTests.cs

示例8: BadRequest_SetsStatusCodeAndValue_ModelState

        public void BadRequest_SetsStatusCodeAndValue_ModelState()
        {
            // Arrange
            var controller = new TestableController();

            // Act
            var result = controller.HttpBadRequest(new ModelStateDictionary());

            // Assert
            Assert.IsType<BadRequestObjectResult>(result);
            Assert.Equal(StatusCodes.Status400BadRequest, result.StatusCode);
            var errors = Assert.IsType<SerializableError>(result.Value);
            Assert.Equal(0, errors.Count);
        }
开发者ID:RehanSaeed,项目名称:Mvc,代码行数:14,代码来源:ControllerTests.cs

示例9: BadRequest_IDisposableObject_RegistersForDispose

        public void BadRequest_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.HttpBadRequest(input);

            // Assert
            Assert.IsType<BadRequestObjectResult>(result);
            Assert.Equal(StatusCodes.Status400BadRequest, result.StatusCode);
            Assert.Same(input, result.Value);
            mockHttpContext.Verify(
                x => x.Response.OnResponseCompleted(It.IsAny<Action<object>>(), It.IsAny<object>()),
                Times.Once());
        }
开发者ID:RehanSaeed,项目名称:Mvc,代码行数:23,代码来源:ControllerTests.cs

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

示例11: ViewDataModelSetter_DoesNotThrow

        public void ViewDataModelSetter_DoesNotThrow(object model, Type expectedType)
        {
            // Arrange
            var activator = new ViewDataDictionaryControllerPropertyActivator(new EmptyModelMetadataProvider());
            var actionContext = new ActionContext(
                new DefaultHttpContext(),
                new RouteData(),
                new ControllerActionDescriptor());
            var controllerContext = new ControllerContext(actionContext);
            var controller = new TestableController();
            activator.Activate(controllerContext, controller);

            // Guard
            Assert.NotNull(controller.ViewData);

            // Act (does not throw)
            controller.ViewData.Model = model;

            // Assert
            Assert.NotNull(controller.ViewData.ModelMetadata);
            Assert.Equal(expectedType, controller.ViewData.ModelMetadata.ModelType);
        }
开发者ID:xuchrist,项目名称:Mvc,代码行数:22,代码来源:ControllerTest.cs

示例12: 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

示例13: HttpNotFound_SetsStatusCode

        public void HttpNotFound_SetsStatusCode()
        {
            // Arrange
            var controller = new TestableController();

            // Act
            var result = controller.HttpNotFound();

            // Assert
            Assert.IsType<HttpNotFoundResult>(result);
            Assert.Equal(StatusCodes.Status404NotFound, result.StatusCode);
        }
开发者ID:RehanSaeed,项目名称:Mvc,代码行数:12,代码来源:ControllerTests.cs

示例14: File_WithStreamAndFileDownloadName

        public void File_WithStreamAndFileDownloadName()
        {
            // 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 fileStream = Stream.Null;

            // Act
            var result = controller.File(fileStream, "application/pdf", "someDownloadName");

            // Assert
            Assert.NotNull(result);
            Assert.Same(fileStream, result.FileStream);
            Assert.Equal("application/pdf", result.ContentType.ToString());
            Assert.Equal("someDownloadName", result.FileDownloadName);
            mockHttpContext.Verify(
                x => x.Response.OnResponseCompleted(It.IsAny<Action<object>>(), It.IsAny<object>()),
                Times.Once());
        }
开发者ID:RehanSaeed,项目名称:Mvc,代码行数:24,代码来源:ControllerTests.cs

示例15: File_WithPathAndFileDownloadName

        public void File_WithPathAndFileDownloadName()
        {
            // Arrange
            var controller = new TestableController();
            var path = Path.GetFullPath("somepath");

            // Act
            var result = controller.File(path, "application/pdf", "someDownloadName");

            // Assert
            Assert.NotNull(result);
            Assert.Equal(path, result.FileName);
            Assert.Equal("application/pdf", result.ContentType.ToString());
            Assert.Equal("someDownloadName", result.FileDownloadName);
        }
开发者ID:RehanSaeed,项目名称:Mvc,代码行数:15,代码来源:ControllerTests.cs


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