• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# TestableController类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: File_WithContentsAndFileDownloadName

        public void File_WithContentsAndFileDownloadName()
        {
            // Arrange
            var controller = new TestableController();
            var fileContents = new byte[0];

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

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


示例17: CreatedAtRoute_WithParameterRouteNameAndValues_SetsResultSameProperties

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


示例18: CreatedAtRoute_WithParameterRouteName_SetsResultSameRouteName

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


示例19: CreatedAtAction_WithActionControllerRouteValues_SetsSameValues

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


示例20: Controller_Content_WithParameterContentStringAndContentType_SetsResultContentAndContentType

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

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

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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# TestableMutableObjectModelBinder类代码示例发布时间:2022-05-24
下一篇:
C# TestableBundle类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap