コード例 #1
0
        public void IsNotAuthenicatedTest()
        {
            var mockRequest = new Mock<HttpRequestBase>();
            mockRequest.Setup(x => x.IsAuthenticated).Returns(false);

            var mockContext = new Mock<HttpContextBase>();
            mockContext.Setup(x => x.Request).Returns(mockRequest.Object);

            var homeController = new HomeController();
            homeController.ControllerContext = new ControllerContext(mockContext.Object, new System.Web.Routing.RouteData(), homeController);

            ViewResult viewResult = (ViewResult)homeController.Login();
            Assert.IsTrue(viewResult.ViewName == string.Empty);
        }
コード例 #2
0
        public void IsAuthenicatedTest()
        {
            var mockRequest = new Mock<HttpRequestBase>();
            mockRequest.Setup(x => x.IsAuthenticated).Returns(true);

            var mockContext = new Mock<HttpContextBase>();
            mockContext.Setup(x => x.Request).Returns(mockRequest.Object);

            var homeController = new HomeController();
            homeController.ControllerContext = new ControllerContext(mockContext.Object, new System.Web.Routing.RouteData(), homeController);

            var result = (RedirectToRouteResult)homeController.Login();
            result.RouteValues["action"].Equals("Index");
            result.RouteValues["controller"].Equals("Project");

            Assert.AreEqual("Index", result.RouteValues["action"]);
            Assert.AreEqual("Project", result.RouteValues["controller"]);
        }