예제 #1
0
        public async Task PostAsyncTest_ReturnsBadRequest()
        {
            var postBatch = new PostBatch();

            controller.ModelState.AddModelError("MockError", "Model is invalid");

            var result = await controller.PostAsync(postBatch);

            var assert = Assert.IsType <BadRequestObjectResult>(result);
        }
예제 #2
0
        public async Task PostAsyncTest_ReturnsCreated()
        {
            var batch     = new BatchDTO();
            var postBatch = new PostBatch();

            _mapperMock.Setup(m => m.Map <PostBatch, BatchDTO>(postBatch))
            .Returns(batch);
            _serviceMock.Setup(s => s.AddAsync(batch))
            .Returns(Task.FromResult(batch));

            var result = await controller.PostAsync(postBatch);

            var assert = Assert.IsType <CreatedResult>(result);
        }
예제 #3
0
        public async Task <IActionResult> PostAsync([FromBody] PostBatch request)
        {
            var prefix = "[PostAsync]";

            _logger.LogInformation($"{prefix} Executing action");

            if (!ModelState.IsValid)
            {
                _logger.LogWarning($"{prefix} Invalid model");
                return(BadRequest(ModelState));
            }

            var entity   = _mapper.Map <PostBatch, BatchDTO>(request);
            var response = await _service.AddAsync(entity);

            _logger.LogInformation($"{prefix} Added batch with id {response.ID}");
            return(Created($"api/batches/{response.ID}", response));
        }
예제 #4
0
        public static void Main(string[] args)
        {
            _filePath = "";
#if DEBUG
            _filePath = "/Users/leealfarosoto/Downloads/Test.csv";
#else
            if (args.Length > 0)
            {
                _filePath = args[0];
            }
#endif
            _request = new PostBatch
            {
                AllowDuplicates  = false,
                ExcludeTransfers = true
            };

            ValidateFilePath();
            ReadCSV();
            WriteJSON();

            Console.WriteLine("Pres any key to exit...");
            Console.ReadKey();
        }