Beispiel #1
0
        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."));
        }
Beispiel #2
0
        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"));
        }
Beispiel #3
0
        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 RedirectController(RedirectService redirectService, ILogger <RedirectController> logger,
                           IEnumerable <IHostedService> services)
 {
     _redirectService = redirectService;
     _logger          = logger;
     // Have to do this because we can't directly injected DeletionService
     _deletionService = (DeletionService)services.FirstOrDefault(w => w.GetType() == typeof(DeletionService));
 }
Beispiel #5
0
        public void RedirectToDashboard_EmptyEmail_ThrowsException()
        {
            // arrange
            var service = new RedirectService();

            // act / assert
            service.ToDashboard("");
        }
Beispiel #6
0
        public void ToUrl_NullUrl_ThrowsException()
        {
            // arrange
            var service = new RedirectService();

            // act / assert
            service.ToUrl(null);
        }
Beispiel #7
0
        public void ToUrl_EmptyUrl_ThrowsException()
        {
            // arrange
            var service = new RedirectService();

            // act / assert
            service.ToUrl("");
        }
Beispiel #8
0
        public void TestRedirects()
        {
            var redirectService = new RedirectService(new WebRequestRedirectStrategy());

            using (redirectService)
            {
                redirectService.TestRedirects();
            }
        }
        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);
        }
Beispiel #10
0
        public void ToUrl_WhatEverIWant_Redirects()
        {
            // arrange
            var service = new RedirectService();

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

            // assert
            result.Url.Should().Be("whateveriwant");
        }
Beispiel #11
0
        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);
        }
Beispiel #12
0
        public void RedirectToDashboard_Redirects()
        {
            // arrange
            var service = new RedirectService();

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

            // assert
            result.Url.Should().Be("~/user/[email protected]");
        }
Beispiel #13
0
        public void ToRegistrationSuccess_Redirects()
        {
            // arrange
            var service = new RedirectService();

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

            // assert
            result.Url.Should().Be("~/registration/success");
        }
        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);
        }
Beispiel #15
0
        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);
        }
Beispiel #16
0
        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 AccountController(
     ApplicationDbContext applicationDbContext,
     UserManager <ApplicationUser> userManager,
     IPersistedGrantService persistedGrantService,
     SignInManager <ApplicationUser> signInManager,
     ILoggerFactory loggerFactory,
     IIdentityServerInteractionService interaction,
     IClientStore clientStore,
     RedirectService redirectService
     )
 {
     _applicationDbContext = applicationDbContext;
     _userManager          = userManager;
     _signInManager        = signInManager;
     _logger          = loggerFactory.CreateLogger <AccountController>();
     _interaction     = interaction;
     _redirectService = redirectService;
 }
        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 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 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]");
        }
Beispiel #21
0
        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;
        }
Beispiel #22
0
        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 HttpErrorPageController(RedirectService redirectService)
 {
     _redirectService = redirectService;
 }