public async Task LoginWhenEncrypServiceThrowShouldReturnFailOperationResult() { ISystemUserRepository systemUserRepository = Substitute.For <ISystemUserRepository>(); IUserService userService = Substitute.For <IUserService>(); IEncrypService encrypService = Substitute.For <IEncrypService>(); SystemUser userResult = new SystemUser { Active = true }; systemUserRepository.FindAsync(Arg.Any <Expression <Func <SystemUser, bool> > >()).Returns(userResult); encrypService.EncrypText(Arg.Any <string>()).Throws(new Exception()); AuthenticationManager authenticationManager = new AuthenticationManager(systemUserRepository, userService, encrypService); AuthenticationRequest authenticationRequest = new AuthenticationRequest { Username = "******", Password = "******" }; IOperationResult <AuthenticationViewModel> actual = await authenticationManager.Login(authenticationRequest); Assert.IsFalse(actual.Success); Assert.AreEqual("Ha ocurrido un error en la autenticación del usuario", actual.Message); }
public SystemUserManager(ISystemUserRepository systemUserRepository, IMapper mapper, IEncrypService encrypService, IEmailService emailService) { _systemUserRepository = systemUserRepository; _mapper = mapper; _encrypService = encrypService; _emailService = emailService; }
public async Task LoginWhenModelIsNullShouldReturnFailOperationResult() { ISystemUserRepository systemUserRepository = Substitute.For <ISystemUserRepository>(); IUserService userService = Substitute.For <IUserService>(); IEncrypService encrypService = Substitute.For <IEncrypService>(); AuthenticationManager authenticationManager = new AuthenticationManager(systemUserRepository, userService, encrypService); IOperationResult <AuthenticationViewModel> actual = await authenticationManager.Login(null); Assert.IsFalse(actual.Success); Assert.AreEqual("La autenticacion no puede estar nula", actual.Message); }
public void SetUp() { systemUserRepository = Substitute.For <ISystemUserRepository>(); mapper = Substitute.For <IMapper>(); encrypService = Substitute.For <IEncrypService>(); emailService = Substitute.For <IEmailService>(); systemUserCreateViewModel = new SystemUserCreateViewModel { Name = "nombre prueba", Email = "correo prueba", Lastname = "apellido prueba", Username = "******", Password = "******" }; }
public async Task LoginWhenPasswordIsNullOrEmptyShouldReturnFailOperationResult(string password) { ISystemUserRepository systemUserRepository = Substitute.For <ISystemUserRepository>(); IUserService userService = Substitute.For <IUserService>(); IEncrypService encrypService = Substitute.For <IEncrypService>(); AuthenticationManager authenticationManager = new AuthenticationManager(systemUserRepository, userService, encrypService); AuthenticationRequest authenticationRequest = new AuthenticationRequest { Username = "******", Password = password }; IOperationResult <AuthenticationViewModel> actual = await authenticationManager.Login(authenticationRequest); Assert.IsFalse(actual.Success); Assert.AreEqual("La contraseña del usuario es requerida", actual.Message); }
public async Task LoginWhenUserNotFoundOrPasswordIsIncorrectShouldReturnFailOperationResult() { ISystemUserRepository systemUserRepository = Substitute.For <ISystemUserRepository>(); IUserService userService = Substitute.For <IUserService>(); IEncrypService encrypService = Substitute.For <IEncrypService>(); systemUserRepository.FindAsync(Arg.Any <Expression <Func <SystemUser, bool> > >()).Returns(default(SystemUser)); AuthenticationManager authenticationManager = new AuthenticationManager(systemUserRepository, userService, encrypService); AuthenticationRequest authenticationRequest = new AuthenticationRequest { Username = "******", Password = "******" }; IOperationResult <AuthenticationViewModel> actual = await authenticationManager.Login(authenticationRequest); Assert.IsFalse(actual.Success); Assert.AreEqual("Usuario o contraseña incorrecto", actual.Message); }
public async Task LoginWhenAllSuccessShouldReturnSuccessOperationResult() { ISystemUserRepository systemUserRepository = Substitute.For <ISystemUserRepository>(); IUserService userService = Substitute.For <IUserService>(); IEncrypService encrypService = Substitute.For <IEncrypService>(); SystemUser userResult = new SystemUser { Active = true }; systemUserRepository.FindAsync(Arg.Any <Expression <Func <SystemUser, bool> > >()).Returns(userResult); AuthenticationManager authenticationManager = new AuthenticationManager(systemUserRepository, userService, encrypService); AuthenticationRequest authenticationRequest = new AuthenticationRequest { Username = "******", Password = "******" }; IOperationResult <AuthenticationViewModel> actual = await authenticationManager.Login(authenticationRequest); Assert.IsTrue(actual.Success); }
public async Task LoginWhenUserIsInactiveShouldReturnFailOperationResult() { ISystemUserRepository systemUserRepository = Substitute.For <ISystemUserRepository>(); IUserService userService = Substitute.For <IUserService>(); IEncrypService encrypService = Substitute.For <IEncrypService>(); SystemUser userResult = new SystemUser { Active = false }; systemUserRepository.FindAsync(Arg.Any <Expression <Func <SystemUser, bool> > >()).Returns(userResult); AuthenticationManager authenticationManager = new AuthenticationManager(systemUserRepository, userService, encrypService); AuthenticationRequest authenticationRequest = new AuthenticationRequest { Username = "******", Password = "******" }; IOperationResult <AuthenticationViewModel> actual = await authenticationManager.Login(authenticationRequest); Assert.IsFalse(actual.Success); Assert.AreEqual("Este usuario no se encuentra activo", actual.Message); }
public AuthenticationManager(ISystemUserRepository systemUserRepository, IUserService userService, IEncrypService encrypService) { _systemUserRepository = systemUserRepository; _userService = userService; _encrypService = encrypService; }