public void login_should_return_with_login_model() { // Arrange const string actionName = "Login"; // Act var sut = new UserControllerBuilder().Build(); var view = sut.Login(); // Assert Assert.NotNull(view); Assert.NotNull(view.Model); Assert.IsInstanceOf<BaseController>(sut); Assert.IsAssignableFrom<LoginModel>(view.Model); sut.AssertGetAttribute(actionName); sut.AssertAllowAnonymousAttribute(actionName); }
public async void login_should_redirect_if_model_is_valid() { // Arrange const string actionName = "Login"; const int id = 1; const string email = "*****@*****.**"; const string fullName = "test"; const string password = "******"; var validModel = new LoginModel { Password = password, Email = email }; var userService = new Mock<IUserService>(); userService.Setup(x => x.Authenticate(email, password)) .Returns(() => Task.FromResult(true)); userService.Setup(x => x.GetByEmail(email)) .Returns(() => Task.FromResult(new UserDto { Id = id, FullName = fullName, Email = email, RoleId = SetRole.User.Value })); var formsAuthenticationService = new Mock<IFormsAuthenticationService>(); formsAuthenticationService.Setup(x => x.SignIn(id, fullName, email, SetRole.User.Value, true)); // Act var sut = new UserControllerBuilder().WithUserService(userService.Object) .WithFormsAuthenticationService(formsAuthenticationService.Object) .Build(); var view = await sut.Login(validModel) as RedirectResult; // Assert Assert.NotNull(view); Assert.AreEqual(view.Url, "/"); Assert.IsInstanceOf<BaseController>(sut); userService.Verify(x => x.Authenticate(email, password), Times.Once); formsAuthenticationService.Verify(x => x.SignIn(id, fullName, email, SetRole.User.Value, true), Times.Once); sut.AssertPostAttribute(actionName, new[] { typeof(LoginModel) }); sut.AssertAllowAnonymousAttribute(actionName, new[] { typeof(LoginModel) }); }