Exemplo n.º 1
0
        public void should_send_http_request_using_sender()
        {
            var callAnApi = CallAnApi.At(Urls.Google).With(_sender);

            callAnApi.SendRequest(_request);

            Check.That(_sender.GetLastSentMessage()).IsEqualTo(_request);
        }
Exemplo n.º 2
0
        public void should_send_request_to_correct_url(string baseUrl, string resource, string expectedUrl)
        {
            var juliet = Actor.Named(Names.Juliet).WhoCan(CallAnApi.At(baseUrl).With(Sender));

            juliet.AttemptsTo(GetHttpInteraction(resource));

            Check.That(Sender.GetLastSentMessage().RequestUri.AbsoluteUri).IsEqualTo(expectedUrl);
        }
Exemplo n.º 3
0
        public void should_intercept_requests_with_interceptors()
        {
            var interceptor = FakeHttpInterceptor.SetupToAddHeader(HttpHeaders.Authorization, TokenValue);
            var callAnApi   = CallAnApi.At(Urls.Google).With(_sender).WhichRequestsInterceptedBy(interceptor);

            callAnApi.SendRequest(_request);

            Check.That(_sender.GetLastSentMessage().FirstValueOfHeader(HttpHeaders.Authorization)).IsEqualTo(TokenValue);
        }
Exemplo n.º 4
0
        public void should_add_query_string_when_resource_have_query_string_in_it()
        {
            var baseUrl      = "http://localhost:5050";
            var resourceName = "api/users?page=2";
            var expectedUrl  = "http://localhost:5050/api/users?page=2";
            var juliet       = Actor.Named(Names.Juliet).WhoCan(CallAnApi.At(baseUrl).With(Sender));

            juliet.AttemptsTo(GetHttpInteraction(resourceName));

            Check.That(Sender.GetLastSentMessage().RequestUri.AbsoluteUri).IsEqualTo(expectedUrl);
        }
Exemplo n.º 5
0
        public void Fetch_user_by_id()
        {
            var jack             = Actor.Named("Jack").WhoCan(CallAnApi.At("https://reqres.in"));
            var expectedResponse = new GetUserByIdResponse(id: 2, name: "fuchsia rose");

            jack.AttemptsTo(FetchUserById(2));

            jack.Should(See.That(LastResponse.Content <GetUserByIdResponse>()))
            .Considering().All.Properties.HasFieldsWithSameValues(expectedResponse);
            jack.Should(See.That(LastResponse.StatusCode())).IsEqualTo(HttpStatusCode.OK);
        }
Exemplo n.º 6
0
        public void Delete_an_user()
        {
            var jack = Actor.Named("Jack").WhoCan(CallAnApi.At("https://reqres.in"));
            var user = new User {
                Name = "Sarah", Job = "Software Architect"
            };

            jack.AttemptsTo(DeleteAn(user));

            jack.Should(See.That(LastResponse.Content <object>())).IsNull();
            jack.Should(See.That(LastResponse.StatusCode())).IsEqualTo(HttpStatusCode.NoContent);
        }
Exemplo n.º 7
0
        public void should_send_request_to_url_with_query_parameters()
        {
            var baseUrl      = "http://localhost:5050";
            var resourceName = "api/users";
            var expectedUrl  = "http://localhost:5050/api/users?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);
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
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");
        }
Exemplo n.º 10
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);
        }
Exemplo n.º 11
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);
        }
Exemplo n.º 12
0
 public static Actor CreateSomeActorWithApiCallAbility(IHttpRequestSender sender)
 {
     return(Actor.Named(Names.Juliet).WhoCan(CallAnApi.At(Urls.Google).With(sender)));
 }
Exemplo n.º 13
0
        public void should_set_base_url()
        {
            var callAnApi = CallAnApi.At(Urls.Google);

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