示例#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));
            }
        }
示例#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));
        }
示例#3
0
        public void GivenNoSubject_WhenValidate_ThenFail()
        {
            var request = new CreateJobFromFileRequest
            {
                FileName     = Constants.ValidNSBDFileName,
                JobPredicate = "test",
                JobSubject   = null
            };

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

            Assert.IsFalse(result);
        }
示例#4
0
        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);
        }
示例#5
0
        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);
        }
示例#6
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());
        }
示例#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());
        }
示例#8
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);
        }
示例#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);
        }
示例#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);
        }
示例#11
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);
        }
示例#12
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>()));
        }
示例#13
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();
        }