Example #1
0
        public void RequestIsCorrectlyInitializedUsingController(HttpStatusCode status, IJSendResponse response, ApiController controller)
        {
            // Exercise system
            var result = new JSendResult <IJSendResponse>(status, response, controller);

            // Verify outcome
            result.Request.Should().Be(controller.Request);
        }
Example #2
0
        public async Task SetsStatusCode(JSendResult <IJSendResponse> result)
        {
            // Exercise system
            var message = await result.ExecuteAsync(new CancellationToken());

            // Verify outcome
            message.StatusCode.Should().Be(result.StatusCode);
        }
Example #3
0
        public async Task SetsContentTypeHeader(JSendResult <IJSendResponse> result)
        {
            // Exercise system
            var message = await result.ExecuteAsync(new CancellationToken());

            // Verify outcome
            message.Content.Headers.ContentType.MediaType.Should().Be("application/json");
        }
Example #4
0
        public void RequestIsCorrectlyInitialized(HttpStatusCode status, IJSendResponse response, HttpRequestMessage request)
        {
            // Exercise system
            var result = new JSendResult <IJSendResponse>(status, response, request);

            // Verify outcome
            result.Request.Should().Be(request);
        }
Example #5
0
        public void StatusCodeIsCorrectlyInitialized(HttpStatusCode expectedStatusCode, IJSendResponse response,
                                                     ApiController controller)
        {
            // Exercise system
            var result = new JSendResult <IJSendResponse>(expectedStatusCode, response, controller);

            // Verify outcome
            result.StatusCode.Should().Be(expectedStatusCode);
        }
Example #6
0
        public void ResponseIsCorrectlyInitialized(HttpStatusCode code, IJSendResponse response,
                                                   ApiController controller)
        {
            // Exercise system
            var result = new JSendResult <IJSendResponse>(code, response, controller);

            // Verify outcome
            result.Response.Should().BeSameAs(response);
        }
Example #7
0
 public void ExecuteThrowsWhenRequestHasNoContext(HttpStatusCode status, IJSendResponse response)
 {
     // Fixture setup
     var request = new HttpRequestMessage();
     var result = new JSendResult<IJSendResponse>(status, response, request);
     // Exercise system and verify outcome
     result.Awaiting(r => r.ExecuteAsync(CancellationToken.None))
         .ShouldThrow<InvalidOperationException>()
         .WithMessage(StringResources.Request_RequestContextMustNotBeNull);
 }
Example #8
0
 public void ExecuteThrowsWhenControllerHasNoRequest(HttpStatusCode status, IJSendResponse response,
     [NoAutoProperties] TestableJSendApiController controller)
 {
     // Fixture setup
     var result = new JSendResult<IJSendResponse>(status, response, controller);
     // Exercise system and verify outcome
     result.Awaiting(r => r.ExecuteAsync(CancellationToken.None))
         .ShouldThrow<InvalidOperationException>()
         .WithMessage("ApiController.Request must not be null.");
 }
Example #9
0
        public void ExecuteThrowsWhenControllerHasNoRequest(HttpStatusCode status, IJSendResponse response,
                                                            [NoAutoProperties] TestableJSendApiController controller)
        {
            // Fixture setup
            var result = new JSendResult <IJSendResponse>(status, response, controller);

            // Exercise system and verify outcome
            result.Awaiting(r => r.ExecuteAsync(CancellationToken.None))
            .ShouldThrow <InvalidOperationException>()
            .WithMessage("ApiController.Request must not be null.");
        }
Example #10
0
        public void ExecuteThrowsWhenRequestHasNoContext(HttpStatusCode status, IJSendResponse response)
        {
            // Fixture setup
            var request = new HttpRequestMessage();
            var result  = new JSendResult <IJSendResponse>(status, response, request);

            // Exercise system and verify outcome
            result.Awaiting(r => r.ExecuteAsync(CancellationToken.None))
            .ShouldThrow <InvalidOperationException>()
            .WithMessage(StringResources.Request_RequestContextMustNotBeNull);
        }
Example #11
0
        public async Task SerializesResponse(JSendResult <SuccessResponse> result)
        {
            // Fixture setup
            var expectedContent = JsonConvert.SerializeObject(result.Response);
            // Exercise system
            var message = await result.ExecuteAsync(new CancellationToken());

            // Verify outcome
            var content = await message.Content.ReadAsStringAsync();

            content.Should().Be(expectedContent);
        }
