public async Task RegisterUser_IfUserWithSameLoginAlreadyExists_ReturnsError() { // Arrange var request = new RegisterUserRequest { Email = "*****@*****.**", Password = "******", }; using var factory = new CustomWebApplicationFactory(); var client = factory.CreateServiceClient <IIdentityServiceClient>(); await SeedUser(client, "*****@*****.**", "Qwerty-Qwerty1"); // Act var response = await client.RegisterUserAsync(request); // Assert var expectedError = new IdentityServiceError { ErrorCode = "DuplicateUserName", ErrorDescription = "Username '*****@*****.**' is already taken.", }; response.UserId.Should().BeEmpty(); response.Errors.Should().BeEquivalentTo(expectedError); }
public async Task RegisterUser_IfEmailIsInvalid_ReturnsError() { // Arrange var request = new RegisterUserRequest { Email = "SomeUser", Password = "******", }; using var factory = new CustomWebApplicationFactory(); var client = factory.CreateServiceClient <IIdentityServiceClient>(); // Act var response = await client.RegisterUserAsync(request); // Assert var expectedError = new IdentityServiceError { ErrorCode = "InvalidEmail", ErrorDescription = "Email 'SomeUser' is invalid.", }; response.UserId.Should().BeEmpty(); response.Errors.Should().BeEquivalentTo(expectedError); }
public async Task CheckUser_ForIncorrectPassword_ReturnsError() { // Arrange var request = new CheckUserRequest { Email = "*****@*****.**", Password = "******", }; using var factory = new CustomWebApplicationFactory(); var client = factory.CreateServiceClient <IIdentityServiceClient>(); await SeedUser(client, "*****@*****.**", "Qwerty-Qwerty1"); // Act var response = await client.CheckUserAsync(request); // Assert var expectedError = new IdentityServiceError { ErrorCode = "IncorrectUserNameOrPassword", ErrorDescription = "The user name or password is incorrect.", }; response.UserId.Should().BeEmpty(); response.Errors.Should().BeEquivalentTo(expectedError); }
/// <summary> /// Asserts that the result has not Succeeded and that first error matches error's code and Description. /// </summary> public static void IsFailure(IdentityServiceResult result, IdentityServiceError error) { Assert.NotNull(result); Assert.False(result.Succeeded); Assert.Equal(error.Description, result.Errors.First().Description); Assert.Equal(error.Code, result.Errors.First().Code); }
public async Task RegisterUser_ForPasswordWithoutDigit_ReturnsError() { var expectedError = new IdentityServiceError { ErrorCode = "PasswordRequiresDigit", ErrorDescription = "Passwords must have at least one digit ('0'-'9').", }; await WeakPasswordTestCase("Qwerty-Qwerty", expectedError); }
public async Task RegisterUser_ForPasswordWithNotEnoughUniqueChars_ReturnsError() { var expectedError = new IdentityServiceError { ErrorCode = "PasswordRequiresUniqueChars", ErrorDescription = "Passwords must use at least 5 different characters.", }; await WeakPasswordTestCase("Qqq-Qqq1", expectedError); }
public async Task RegisterUser_ForPasswordWhichIsTooShort_ReturnsError() { var expectedError = new IdentityServiceError { ErrorCode = "PasswordTooShort", ErrorDescription = "Passwords must be at least 8 characters.", }; await WeakPasswordTestCase("Some-Q1", expectedError); }
public async Task RegisterUser_ForPasswordWithoutUppercaseCharacter_ReturnsError() { var expectedError = new IdentityServiceError { ErrorCode = "PasswordRequiresUpper", ErrorDescription = "Passwords must have at least one uppercase ('A'-'Z').", }; await WeakPasswordTestCase("qwerty-qwerty1", expectedError); }
public async Task RegisterUser_ForPasswordWithoutNonAlphanumericCharacter_ReturnsError() { var expectedError = new IdentityServiceError { ErrorCode = "PasswordRequiresNonAlphanumeric", ErrorDescription = "Passwords must have at least one non alphanumeric character.", }; await WeakPasswordTestCase("QwertyQwerty1", expectedError); }
public async Task RegisterUser_ForPasswordWithoutLowercaseCharacter_ReturnsError() { var expectedError = new IdentityServiceError { ErrorCode = "PasswordRequiresLower", ErrorDescription = "Passwords must have at least one lowercase ('a'-'z').", }; await WeakPasswordTestCase("QWERTY-QWERTY1", expectedError); }
private static async Task WeakPasswordTestCase(string password, IdentityServiceError expectedError) { // Arrange var request = new RegisterUserRequest { Email = "*****@*****.**", Password = password, }; using var factory = new CustomWebApplicationFactory(); var client = factory.CreateServiceClient <IIdentityServiceClient>(); // Act var response = await client.RegisterUserAsync(request); // Assert response.UserId.Should().BeEmpty(); response.Errors.Should().BeEquivalentTo(expectedError); }