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 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 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; }