public void actor_not_remember_anything_when_response_is_not_success() { const string endpoint = "http://localhost:5000/"; const string username = "******"; const string password = "******"; sender.SetupResponse(new HttpResponseBuilder().WithHttpStatusCode(HttpStatusCode.BadRequest).Build()); actor.AttemptsTo(GetAccessToken .UsingResourceOwnerPasswordCredentialFlow() .WithCredentials(username, password) .FromEndpoint(endpoint)); Action remembering = () => actor.Recall <OAuthToken>(TokenConstants.TokenKey); Check.ThatCode(remembering).Throws <KeyNotFoundException>(); }
public void should_send_request_to_correct_url() { const string endpoint = "http://localhost:5000/"; const string username = "******"; const string password = "******"; SetupSuccessfulResponse(OAuthTokenFactory.SomeToken()); actor.AttemptsTo(GetAccessToken .UsingResourceOwnerPasswordCredentialFlow() .WithCredentials(username, password) .FromEndpoint(endpoint)); var lastRequestContent = sender.GetLastSentMessage().RequestUri.AbsoluteUri; Check.That(lastRequestContent).IsEqualTo(endpoint); }
public void actor_should_remember_access_token_after_response() { const string endpoint = "http://localhost:5000/"; const string username = "******"; const string password = "******"; var token = OAuthTokenFactory.SomeToken(); SetupSuccessfulResponse(token); actor.AttemptsTo(GetAccessToken .UsingResourceOwnerPasswordCredentialFlow() .WithCredentials(username, password) .FromEndpoint(endpoint)); var rememberedToken = actor.Recall <OAuthToken>(TokenConstants.TokenKey); Check.That(rememberedToken).HasFieldsWithSameValues(token); }
public void should_send_username_and_password() { const string endpoint = "http://localhost:5000/"; const string username = "******"; const string password = "******"; const string expected = "grant_type=password&username=admin&password=123456"; SetupSuccessfulResponse(OAuthTokenFactory.SomeToken()); actor.AttemptsTo(GetAccessToken .UsingResourceOwnerPasswordCredentialFlow() .WithCredentials(username, password) .FromEndpoint(endpoint)); var lastRequestContent = sender.GetLastSentMessage().Content.ReadAsStringAsync().Result; Check.That(lastRequestContent).IsEqualTo(expected); }
private void ActorRequestsForAccessToken() { this._actor.AttemptsTo(GetAccessToken.UsingResourceOwnerPasswordCredentialFlow() .WithCredentials("Admin", "123456") .FromEndpoint("http://localhost:5000")); }