Skip to content

Commit 7595942

Browse files
committed
test: creating test case for when password length is less than 6, test passed
1 parent 15ed501 commit 7595942

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

test/CommonTestUtilities/Requests/RegisterUserRequestJSONMockFactory.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace CommonTestUtilities.Requests;
55

66
public static class RegisterUserRequestJSONMockFactory
77
{
8-
public static RegisterUserRequestJSON CreateMock()
8+
public static RegisterUserRequestJSON CreateMock(int length = 10)
99
=> new Faker<RegisterUserRequestJSON>()
1010
.CustomInstantiator(f =>
1111
{
@@ -14,7 +14,7 @@ public static RegisterUserRequestJSON CreateMock()
1414
return new RegisterUserRequestJSON(
1515
name,
1616
f.Internet.Email(name),
17-
f.Internet.Password()
17+
f.Internet.Password(length)
1818
);
1919
}).Generate();
2020

test/Validators.Test/User/Register/RegisterUserValidatorTest.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ public void Test_OnFailureWith_EmptyEmail()
4242
result.Errors.Should().ContainSingle()
4343
.And.Contain(e => e.ErrorMessage.Equals(ResourcesAccessor.EMAIL_REQUIRED));
4444
}
45-
4645
[Fact]
4746
public void Test_OnFailureWith_InvalidEmail()
4847
{
@@ -64,4 +63,19 @@ public void Test_OnFailureWith_EmptyPassword()
6463
result.Errors.Should().ContainSingle()
6564
.And.Contain(e => e.ErrorMessage.Equals(ResourcesAccessor.PASSWORD_REQUIRED));
6665
}
66+
[Theory]
67+
[InlineData(1)]
68+
[InlineData(2)]
69+
[InlineData(3)]
70+
[InlineData(4)]
71+
[InlineData(5)]
72+
public void Test_OnFailureWith_InvalidPassword(int passwordLength)
73+
{
74+
var request = RegisterUserRequestJSONMockFactory.CreateMock(passwordLength);
75+
var result = _validator.Validate(request);
76+
77+
result.IsValid.Should().BeFalse();
78+
result.Errors.Should().ContainSingle()
79+
.And.Contain(e => e.ErrorMessage.Equals(ResourcesAccessor.PASSWORD_LENGTH));
80+
}
6781
}

0 commit comments

Comments
 (0)