Exemple #1
0
        public void WhenNotAuthenticatedRedirectToGlobal()
        {
            // Arrange
            var dbmock     = new Mock <IDatabase>();
            var controller = CB.Of(new HomeController(dbmock.Object)).Build();

            // Act
            var result = controller.Index() as RedirectToRouteResult;

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual("Global", result.RouteValues["controller"]);
            Assert.AreEqual("Index", result.RouteValues["action"]);
        }
Exemple #2
0
        public void WhenInvalidUserNameSpecified()
        {
            // Arrange
            var dbmock     = new Mock <IDatabase>();
            var forms      = new Mock <IAuthentication>();
            var controller = CB.Of(new LogonController(dbmock.Object, forms.Object)).Build();
            var model      = new LogonInputModel {
                Username = "", Password = "", RememberMe = true, ReturnUrl = ""
            };

            // Act
            var result = controller.Index(model) as ViewResult;

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(false, controller.ModelState.IsValid);
        }
Exemple #3
0
        public void WhenAuthenticatedReturnHomeView()
        {
            // Arrange
            var dbmock = new Mock <IDatabase>();

            dbmock.Setup(x => x.Fetch <SquawkDisplay>(It.IsAny <Sql>())).Returns(new List <SquawkDisplay>());
            var controller = CB.Of(new HomeController(dbmock.Object))
                             .WithLoggedInId(1)
                             .Build();

            // Act
            var result = controller.Index() as ViewResult;

            //var squawks = result.Model.As<HomeIndexViewModel>().Squawks;

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(typeof(HomeIndexViewModel), result.Model.GetType());
        }
Exemple #4
0
        public void WhenValidUserNameAndPasswordSpecifiedWithReturnUrl()
        {
            // Arrange
            var dbmock = new Mock <IDatabase>();
            var forms  = new Mock <IAuthentication>();

            dbmock.Setup(x => x.SingleOrDefault <LogonController.LogonUser>(It.IsAny <string>(), It.IsAny <string>())).Returns(new LogonController.LogonUser()
            {
                UserId = 1, Password = "******"
            });
            var controller = CB.Of(new LogonController(dbmock.Object, forms.Object)).Build();

            var model = new LogonInputModel {
                Username = "******", Password = "******", RememberMe = true, ReturnUrl = "blah/blah"
            };

            // Act
            var result = controller.Index(model) as RedirectResult;

            // Assert
            Assert.AreEqual("blah/blah", result.Url);
            forms.Verify(x => x.SetAuthCookie(It.IsAny <string>(), It.IsAny <bool>()), Times.Once());
        }