Exemplo n.º 1
0
        public void About()
        {
            // Arrange
            HomeController controller = new HomeController();

            // Act
            ViewResult result = controller.About() as ViewResult;

            // Assert
            Assert.IsNotNull(result);
        }
Exemplo n.º 2
0
        public void Index_WithLoggedInAdmin()
        {
            // Arrange
            Mock<IRepositoryService> repoService = new Mock<IRepositoryService>();
            Mock<IAccountService> accountService = new Mock<IAccountService>();
            HomeController controller = new HomeController(accountService.Object, repoService.Object);

            accountService.Setup(a => a.RoleExists("Administrators")).Returns(() => true);
            accountService.Setup(a => a.RoleExists("Staff")).Returns(() => true);
            accountService.Setup(a => a.GetRolesForUser()).Returns(() => new string[] { "Administrators" });

            // Act
            ActionResult result = controller.Index() as ActionResult;

            // Assert
            //Assert.AreEqual("Welcome to ASP.NET MVC!", result.ViewBag.Message);
            Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult));
            RedirectToRouteResult redirectresult = (RedirectToRouteResult)result;
            StringAssert.Equals(redirectresult.RouteValues["action"], "Index");
            StringAssert.Equals(redirectresult.RouteValues["controller"], "Admin");
        }