public async Task<HttpResponseMessage> PostAsync(CreateIncidentRequest request)
        {
            Log.Information("Create incident from file has been requested : {@createIncidentFromFileRequest}", request);

            try
            {
                if (!ModelState.IsValid)
                {
                    Log.Error("Could not create incident from file: {errors}", ModelState.SerializeForLog());
                    return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
                }

                var incident = incidentRequestMapper.Map(request);
                await incidentExchangePublisher.PublishAsync(incident, incident.jobIdentifier);

                return Request.CreateResponse(HttpStatusCode.OK,
                    new ApiResponse { message = string.Format("The request has completed successfully. A incident has been queued for {0}.", request.JobIdentifier) });
            }
            catch (Exception ex)
            {
                const string message = "An error occurred while creating the incident.";
                Log.Error(ex, message);
                return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, message);
            }
        }
        public async Task WhenPostFromFile_ThenMapRequest()
        {
            var request = new CreateIncidentRequest
            {
                JobIdentifier = It.IsAny<string>(),
                JobSubject = It.IsAny<string>(),
                JobPredicate = It.IsAny<string>()
            };

            var sut = CreateController(new HttpRequestMessage());
            await sut.PostAsync(request);

            incidentRequestMapper.Verify(x => x.Map(request));
        }
        public async Task WhenPostFromFile_AndUnexpectedException_ThenReturnInternalServerError()
        {
            incidentRequestMapper.Setup(x => x.Map(It.IsAny<CreateIncidentRequest>()))
                .Throws(new Exception());

            var sut = CreateController(new HttpRequestMessage());

            var request = new CreateIncidentRequest
            {
                JobIdentifier = It.IsAny<string>(),
                JobSubject = It.IsAny<string>(),
                JobPredicate = It.IsAny<string>()
            };

            var result = await sut.PostAsync(request);

            Assert.AreEqual(HttpStatusCode.InternalServerError, result.StatusCode);
        }
        public async Task WhenPostFromFile_ThenPublishAsync()
        {
            var request = new CreateIncidentRequest
            {
                JobIdentifier = It.IsAny<string>(),
                JobSubject = It.IsAny<string>(),
                JobPredicate = It.IsAny<string>()
            };

            var incident = new Incident { jobIdentifier = Guid.NewGuid().ToString() };

            ExpectIncidentMapperToMap(incident);
            ExpectExchangeToPublish();

            var sut = CreateController(new HttpRequestMessage());
            await sut.PostAsync(request);

            exchange.Verify(x => x.PublishAsync(incident, It.IsAny<string>()));
        }
        public async Task WhenPostFromFile_AndPublishAsyncFaults_ThenReturnInternalServerError()
        {
            var request = new CreateIncidentRequest
            {
                JobIdentifier = It.IsAny<string>(),
                JobSubject = It.IsAny<string>(),
                JobPredicate = It.IsAny<string>()
            };

            var incident = new Incident { jobIdentifier = Guid.NewGuid().ToString() };

            ExpectIncidentMapperToMap(incident);
            ExpectExchangeToFaultOnPublish();

            var sut = CreateController(new HttpRequestMessage());
            var result = await sut.PostAsync(request);

            Assert.AreEqual(HttpStatusCode.InternalServerError, result.StatusCode);
        }