Example #1
0
        public void should_use_query_string_both_from_resource_name_and_added_query_strings()
        {
            var baseUrl      = "http://localhost:5050";
            var resourceName = "api/users?page=2";
            var expectedUrl  = "http://localhost:5050/api/users?page=2&UserId=2&LocationId=3";
            var juliet       = Actor.Named(Names.Juliet).WhoCan(CallAnApi.At(baseUrl).With(Sender));

            juliet.AttemptsTo(GetHttpInteraction(resourceName)
                              .WithQueryParameter("UserId", "2")
                              .WithQueryParameter("LocationId", "3"));

            Check.That(Sender.GetLastSentMessage().RequestUri.AbsoluteUri).IsEqualTo(expectedUrl);
        }
Example #2
0
        public void should_intercept_requests_with_multiple_interceptors()
        {
            var tokenInterceptor  = FakeHttpInterceptor.SetupToAddHeader(HttpHeaders.Authorization, TokenValue);
            var acceptInterceptor = FakeHttpInterceptor.SetupToAddHeader(HttpHeaders.Accept, MediaTypes.ApplicationJson);
            var callAnApi         = CallAnApi.At(Urls.Google).With(_sender)
                                    .WhichRequestsInterceptedBy(tokenInterceptor)
                                    .WhichRequestsInterceptedBy(acceptInterceptor);

            callAnApi.SendRequest(_request);

            Check.That(_sender.GetLastSentMessage().FirstValueOfHeader(HttpHeaders.Authorization)).IsEqualTo(TokenValue);
            Check.That(_sender.GetLastSentMessage().FirstValueOfHeader(HttpHeaders.Accept)).IsEqualTo(MediaTypes.ApplicationJson);
        }
Example #3
0
        public void Modify_part_of_an_user()
        {
            var jack = Actor.Named("Jack").WhoCan(CallAnApi.At("https://reqres.in"));
            var user = new User {
                Name = "Sarah", Job = "Software Architect"
            };

            jack.AttemptsTo(ModifyPartOf(user));

            jack.Should(See.That(LastResponse.Content <ModifyUserResponse>()))
            .Considering().All.Properties.HasFieldsWithSameValues(user);
            jack.Should(See.That(LastResponse.StatusCode())).IsEqualTo(HttpStatusCode.OK);
        }
Example #4
0
        public void should_intercept_requests_in_order_of_registration()
        {
            const string sandbox           = "Sandbox";
            var          firstInterceptor  = FakeHttpInterceptor.SetupToAddHeader(sandbox, "test");
            var          secondInterceptor = FakeHttpInterceptor.SetupToAddHeader(sandbox, "test test");
            var          callAnApi         = CallAnApi.At(Urls.Google).With(_sender)
                                             .WhichRequestsInterceptedBy(firstInterceptor)
                                             .WhichRequestsInterceptedBy(secondInterceptor);

            callAnApi.SendRequest(_request);

            Check.That(_sender.GetLastSentMessage().FirstValueOfHeader(sandbox)).IsEqualTo("test");
            Check.That(_sender.GetLastSentMessage().SecondValueOfHeader(sandbox)).IsEqualTo("test test");
        }
Example #5
0
        public void should_post_a_person_to_api()
        {
            var jack   = Actor.Named("Jack").WhoCan(CallAnApi.At(_fixture.Host.BaseUrl));
            var person = new CreatePerson {
                Firstname = "Sarah", Lastname = "Ohara"
            };

            jack.AttemptsTo(Post.DataAsJson(person).To("api/People"));
            var resourceLocation = jack.AsksFor(LastResponse.Header(HttpHeaders.Location));

            jack.AttemptsTo(Get.ResourceAt(resourceLocation));

            jack.Should(See.That(LastResponse.Content <Person>()))
            .Considering().All.Properties.HasFieldsWithSameValues(person);
        }
Example #6
0
        public void should_raise_start_sending_http_request_event()
        {
            var baseUrl         = "http://localhost:5050";
            var resourceName    = "api/users";
            var expectedUrl     = "http://localhost:5050/api/users";
            var juliet          = Actor.Named(Names.Juliet).WhoCan(CallAnApi.At(baseUrl).With(Sender));
            var publishedEvents = new Queue <IEvent>();

            Broadcaster.SubscribeToAllEvents(new DelegatingEventHandler(z => publishedEvents.Enqueue(z)));

            juliet.AttemptsTo(GetHttpInteraction(resourceName));

            Check.That(publishedEvents.CountOfType <StartSendingHttpRequestEvent>()).IsEqualTo(1);
            Check.That(publishedEvents.FirstElementOfType <StartSendingHttpRequestEvent>().Method).IsEqualTo(GetHttpMethod());
            Check.That(publishedEvents.FirstElementOfType <StartSendingHttpRequestEvent>().Url).IsEqualTo(expectedUrl);
            Check.That(publishedEvents.FirstElementOfType <StartSendingHttpRequestEvent>().ActorName).IsEqualTo(Names.Juliet);
        }
Example #7
0
 public static Actor CreateSomeActorWithApiCallAbility(IHttpRequestSender sender)
 {
     return(Actor.Named(Names.Juliet).WhoCan(CallAnApi.At(Urls.Google).With(sender)));
 }
Example #8
0
        public void should_set_base_url()
        {
            var callAnApi = CallAnApi.At(Urls.Google);

            Check.That(callAnApi.BaseUrl).IsEqualTo(Urls.Google);
        }