Ejemplo n.º 1
0
        public async Task<HttpResponseMessage> PostAsync(CreateJobFromFileRequest request)
        {
            Log.Information("Create job from file has been requested : {@createJobFromFileRequest}", request);

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

                var job = jobRequestMapper.Map(request);
                await jobExchangePublisher.PublishAsync(job, job.jobIdentifier);
                
                return Request.CreateResponse(HttpStatusCode.OK,
                    new ApiResponse { message = string.Format("The request has completed successfully. A job has been queued for {0}.", request.FileName) });
            }
            catch (Exception ex)
            {
                const string message = "An error occurred while creating the job.";
                Log.Error(ex, message);
                return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, message);
            }
        }
Ejemplo n.º 2
0
        public async Task WhenPostFromFile_ThenMapRequest()
        {
            var request = new CreateJobFromFileRequest
            {
                FileName = Constants.ValidNSBDFileName
            };

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

            jobRequestMapper.Verify(x => x.Map(request));
        }
        public void GivenNoPredicate_WhenValidate_ThenFail()
        {
            var request = new CreateJobFromFileRequest
            {
                FileName = Constants.ValidNSBDFileName,
                JobPredicate = null,
                JobSubject = "test"
            };

            var result = Validator.TryValidateObject(request, new ValidationContext(request, null, null), null, true);

            Assert.IsFalse(result);
        }
        public void GivenInvalidFileName_WhenValidate_ThenFail()
        {
            var request = new CreateJobFromFileRequest
            {
                FileName = "So Obviously Broken",
                JobPredicate = "test",
                JobSubject = "test"
            };

            var result = Validator.TryValidateObject(request, new ValidationContext(request, null, null), null, true);

            Assert.IsFalse(result);
        }
        public void GivenValidInClearingFileName_WhenValidate_ThenPass()
        {
            var request = new CreateJobFromFileRequest
            {
                FileName = Constants.ValidNIEIFileName,
                JobPredicate = "test",
                JobSubject = "test"
            };

            var result = Validator.TryValidateObject(request, new ValidationContext(request, null, null), null, true);

            Assert.IsTrue(result);
        }
Ejemplo n.º 6
0
        public async Task WhenPostFromFile_AndUnexpectedException_ThenReturnInternalServerError()
        {
            jobRequestMapper.Setup(x => x.Map(It.IsAny<CreateJobFromFileRequest>()))
                .Throws(new Exception());

            var sut = CreateController(new HttpRequestMessage());

            var request = new CreateJobFromFileRequest
            {
                FileName = Constants.ValidNSBDFileName
            };

            var result = await sut.PostAsync(request);

            Assert.AreEqual(HttpStatusCode.InternalServerError, result.StatusCode);
        }
Ejemplo n.º 7
0
        public void GiveCreateJobFromNSBDFileRequest_WhenMap_ThenUseDateTimeProvider()
        {
            var request = new CreateJobFromFileRequest
            {
                FileName = Constants.ValidNSBDFileName,
                JobSubject = "voucher",
                JobPredicate = "outclearings",
                JobIdentifier = Constants.ValidNSBDFileName.Substring(Constants.ValidNSBDFileName.IndexOf("_", StringComparison.Ordinal) + 1, Constants.ValidNSBDFileName.IndexOf(".", StringComparison.Ordinal) - Constants.ValidNSBDFileName.IndexOf("_", StringComparison.Ordinal) - 1)
            };

            var sut = CreateMapper();

            sut.Map(request);

            dateTimeProvider.Verify(x => x.CurrentTimeInAustralianEasternTimeZone());
        }
Ejemplo n.º 8
0
        public async Task WhenPostFromFile_ThenPublishAsync()
        {
            var request = new CreateJobFromFileRequest
            {
                FileName = Constants.ValidNSBDFileName
            };

            var job = new JobRequest { jobIdentifier = Guid.NewGuid().ToString() };

            ExpectJobRequestMapperToMap(job);
            ExpectExchangeToPublish();

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

            exchange.Verify(x => x.PublishAsync(job, It.IsAny<string>()));
        }
Ejemplo n.º 9
0
        public void GiveCreateJobFromNIEIFileRequest_WhenMap_ThenMapToJobRequest()
        {
            var request = new CreateJobFromFileRequest
            {
                FileName = Constants.ValidNIEIFileName,
                JobSubject = "inwardimageexchange",
                JobPredicate = "inclearings",
                JobIdentifier = "NIEI-2cbabea0-43f9-4554-b118-c80c487d97c3"
            };

            var sut = CreateMapper();

            var result = sut.Map(request);

            Assert.AreEqual(Constants.ValidNIEIJobId, result.jobIdentifier);
            Assert.AreEqual(request.JobSubject, result.subject);
            Assert.AreEqual(request.JobPredicate, result.predicate);
        }
Ejemplo n.º 10
0
        public void GiveCreateJobFromNSBDFileRequest_WhenMap_ThenMapToJobRequest()
        {
            var request = new CreateJobFromFileRequest
            {
                FileName = Constants.ValidNSBDFileName,
                JobSubject = "voucher",
                JobPredicate = "outclearings",
                JobIdentifier = Constants.ValidNSBDJobId
            };

            var sut = CreateMapper();

            var result = sut.Map(request);

            Assert.AreEqual(Constants.ValidNSBDJobId, result.jobIdentifier);
            Assert.AreEqual(request.JobSubject, result.subject);
            Assert.AreEqual(request.JobPredicate, result.predicate);
        }
Ejemplo n.º 11
0
        public void WhenCodelineValidationRequest(string subject, string predicate, string fileName, string parameters)
        {
            var message = new CreateJobFromFileRequest
            {
                FileName = fileName,
                JobSubject = subject,
                JobPredicate = predicate,
                JobIdentifier = jobIdentifier,
                Parameters = parameters == "empty" ? null : parameters
            };

            var httpClient = new HttpClient();
            var url = string.Format("{0}jobs", ConfigurationHelper.MftAdapterApiUrl);
            var task = httpClient.PostAsync(url, new StringContent(JsonConvert.SerializeObject(message), System.Text.Encoding.UTF8, "application/json"));
            task.Wait();

            var response = task.Result;

            response.EnsureSuccessStatusCode();
        }
Ejemplo n.º 12
0
        public async Task WhenPostFromFile_AndPublishAsyncFaults_ThenReturnInternalServerError()
        {
            var request = new CreateJobFromFileRequest
            {
                FileName = Constants.ValidNSBDFileName
            };

            var job = new JobRequest { jobIdentifier = Guid.NewGuid().ToString() };

            ExpectJobRequestMapperToMap(job);
            ExpectExchangeToFaultOnPublish();

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

            Assert.AreEqual(HttpStatusCode.InternalServerError, result.StatusCode);
        }
Ejemplo n.º 13
0
        public void GiveCreateJobFromNIEIFileRequest_WhenMap_ThenUseDateTimeProvider()
        {
            var request = new CreateJobFromFileRequest
            {
                FileName = Constants.ValidNIEIFileName,
                JobSubject = "inwardimageexchange",
                JobPredicate = "inclearings",
                JobIdentifier = "NIEI-2cbabea0-43f9-4554-b118-c80c487d97c3"
            };

            var sut = CreateMapper();

            sut.Map(request);

            dateTimeProvider.Verify(x => x.CurrentTimeInAustralianEasternTimeZone());
        }