public void AttemptLogin(string username, string password, IStoredCredentialsRepository repo) { var credentials = new UsernameAndPassword { Username = username, Password = password }; var authenticationService = GetAuthenticationService(repo); authenticationResult = authenticationService.Authenticate(credentials); }
/// <summary> /// Initializes a new instance of the <see cref="T:PasswordAuthenticationService{TRequest}"/> class. /// </summary> /// <param name="requestFactory">Request factory.</param> /// <param name="repository">Repository.</param> /// <param name="verifierFactory">Verifier factory.</param> /// <param name="serializer">Serializer.</param> public PasswordAuthenticationService(IStoredCredentialsRepository repository, IPasswordVerifierFactory verifierFactory = null, IRequestFactory <TRequest> requestFactory = null, ICredentialsSerializer serializer = null) { if (repository == null) { throw new ArgumentNullException(nameof(repository)); } this.repository = repository; this.verifierFactory = verifierFactory ?? new PasswordVerifierFactory(); this.requestFactory = requestFactory ?? new SimpleRequestFactory <TRequest>(); this.credentialsSerializer = serializer ?? new JsonCredentialsSerializer(); }
IPasswordAuthenticationService GetAuthenticationService(IStoredCredentialsRepository repo) { var output = new PasswordAuthenticationService <AuthenticationRequest>(repo); if (useSuccessListener) { output.SuccessfulAuthentication += (sender, e) => { listenerTriggered = true; }; } else if (useFailureListener) { output.FailedAuthentication += (sender, e) => { listenerTriggered = true; }; } return(output); }
public void RetrieveStoredCredentials_uses_repository([Frozen] IStoredCredentialsRepository repository, PasswordAuthenticationService <StubAuthenticationRequest> sut, StubAuthenticationRequest request, StubStoredCredentials stored) { // Arrange Mock.Get(repository) .Setup(x => x.GetStoredCredentials(request.EnteredCredentials)) .Returns(stored); request.EnteredCredentials = request.EnteredCredentials; // Act sut.RetrieveStoredCredentials(ref request); // Assert Assert.AreSame(stored, request.StoredCredentials, "Stored credentials are set"); Mock.Get(repository) .Verify(x => x.GetStoredCredentials(request.EnteredCredentials), Times.Once()); }
public void RetrieveStoredCredentials_sets_result_when_credentials_are_not_found([Frozen] IStoredCredentialsRepository repository, PasswordAuthenticationService <StubAuthenticationRequest> sut, StubAuthenticationRequest request) { // Arrange Mock.Get(repository) .Setup(x => x.GetStoredCredentials(request.EnteredCredentials)) .Returns((StubStoredCredentials)null); request.EnteredCredentials = request.EnteredCredentials; request.Result = null; // Act sut.RetrieveStoredCredentials(ref request); // Assert Assert.IsNull(request.StoredCredentials, "Stored credentials are null"); Assert.NotNull(request.Result, "Result is set"); Assert.IsFalse(request.Result.CredentialsFound, "Credentials not found"); }
public AuthenticationService(IStoredCredentialsRepository repo) : base(repo) {}