public void Register_Post_Success_Redirected_To_Dashboard()
        {
            // arrange
            var auth = new Mock<IAuthenticationService>();
            var notification = new Mock<INotificationService>();
            var redirect = new RedirectService();
            var controller = new RegistrationController(auth.Object, notification.Object, redirect);

            var model = new RegisterUserModel()
            {
                Email = "*****@*****.**",
                Password = "******",
                ConfirmPassword = "******"
            };

            auth.Setup(a => a.ValidateCaptcha()).Returns(true);
            auth.Setup(a => a.RegisterNewUser("*****@*****.**", "password")).Returns(true);
            auth.Setup(a => a.Authenticate("*****@*****.**", "password")).Returns(true);

            //act
            var result = controller.Register(model) as RedirectResult;

            //assert (result)
            result.Url.Should().Be("~/user/[email protected]");
        }
        public void Register_Post_Fail_Already_Registered()
        {
            // arrange
            var auth = new Mock<IAuthenticationService>();
            var notification = new Mock<INotificationService>();
            var redirect = new RedirectService();
            var controller = new RegistrationController(auth.Object, notification.Object, redirect);
            var model = new RegisterUserModel()
            {
                Email = "*****@*****.**",
                Password = "******",
                ConfirmPassword = "******"
            };

            auth.Setup(a => a.ValidateCaptcha()).Returns(true);
            auth.Setup(a => a.RegisterNewUser("*****@*****.**", "password")).Returns(false);

            //act
            controller.Register(model);
            var result = controller.Register(model) as ViewResult;

            //assert
            Assert.That(model, Is.EqualTo(result.ViewData.Model));
            Assert.That(controller.ModelState[""].Errors[0].ErrorMessage, Is.EqualTo("Sorry, user with such email already exist. Please register with different email."));
        }
        public void ToUrl_NullUrl_ThrowsException()
        {
            // arrange
            var service = new RedirectService();

            // act / assert
            service.ToUrl(null);
        }
        public void RedirectToDashboard_EmptyEmail_ThrowsException()
        {
            // arrange
            var service = new RedirectService();

            // act / assert
            service.ToDashboard("");
        }
        public void Smoke()
        {
            // arrange
            var service = new Mock<IAuthenticationService>();
            var redirect = new RedirectService();
            var controller = new LoginController(service.Object, redirect);

            //act/post
            Assert.That(controller, Is.Not.Null);
        }
        public void ToUrl_WhatEverIWant_Redirects()
        {
            // arrange
            var service = new RedirectService();

            // act
            var result = service.ToUrl("whateveriwant");

            // assert
            result.Url.Should().Be("whateveriwant");
        }
        public void ToRegistrationSuccess_Redirects()
        {
            // arrange
            var service = new RedirectService();

            // act
            var result = service.ToRegistrationSuccess();

            // assert
            result.Url.Should().Be("~/registration/success");
        }
        public void RedirectToDashboard_Redirects()
        {
            // arrange
            var service = new RedirectService();

            // act
            var result = service.ToDashboard("*****@*****.**");

            // assert
            result.Url.Should().Be("~/user/[email protected]");
        }
        public void Smoke()
        {
            // arrange
            var auth = new Mock<IAuthenticationService>();
            var notification = new Mock<INotificationService>();
            var redirect = new RedirectService();
            var controller = new RegistrationController(auth.Object, notification.Object, redirect);

            //act/assert
            Assert.That(controller, Is.Not.Null);
        }
        public void Login_Index_View()
        {
            // arrange
            var service = new Mock<IAuthenticationService>();
            var redirect = new RedirectService();
            var controller = new LoginController(service.Object, redirect);

            //act
            var result = controller.Index();

            //assert
            Assert.That(result, Is.Not.Null);
        }
        public void Index_Get_ReturnsView()
        {
            // arrange
            var auth = new Mock<IAuthenticationService>();
            var notification = new Mock<INotificationService>();
            var redirect = new RedirectService();
            var controller = new RegistrationController(auth.Object, notification.Object, redirect);

            //act
            var result = controller.Index();

            //post
            Assert.That(result, Is.Not.Null);
        }
        public void Login_Post_Success()
        {
            // arrange
            var service = new Mock<IAuthenticationService>();
            var redirect = new RedirectService();
            var controller = new LoginController(service.Object, redirect);
            var model = new LoginModel() { Email = "*****@*****.**", Password = "******" };

            service.Setup(s => s.Authenticate("*****@*****.**", "xxx")).Returns(true);
            
            //act
            var result = controller.Login(model, null) as RedirectResult;

            //assert
            result.Url.Should().Be("~/user/[email protected]");
        }
        public void Login_Post_Success_With_ReturnUrl()
        {
            // arrange
            var service = new Mock<IAuthenticationService>();
            var redirect = new RedirectService();
            var controller = new LoginController(service.Object, redirect);
            var model = new LoginModel() { Email = "*****@*****.**", Password = "******" };

            service.Setup(s => s.Authenticate("*****@*****.**", "xxx")).Returns(true);

            //act
            var result = controller.Login(model, "somewhere") as RedirectResult;

            //assert
            Assert.That(result.Url, Is.EqualTo("somewhere"));
        }
        public void Mobile_Get_ReturnsView()
        {
            // arrange
            var auth = new Mock<IAuthenticationService>();
            var notification = new Mock<INotificationService>();
            var redirect = new RedirectService();
            var controller = new RegistrationController(auth.Object, notification.Object, redirect);

            // act
            var view = controller.Mobile();

            // assert
            Assert.That(view, Is.Not.Null);
        }
        public void Login_Post_Fail()
        {
            // arrange
            var service = new Mock<IAuthenticationService>();
            var redirect = new RedirectService();
            var controller = new LoginController(service.Object, redirect);
            var model = new LoginModel() { Email = "*****@*****.**", Password = "******" };

            service.Setup(s => s.Authenticate("*****@*****.**", "xxx")).Returns(false);

            //act
            var result = controller.Login(model, "somewhere") as ViewResult;

            //assert
            Assert.That(controller.ModelState[""].Errors[0].ErrorMessage, Is.EqualTo("The user name or password provided is incorrect."));
        }
        public void Register_Post_Fail_Unknown_Reason()
        {
            // arrange
            var auth = new Mock<IAuthenticationService>();
            var notification = new Mock<INotificationService>();
            var redirect = new RedirectService();
            var controller = new RegistrationController(auth.Object, notification.Object, redirect);
            var model = new RegisterUserModel()
            {
                Email = "*****@*****.**",
                Password = "******",
                ConfirmPassword = "******"
            };

            auth.Setup(a => a.ValidateCaptcha()).Returns(true);
            auth.Setup(a => a.RegisterNewUser("*****@*****.**", "password")).Throws(new Exception());

            //act / post
            var result = controller.Register(model) as ViewResult;
        }
        public void Register_NewUserRegistered_EmailSent()
        {
            // arrange
            var auth = new Mock<IAuthenticationService>();
            var notification = new Mock<INotificationService>();
            var redirect = new RedirectService();
            var controller = new RegistrationController(auth.Object, notification.Object, redirect);
            var user = new RegisterUserModel
            {
                Email = "*****@*****.**",
                Password = "******"
            };

            auth.Setup(a => a.ValidateCaptcha()).Returns(true);
            auth.Setup(a => a.RegisterNewUser("*****@*****.**", "111111")).Returns(true);

            //act
            var result = controller.Register(user) as RedirectResult;

            //post
            notification.Verify(n => n.NotifyUserOnRegistration("*****@*****.**", "111111"));
        }
        public void ToUrl_EmptyUrl_ThrowsException()
        {
            // arrange
            var service = new RedirectService();

            // act / assert
            service.ToUrl("");
        }
        public void RegisterMobile_Post_RedirectedToSuccess()
        {
            // arrange
            var auth = new Mock<IAuthenticationService>();
            var notification = new Mock<INotificationService>();
            var redirect = new RedirectService();
            var controller = new RegistrationController(auth.Object, notification.Object, redirect);

            // act
            var model = new RegisterUserModel()
            {
                Email = "*****@*****.**",
                Password = "******",
                ConfirmPassword = "******"
            };

            auth.Setup(a => a.ValidateCaptcha()).Returns(true);
            auth.Setup(a => a.RegisterNewUser("*****@*****.**", "password")).Returns(true);
            auth.Setup(a => a.Authenticate("*****@*****.**", "password")).Returns(true);

            var result = controller.RegisterMobile(model) as RedirectResult;

            // assert
            Assert.That(result.Url, Is.EqualTo("~/registration/success"));
        }