public async Task AuthenticateAdmin_Should_Return_Failure_Result_When_Credentials_Are_Empity(string email, string password) { var userRepositoryMock = new Mock <IUserRepository>(); var adminRepositoryMock = new Mock <IAdminRepository>(); var hashingService = new Mock <IHashingService>(); var authService = new PearUpAuthenticationService(userRepositoryMock.Object, hashingService.Object, adminRepositoryMock.Object); var actualResult = await authService.AuthenticateAdmin(email, password); Assert.IsFalse(actualResult.IsSuccessed); Assert.AreEqual(UserErrorMessages.EmailAddress_And_Password_Are_Required, actualResult.GetErrorString()); }
public async Task AuthenticateAdmin_Should_Return_Failure_Result_When_Email_Exist_And_Password_Is_InCorrect(string email, string password) { var userRepositoryMock = new Mock <IUserRepository>(); var adminRepositoryMock = new Mock <IAdminRepository>(); var hashingService = new Mock <IHashingService>(); adminRepositoryMock.Setup(us => us.GetAdminByEmailId(It.IsAny <string>())) .ReturnsAsync(Result.Ok(admin)); hashingService.Setup(hash => hash.SlowEquals(It.IsAny <byte[]>(), It.IsAny <byte[]>())) .Returns(false); var authService = new PearUpAuthenticationService(userRepositoryMock.Object, hashingService.Object, adminRepositoryMock.Object); var actualResult = await authService.AuthenticateAdmin(email, password); Assert.IsFalse(actualResult.IsSuccessed); Assert.AreEqual(actualResult.GetErrorString(), UserErrorMessages.Password_Is_Incorrect); }
public async Task AuthenticateAdmin_Should_Return_SuccessResult_When_Credentials_Are_Valid(string email, string password) { var userRepositoryMock = new Mock <IUserRepository>(); var adminRepositoryMock = new Mock <IAdminRepository>(); var hashingService = new Mock <IHashingService>(); adminRepositoryMock.Setup(us => us.GetAdminByEmailId(It.IsAny <string>())) .ReturnsAsync(Result.Ok(admin)); hashingService.Setup(hash => hash.SlowEquals(It.IsAny <byte[]>(), It.IsAny <byte[]>())) .Returns(true); var authService = new PearUpAuthenticationService(userRepositoryMock.Object, hashingService.Object, adminRepositoryMock.Object); var actualResult = await authService.AuthenticateAdmin(email, password); Assert.IsTrue(actualResult.IsSuccessed); Assert.AreEqual(actualResult.Value, admin); }