Exemplo n.º 1
0
        public void Can_Login_With_Valid_Credentials()
        {
            Mock<IAuthProvider> mock =new Mock<IAuthProvider>();
            mock.Setup(m => m.Authenticate("admin", "secret")).Returns(true);

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

            AccountController target =new AccountController(mock.Object);
            var result = target.Login(model, "/MyURL");

            Assert.IsInstanceOfType(result, typeof(RedirectResult));
            Assert.AreEqual("/MyURL", ((RedirectResult)result).Url);
        }
Exemplo n.º 2
0
        public void Cannot_Login_With_Invalid_Credentials()
        {
            var mock = new Mock<IAuthProvider>();
            mock.Setup(m => m.Authenticate("badUser", "badPass")).Returns(false);

            var model = new LoginViewModel
            {
                UserName = "******",
                Password = "******"
            };

            AccountController target = new AccountController(mock.Object);
            var result = target.Login(model, "/MyURL");

            Assert.IsInstanceOfType(result, typeof(ViewResult));
            Assert.IsFalse(((ViewResult)result).ViewData.ModelState.IsValid);
        }
        public void SetUp()
        {
            _shoppingCartService = new FakeShoppingCartService();
            _authenticationService = new FakeAuthenticationService();
            _personalizationService = new FakePersonalizationService();
            _userRepository = new FakeUserRepository();
            _fakeAuthorizationService = new FakeAuthorizationService();

            _accountController = new AccountController(_shoppingCartService,
                                                       _authenticationService,
                                                       _personalizationService,
                                                       _userRepository,
                                                       _fakeAuthorizationService);

            var controllerContext = new Mock<ControllerContext>();

            controllerContext.SetupGet(x => x.HttpContext.User.Identity.Name)
                .Returns(_authenticationService.User.Email);

            //            controllerContext.SetupGet(x => x.HttpContext.User.Identity.IsAuthenticated)
            //                .Returns(true);

            //            controllerContext.SetupGet(x => x.HttpContext.Request.IsAuthenticated)
            //                .Returns(true);

            controllerContext.SetupGet(x => x.HttpContext.Session[ShoppingCartService.CartSessionKey])
                .Returns(_authenticationService.User.ShoppingCart);

            _accountController.ControllerContext = controllerContext.Object;

            var context = new Mock<HttpContextBase>(MockBehavior.Default);

            _accountController.Url = new UrlHelper(
                new RequestContext(context.Object,
                                   new RouteData()), new RouteCollection());
        }
Exemplo n.º 4
0
        public void Can_Login_With_Valid_Credentials()
        {
            var 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);
            // аутентификация с использованием правильных учетных данных
            var result = target.LogOn(model, "/MyURL");

            Assert.IsInstanceOfType(result, typeof(RedirectResult));
            Assert.AreEqual("/MyURL", ((RedirectResult)result).Url);
        }