Exemplo n.º 1
0
        public void RedirectTest()
        {
            var target = new ExampleController();
            var result = target.Redirect();

            Assert.IsTrue(result.Permanent);
            Assert.AreEqual("/Example/Index", result.Url);
        }
Exemplo n.º 2
0
        public void Redirection()
        {
            ExampleController controller = new ExampleController();
            RedirectResult    result     = controller.Redirect();

            result.Url.Should().Be("/Example/Index");
            result.Permanent.Should().BeFalse();
        }
Exemplo n.º 3
0
        public void Redirect()
        {
            ExampleController controller = new ExampleController();

            RedirectResult result = controller.Redirect();

            Assert.Equal("/Example/Index", result.Url);
            Assert.False(result.Permanent);
        }
Exemplo n.º 4
0
        public void Redirection()
        {    // Arrange
            ExampleController controller = new ExampleController();
            // Act
            RedirectToActionResult result = controller.Redirect();

            // Assert
            Assert.False(result.Permanent);
            Assert.Equal("Index", result.ActionName);
        }
        public void Redirect()
        {
            ExampleController controller = new ExampleController();

            RedirectToActionResult result = controller.Redirect();

            Assert.Equal("HomeController", result.ControllerName);
            Assert.Equal("Index", result.ActionName);
            Assert.False(result.Permanent);
        }
Exemplo n.º 6
0
        public void RedirectTest()
        {
            // Arrange
            ExampleController controller = new ExampleController();

            // Act
            RedirectResult result = controller.Redirect();

            // Assert
            Assert.AreEqual("/Example/Index", result.Url);
        }
Exemplo n.º 7
0
        public void RedirectTest()
        {
            // 准备——创建控制器
            ExampleController target = new ExampleController();

            // 动作——调用动作方法
            RedirectResult result = target.Redirect();

            // 断言——检查结果
            Assert.IsFalse(result.Permanent);
            Assert.AreEqual("/Example/Index", result.Url);
        }
Exemplo n.º 8
0
        public void ControllerTest_RedirectLiteral()
        {
            // Arrange  - create the controller
            var controller = new ExampleController();

            // Act  - call the action method
            RedirectResult result = controller.Redirect();

            // Assert
            Assert.AreEqual("/Example/Index", result.Url);
            Assert.IsFalse(result.Permanent);
        }
            public void RedirectTest()
            {
                // Arrange
                ExampleController target = new ExampleController();

                // Act
                RedirectResult result = target.Redirect();

                // Assert
                Assert.IsFalse(result.Permanent);
                Assert.AreEqual("/Example/Index", result.Url);
            }
Exemplo n.º 10
0
        public void RedirectTest()
        {
            // Arrange - create the controller
            ExampleController target = new ExampleController();

            // Act - call the action method
            RedirectResult result = target.Redirect();

            // Assert - check the result
            Assert.IsTrue(result.Permanent);
            Assert.AreEqual("/Example/Index", result.Url);
        }
Exemplo n.º 11
0
        public void Redirection()
        {
            // Arrange
            var exampleController = new ExampleController();

            // Act
            var redirectResult = exampleController.Redirect();

            // Assert
            Assert.False(redirectResult.Permanent);
            Assert.Equal("Home", redirectResult.ControllerName);
            Assert.Equal("Index", redirectResult.ActionName);
        }
Exemplo n.º 12
0
        public void RedirectWithRouteTest()
        {
            // Arrange - create the controller
            ExampleController target = new ExampleController();

            // Act - call the action method
            RedirectToRouteResult result = target.Redirect();

            // Assert - check the result
            Assert.IsFalse(result.Permanent);
            Assert.AreEqual("Example", result.RouteValues["controller"]);
            Assert.AreEqual("Index", result.RouteValues["action"]);
            Assert.AreEqual("MyID", result.RouteValues["ID"]);
        }
Exemplo n.º 13
0
        public void RedirectTest()
        {
            // Arrange
            var controller = new ExampleController();

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

            // Assert
            Assert.IsFalse(result.Permanent);

            Action <Action <string, string>, string, string> test = (func, a, b) => func(a, b);

            test(Assert.AreEqual, "Example", (string)result.RouteValues["controller"]);
            test(Assert.AreEqual, "Index", (string)result.RouteValues["action"]);
        }
