Beispiel #1
0
 public void Can_Login_With_Valid_Credentials()
 {
     // Arrange - create a mock authentication provider
     Mock<IAuthProvider> mock = new Mock<IAuthProvider>();
     mock.Setup(m => m.Authenticate("admin", "secret")).Returns(true);
     // Arrange - create the view model
     LogOnViewModel model = new LogOnViewModel {
     UserName = "******",
     Password = "******"
     };
     // Arrange - create the controller
     AccountController target = new AccountController(mock.Object);
     // Act - authenticate using valid credentials
     ActionResult result = target.LogOn(model, "/MyURL");
     // Assert
     Assert.IsInstanceOfType(result, typeof(RedirectResult));
     Assert.AreEqual("/MyURL", ((RedirectResult)result).Url);
 }
Beispiel #2
0
 public void Cannot_Login_With_Invalid_Credentials()
 {
     // Arrange - create a mock authentication provider
     Mock<IAuthProvider> mock = new Mock<IAuthProvider>();
     mock.Setup(m => m.Authenticate("badUser", "badPass")).Returns(false);
     // Arrange - create the view model
     LogOnViewModel model = new LogOnViewModel {
         UserName = "******",
         Password = "******"
     };
     // Arrange - create the controller
     AccountController target = new AccountController(mock.Object);
     // Act - authenticate using valid credentials
     ActionResult result = target.LogOn(model, "/MyURL");
     // Assert
     Assert.IsInstanceOfType(result, typeof(ViewResult));
     Assert.IsFalse(((ViewResult)result).ViewData.ModelState.IsValid);
 }
        public void AccountController_Logon_CannotLoginWithInvalidCredentials()
        {
            //Arrange
            Mock<IAuthProvider> mock = new Mock<IAuthProvider>();
            mock.Setup(m => m.Authenticate("admin", "secret")).Returns(true);
            var model = new LogonViewModel
            {
                UserName = "******",
                Password = "******"
            };
            var target = new AccountController(mock.Object);

            // Act
            var result = target.LogOn(model, "/MyUrl");

            // Assert
            Assert.IsInstanceOfType(result, typeof(ViewResult));
            Assert.IsFalse(((ViewResult)result).ViewData.ModelState.IsValid);
        }
        public void AccountController_Logon_CanLoginWithValidCredentials()
        {
            //Arrange
            Mock<IAuthProvider> mock = new Mock<IAuthProvider>();
            mock.Setup(m => m.Authenticate("admin", "secret")).Returns(true);
            var model = new LogonViewModel
            {
                UserName = "******",
                Password = "******"
            };
            var target = new AccountController(mock.Object);

            // Act
            var result = target.LogOn(model, "/MyUrl");

            // Assert
            Assert.IsInstanceOfType(result, typeof(RedirectResult));
            Assert.AreEqual<string>("/MyUrl", ((RedirectResult)result).Url);
        }
        public void Can_Login_With_Valid_Credentials()
        {
            // Arrange
            Mock<IAuthProvider> mock = new Mock<IAuthProvider>();
            mock.Setup(m => m.Authenticate("goodUser", "goodPass")).Returns(true);

            LogOnViewModel model = new LogOnViewModel
            {
                UserName = "******",
                Password = "******",
            };

            AccountController controller = new AccountController(mock.Object);

            // Act
            ActionResult result = controller.LogOn(model, "/MyUrl");

            // Assert
            Assert.IsInstanceOfType(result, typeof(RedirectResult));
            Assert.AreEqual("/MyUrl", ((RedirectResult)result).Url);
        }
        public void Cannot_Login_With_Invalid_Credentials()
        {
            // Arrange
            Mock<IAuthProvider> mock = new Mock<IAuthProvider>();
            mock.Setup(m => m.Authenticate("badUser", "badPass")).Returns(false);

            LogOnViewModel model = new LogOnViewModel
            {
                UserName = "******",
                Password = "******",
            };

            AccountController controller = new AccountController(mock.Object);

            // Act
            ActionResult result = controller.LogOn(model, "/MyUrl");

            // Assert
            Assert.IsInstanceOfType(result, typeof(ViewResult));
            Assert.IsFalse(((ViewResult)result).ViewData.ModelState.IsValid);
        }