Exemplo n.º 1
0
 public async Task ParsesSuccessResponseWithoutData(JSendClient client)
 {
     // Exercise system
     using (client)
         using (var response = await client.GetAsync <User>("http://localhost/users/success"))
         {
             // Verify outcome
             response.Status.Should().Be(JSendStatus.Success);
             response.HasData.Should().BeFalse();
         }
 }
Exemplo n.º 2
0
 public async Task ParsesSuccessResponseWithoutData(JSendClient client)
 {
     // Exercise system
     using (client)
     using (var response = await client.GetAsync<User>("http://localhost/users/success"))
     {
         // Verify outcome
         response.Status.Should().Be(JSendStatus.Success);
         response.HasData.Should().BeFalse();
     }
 }
Exemplo n.º 3
0
        public async Task GetAsync_SendsGetRequest(
            [FrozenAsHttpClient] HttpClientSpy httpClientSpy,
            Uri uri, [Greedy] JSendClient client)
        {
            // Exercise system
            await client.GetAsync <Model>(uri);

            // Verify outcome
            var request = httpClientSpy.Request;

            request.Method.Should().Be(HttpMethod.Get);
        }
Exemplo n.º 4
0
 public async Task ParsesFailResponse(JSendClient client)
 {
     // Exercise system
     using (client)
         using (var response = await client.GetAsync <User>("http://localhost/users/fail"))
         {
             // Verify outcome
             response.Status.Should().Be(JSendStatus.Fail);
             response.HasData.Should().BeFalse();
             response.Error.Data.Value <string>().Should().Be(UsersController.ErrorData);
         }
 }
Exemplo n.º 5
0
 public async Task ParsesSuccessResponseWithData(JSendClient client)
 {
     // Exercise system
     using (client)
         using (var response = await client.GetAsync <User>("http://localhost/users/success-with-user"))
         {
             // Verify outcome
             response.Status.Should().Be(JSendStatus.Success);
             response.HasData.Should().BeTrue();
             response.Data.ShouldBeEquivalentTo(UsersController.TestUser);
         }
 }
Exemplo n.º 6
0
 public async Task ParsesFailResponse(JSendClient client)
 {
     // Exercise system
     using (client)
     using (var response = await client.GetAsync<User>("http://localhost/users/fail"))
     {
         // Verify outcome
         response.Status.Should().Be(JSendStatus.Fail);
         response.HasData.Should().BeFalse();
         response.Error.Data.Value<string>().Should().Be(UsersController.ErrorData);
     }
 }
Exemplo n.º 7
0
 public async Task ParsesSuccessResponseWithData(JSendClient client)
 {
     // Exercise system
     using (client)
     using (var response = await client.GetAsync<User>("http://localhost/users/success-with-user"))
     {
         // Verify outcome
         response.Status.Should().Be(JSendStatus.Success);
         response.HasData.Should().BeTrue();
         response.Data.ShouldBeEquivalentTo(UsersController.TestUser);
     }
 }
 public async Task InterceptsRequestsBeforeBeingSent(
     [WithInterceptor(typeof(VersionHeaderInterceptor))] JSendClient client)
 {
     // Exercise system
     using (client)
         using (var response =
                    await client.GetAsync <Dictionary <string, List <string> > >("http://localhost/users/echo-headers"))
         {
             // Verify outcome
             response.Data.Should().ContainKey("Version")
             .WhichValue.Should().ContainSingle("1");
         }
 }
        public async Task InterceptsParsedResponses(
            [FrozenWithoutAutoProperties] InterceptorSpy spy,
            [WithInterceptor(typeof(InterceptorSpy))] JSendClient client)
        {
            using (client)
                using (var response = await client.GetAsync <string>("http://localhost/users/get"))
                {
                    // Exercise system and verify outcome
                    spy.ResponseParsedContext.Should().NotBeNull();

                    spy.ResponseParsedContext.As <ResponseParsedContext <string> >()
                    .JSendResponse.Should().Be(response);
                }
        }
Exemplo n.º 10
0
        public async Task GetAsync_SetsUri(
            string uri,
            Uri expectedUri,
            [FrozenAsHttpClient] HttpClientSpy httpClientSpy,
            [Greedy] JSendClient client)
        {
            // Exercise system
            await client.GetAsync <Model>(uri);

            // Verify outcome
            var request = httpClientSpy.Request;

            request.RequestUri.Should().Be(expectedUri);
        }
Exemplo n.º 11
0
        public void BlockingDoesNotCauseDeadlocks(JSendClient client)
        {
            // Fixture setup
            // Use a synchronization context that schedules continuations on the initial thread to mimic an UI application.
            // This scenario is also somewhat equivalent to an ASP.NET environment, where the request context is not tied to a specific thread,
            // but is limited to one thread at a time (http://blog.stephencleary.com/2012/07/dont-block-on-async-code.html).
            Action action = () => AsyncContext.Run(() =>
            {
                client.GetAsync <string>("http://localhost/users/get").Wait();
            });

            // Exercise system and verify outcome
            action.ExecutionTime().ShouldNotExceed(3.Seconds());
        }
Exemplo n.º 12
0
        public async Task SendsGetRequestsToTheCorrectEndpoint(string baseAddress, string requestUri, JSendClient client)
        {
            using (client)
            {
                // Fixture setup
                client.HttpClient.BaseAddress = baseAddress == null ? null : new Uri(baseAddress);

                // Exercise system
                using (var response = await client.GetAsync <string>(requestUri))
                {
                    // Verify outcome
                    response.Status.Should().Be(JSendStatus.Success);
                    response.Data.Should().Be("get");
                }
            }
        }
Exemplo n.º 13
0
        public async Task SendsGetRequestsToTheCorrectEndpoint(string baseAddress, string requestUri, JSendClient client)
        {
            using (client)
            {
                // Fixture setup
                client.HttpClient.BaseAddress = baseAddress == null ? null : new Uri(baseAddress);

                // Exercise system
                using (var response = await client.GetAsync<string>(requestUri))
                {
                    // Verify outcome
                    response.Status.Should().Be(JSendStatus.Success);
                    response.Data.Should().Be("get");
                }
            }
        }
Exemplo n.º 14
0
        public async Task GetAsync_ReturnsParsedResponse(
            HttpResponseMessage httpResponse, JSendResponse <Model> parsedResponse,
            [FrozenAsHttpClient] HttpClientStub clientStub,
            Uri uri, [Greedy] JSendClient client)
        {
            // Fixture setup
            clientStub.ReturnOnSend = httpResponse;

            Mock.Get(client.Parser)
            .Setup(p => p.ParseAsync <Model>(It.IsAny <JsonSerializerSettings>(), httpResponse))
            .ReturnsAsync(parsedResponse);
            // Exercise system
            var response = await client.GetAsync <Model>(uri);

            // Verify outcome
            response.Should().BeSameAs(parsedResponse);
        }
        public async Task InterceptsExceptions(
            [FrozenWithoutAutoProperties] InterceptorSpy spy,
            [WithInterceptor(typeof(InterceptorSpy))] JSendClient client)
        {
            using (client)
            {
                try
                {
                    await client.GetAsync <string>("http://localhost/users/non-jsend");
                }
                catch
                {
                }

                // Exercise system and verify outcome
                spy.ExceptionContext.Should().NotBeNull();

                spy.ExceptionContext.Exception
                .Should().BeOfType <JSendParseException>();
            }
        }