Exemplo n.º 14
0
        public void Redirection()
        {
            ExampleController controller = new ExampleController();
            //RedirectResult result = controller.Redirect();
            //RedirectToRouteResult result = controller.Redirect();
            RedirectToActionResult result = controller.Redirect();

            //Assert.Equal("/Example/Index", result.Url);
            //Assert.True(result.Permanent);
            //Assert.False(result.Permanent);
            //Assert.Equal("Example", result.RouteValues["controller"]);
            //Assert.Equal("Index", result.RouteValues["action"]);
            //Assert.Equal("myID", result.RouteValues["ID"]);
            Assert.Equal("Home", result.ControllerName);
            Assert.Equal("Index", result.ActionName);
        }
Exemplo n.º 15
0
        public void Redirection()
        {
            // Arrange
            ExampleController controller = new ExampleController();

            // Act
            //RedirectToRouteResult result = controller.Redirect();
            RedirectToActionResult result = controller.Redirect();

            // Assert
            Assert.False(result.Permanent);
            Assert.Equal("Index", result.ActionName);

            //Assert.Equal("Example", result.RouteValues["Controller"]);
            //Assert.Equal("Index", result.RouteValues["action"]);
            //Assert.Equal("MyID", result.RouteValues["ID"]);
        }
Exemplo n.º 16
0
        public void TestMethod2()
        {
            ExampleController exam = new ExampleController();

            ViewResult result = exam.Index();

            Assert.AreEqual("Hello", result.ViewBag.Message);

            RedirectResult result2 = exam.Redirect();

            Assert.IsTrue(result2.Permanent);
            Assert.AreEqual("/Example/Index", result2.Url);

            RedirectToRouteResult result3 = exam.Redirect2();

            Assert.IsFalse(result3.Permanent);
            Assert.AreEqual("Example", result3.RouteValues["controller"]);
            Assert.AreEqual("Index", result3.RouteValues["action"]);
            Assert.AreEqual("MyID", result3.RouteValues["ID"]);
        }
Exemplo n.º 17
0
        public void ControllerTest()
        {
            ExampleController target = new ExampleController();
            //ViewResult result = target.Index();
            //RedirectResult result = target.Redirect();
            RedirectToRouteResult result = target.Redirect();

            //Assert.AreEqual("Homepage", result.ViewName);
            //Assert.IsTrue(result.Permanent);
            //Assert.AreEqual("/Example/Index", result.Url);

            Assert.IsFalse(result.Permanent);
            //Assert.AreEqual("Example", result.RouteValues["controller"]);
            Assert.AreEqual("Index", result.RouteValues["action"]);
            //Assert.AreEqual("MyID", result.RouteValues["ID"]);

            HttpStatusCodeResult result2 = target.StatusCode401();

            Assert.AreEqual(401, result2.StatusCode);
        }
Exemplo n.º 18
0
        public void RedirectURLTest()
        {
            // Arrange - create the controller
            ExampleController target = new ExampleController();
            // Arrange - populate a route collection
            RouteCollection routes = new RouteCollection();

            MvcApplication.RegisterRoutes(routes);
            // Arrange - create a request context
            RequestContext context = new RequestContext(CreateHttpContext(), new RouteData());

            // Act - call the action method
            RedirectToRouteResult result = target.Redirect();
            // Act - generate the URL
            string resultURL = UrlHelper.GenerateUrl(result.RouteName, null, null,
                                                     result.RouteValues, routes, context, true);

            // Assert - check the result
            Assert.IsFalse(result.Permanent);
            Assert.AreEqual("/Example/Index/MyID", resultURL);
        }
Exemplo n.º 19
0
        public void ControllerTest()
        {
            //Arrange Controller
            ExampleController target = new ExampleController();

            //Action
            ViewResult            result              = target.Index();
            RedirectResult        redirectResult      = target.Redirect();
            RedirectToRouteResult redirectRouteResult = target.RedirectRoute();
            HttpStatusCodeResult  httpStatusResult    = target.StatusCode();

            //Assert
            Assert.AreEqual("", result.ViewName);
            Assert.AreEqual("Hello", result.ViewBag.Message);      //对ViewBag进行单元测试
            Assert.IsTrue(redirectResult.Permanent);               //测试是否永久重定向
            Assert.AreEqual("/Example/Index", redirectResult.Url); //测试重定向URL

            Assert.IsFalse(redirectRouteResult.Permanent);
            Assert.AreEqual("Example", redirectRouteResult.RouteValues["controller"]);
            Assert.AreEqual("Index", redirectRouteResult.RouteValues["action"]);
            Assert.AreEqual("MyID", redirectRouteResult.RouteValues["ID"]);
            Assert.AreEqual(401, httpStatusResult.StatusCode);
        }