Example #1
0
        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>();
        }
Example #2
0
        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);
        }
Example #3
0
        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);
        }
Example #4
0
        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);
        }
Example #5
0
 private void ActorRequestsForAccessToken()
 {
     this._actor.AttemptsTo(GetAccessToken.UsingResourceOwnerPasswordCredentialFlow()
                            .WithCredentials("Admin", "123456")
                            .FromEndpoint("http://localhost:5000"));
 }