Ik heb problemen bij het instellen van de nep om te falen als de gebruiker drie keer heeft geprobeerd in te loggen met een fout. Mijn code ziet er als volgt uit:
Public Sub User_LogIn_With_Three_Failed_Attempts_AccountLocks_Pass()
' arrange
Dim logInMock As New Moq.Mock(Of IUserLoginRepository)()
logInMock.Setup(Function(repo) repo.LogInUser(It.IsAny(Of String), It.IsAny(Of String))).Returns(False)
' Todo: have to instruct the mock that if it is repeated 3 times then lock the account. How to do this????
' act
Dim logInBO As New LogInBO(logInMock.Object)
logInBO.LogIn("someusername", "someWrongPassword")
logInBO.LogIn("someusername", "someWrongPassword")
logInBO.LogIn("someusername", "someWrongPassword")
' verify
logInMock.Verify(Function(r) r.LogInUser("someusername", "someWrongPassword"), times:=Times.Exactly(3))
logInMock.Verify(Function(r) r.IsAccountLocked = True)
End Sub
Ervan uitgaande dat mijn repository er ongeveer zo uitziet:
public interface IUserLoginRepository
{
bool LogInUser(string userName, string password);
bool IsAccountLocked { get; }
bool ResetPassword(string userName, string password);
int FailedAttempts(string userName);
bool LockAccount(string userName);
}
waardeer alle tips en zou dol zijn op de moq syntax in VB.Net ;-)
De LoginBo-code is als:
public bool LogIn(string userName, string password)
{
if (_logInRepo.IsAccountLocked)
//TODO log error
return false;
if (_logInRepo.LogInUser(userName, password))
{
return true;
}
else
{
if (_logInRepo.FailedAttempts(userName) == 3)//this should increment the failed attempts and return the value
_logInRepo.LockAccount(userName);
}
//Log error
return false;
}