Example #12
0
        public void ExecuteThrowsWhenRequestContextHasNoConfiguration(HttpRequestMessage request, HttpStatusCode status,
            IJSendResponse response)
        {
            // Fixture setup
            var requestContext = new HttpRequestContext();
            request.SetRequestContext(requestContext);

            var result = new JSendResult<IJSendResponse>(status, response, request);
            // Exercise system and verify outcome
            result.Awaiting(r => r.ExecuteAsync(CancellationToken.None))
                .ShouldThrow<InvalidOperationException>()
                .WithMessage("HttpRequestContext.Configuration must not be null.");
        }
Example #13
0
        public void ExecuteThrowsWhenRequestContextHasNoConfiguration(HttpRequestMessage request, HttpStatusCode status,
                                                                      IJSendResponse response)
        {
            // Fixture setup
            var requestContext = new HttpRequestContext();

            request.SetRequestContext(requestContext);

            var result = new JSendResult <IJSendResponse>(status, response, request);

            // Exercise system and verify outcome
            result.Awaiting(r => r.ExecuteAsync(CancellationToken.None))
            .ShouldThrow <InvalidOperationException>()
            .WithMessage("HttpRequestContext.Configuration must not be null.");
        }
Example #14
0
        public void ExecuteThrowsWhenControllerHasNoJsonFormatter(HttpStatusCode status, IJSendResponse response,
                                                                  ApiController controller)
        {
            // Fixture setup
            var formatters = controller.Configuration.Formatters;

            formatters.OfType <JsonMediaTypeFormatter>().ToList()
            .ForEach(f => formatters.Remove(f));

            var result = new JSendResult <IJSendResponse>(status, response, controller);

            // Exercise system and verify outcome
            result.Awaiting(r => r.ExecuteAsync(CancellationToken.None))
            .ShouldThrow <InvalidOperationException>()
            .WithMessage(StringResources.ConfigurationMustContainFormatter);
        }
Example #15
0
 public void StatusCodeIsCorrectlyInitialized(HttpStatusCode expectedStatusCode, IJSendResponse response,
     ApiController controller)
 {
     // Exercise system
     var result = new JSendResult<IJSendResponse>(expectedStatusCode, response, controller);
     // Verify outcome
     result.StatusCode.Should().Be(expectedStatusCode);
 }
Example #16
0
 public async Task SerializesResponse(JSendResult<SuccessResponse> result)
 {
     // Fixture setup
     var expectedContent = JsonConvert.SerializeObject(result.Response);
     // Exercise system
     var message = await result.ExecuteAsync(new CancellationToken());
     // Verify outcome
     var content = await message.Content.ReadAsStringAsync();
     content.Should().Be(expectedContent);
 }
Example #17
0
 public void RequestIsCorrectlyInitializedUsingController(HttpStatusCode status, IJSendResponse response, ApiController controller)
 {
     // Exercise system
     var result = new JSendResult<IJSendResponse>(status, response, controller);
     // Verify outcome
     result.Request.Should().Be(controller.Request);
 }
Example #18
0
 public async Task SetsStatusCode(JSendResult<IJSendResponse> result)
 {
     // Exercise system
     var message = await result.ExecuteAsync(new CancellationToken());
     // Verify outcome
     message.StatusCode.Should().Be(result.StatusCode);
 }
Example #19
0
 public async Task SetsContentTypeHeader(JSendResult<IJSendResponse> result)
 {
     // Exercise system
     var message = await result.ExecuteAsync(new CancellationToken());
     // Verify outcome
     message.Content.Headers.ContentType.MediaType.Should().Be("application/json");
 }
Example #20
0
        public void ExecuteThrowsWhenControllerHasNoJsonFormatter(HttpStatusCode status, IJSendResponse response,
            ApiController controller)
        {
            // Fixture setup
            var formatters = controller.Configuration.Formatters;
            formatters.OfType<JsonMediaTypeFormatter>().ToList()
                .ForEach(f => formatters.Remove(f));

            var result = new JSendResult<IJSendResponse>(status, response, controller);
            // Exercise system and verify outcome
            result.Awaiting(r => r.ExecuteAsync(CancellationToken.None))
                .ShouldThrow<InvalidOperationException>()
                .WithMessage(StringResources.ConfigurationMustContainFormatter);
        }
Example #21
0
 public void ResponseIsCorrectlyInitialized(HttpStatusCode code, IJSendResponse response,
     ApiController controller)
 {
     // Exercise system
     var result = new JSendResult<IJSendResponse>(code, response, controller);
     // Verify outcome
     result.Response.Should().BeSameAs(response);
 }
Example #22
0
 public void RequestIsCorrectlyInitialized(HttpStatusCode status, IJSendResponse response, HttpRequestMessage request)
 {
     // Exercise system
     var result = new JSendResult<IJSendResponse>(status, response, request);
     // Verify outcome
     result.Request.Should().Be(request);
 }