public async Task ErrorSetIsReturned(ErrorSet errorSet)
        {
            var controller = new DummyController
            {
                Configuration = new HttpConfiguration(),
                Request       = new HttpRequestMessage()
            };

            controller.Request.Headers.Accept.Clear();
            controller.Request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            var statusCode   = HttpStatusCode.MethodNotAllowed;
            var actionResult = new FailureWithErrorSetResult(statusCode, controller, errorSet);
            var response     = await actionResult.ExecuteAsync(new CancellationToken());

            var responseSet = await response.Content.ReadAsAsync <ErrorSet>();

            responseSet.Should().NotBeNull("because an error set should be present in the response");
            responseSet.Errors.Should().NotBeNull("because there should be an error collection present in the response, even if empty");

            var expectedErrors = errorSet.Errors.OrderBy(item => item.Code).ToList();
            var responseErrors = responseSet.Errors.OrderBy(item => item.Code).ToList();

            responseErrors.Should().HaveSameCount(expectedErrors, "because the number of errors in the result should match the provided error set")
            .And.Equal(expectedErrors, (left, right) => ((left.Code == right.Code) && (left.Description == right.Description)), "because the provided error set should have been used in the response");
        }
        public async Task ContentTypeIsSetOnResponse()
        {
            var controller = new DummyController
            {
                Configuration = new HttpConfiguration(),
                Request       = new HttpRequestMessage()
            };

            var statusCode   = HttpStatusCode.MethodNotAllowed;
            var actionResult = new FailureWithErrorSetResult(statusCode, controller, new ErrorSet());
            var response     = await actionResult.ExecuteAsync(new CancellationToken());

            response.Content.Headers.ContentLanguage.Any().Should().BeTrue("because the response should specify the content type.");
        }
        public async void HttpStatusCodeIsCorrect()
        {
            var controller = new DummyController
            {
                Configuration = new HttpConfiguration(),
                Request       = new HttpRequestMessage()
            };

            var statusCode   = HttpStatusCode.Forbidden;
            var actionResult = new FailureWithErrorSetResult(statusCode, controller, new ErrorSet());
            var response     = await actionResult.ExecuteAsync(new CancellationToken());

            response.StatusCode.Should().Be(statusCode, "because the result should set the provided status code");
        }
        public async Task ContentTypeIsReturned(string expectedContentType)
        {
            var controller = new DummyController
            {
                Configuration = new HttpConfiguration(),
                Request       = new HttpRequestMessage()
            };

            var statusCode   = HttpStatusCode.ExpectationFailed;
            var actionResult = new FailureWithErrorSetResult(statusCode, controller, new ErrorSet(), expectedContentType);
            var response     = await actionResult.ExecuteAsync(new CancellationToken());

            response.Content.Headers.ContentLanguage.FirstOrDefault().Should().Be(expectedContentType, "because the Content-Type header should ahve been set.");
        }
        public async Task ContentTypeAssignsDefault(string contentType)
        {
            var controller = new DummyController
            {
                Configuration = new HttpConfiguration(),
                Request       = new HttpRequestMessage()
            };

            var statusCode   = HttpStatusCode.HttpVersionNotSupported;
            var actionResult = new FailureWithErrorSetResult(statusCode, controller, new ErrorSet(), contentType);
            var response     = await actionResult.ExecuteAsync(new CancellationToken());

            response.Content.Headers.ContentLanguage.Any().Should().BeTrue("because the response should specify the content type.");
            response.Content.Headers.ContentLanguage.First().Trim().Length.Should().BeGreaterOrEqualTo(1, "because the content type should have a default value.");
        }