Example #1
0
        public async Task Correct_success_returned()
        {
            _mediator
            .Send(Arg.Any <ParseMeterReadingCsvFileRequest>(), Arg.Any <CancellationToken>())
            .Returns(new ParseCsvFileResult <MeterReadingDto> {
                Errors = new System.Collections.Generic.List <CsvRowError> {
                    new CsvRowError(),
                    new CsvRowError(),
                    new CsvRowError(),
                    new CsvRowError(),
                    new CsvRowError(),
                },
                ValidRows = new System.Collections.Generic.List <MeterReadingDto>
                {
                    new MeterReadingDto(),
                    new MeterReadingDto(),
                    new MeterReadingDto(),
                    new MeterReadingDto(),
                    new MeterReadingDto(),
                    new MeterReadingDto(),
                    new MeterReadingDto(),
                    new MeterReadingDto(),
                    new MeterReadingDto(),
                    new MeterReadingDto()
                }
            });

            _mediator
            .Send(Arg.Any <StoreMeterReadingRecordsRequest>(), Arg.Any <CancellationToken>())
            .Returns(1);

            var response = await _subject.Post(FormFileFactory.Get("test", 300, "big.csv", "text/csv"));

            Assert.AreEqual(9, response.Value.SuccessfulRows);
        }
Example #2
0
        public async Task Malformed_file_error_returns_message()
        {
            _mediator
            .Send(Arg.Any <ParseMeterReadingCsvFileRequest>(), Arg.Any <CancellationToken>())
            .Returns <Task <ParseCsvFileResult <MeterReadingDto> > >(x => { throw new MalformedFileException("error message"); });

            var response = await _subject.Post(FormFileFactory.Get("test", 300, "big.csv", "text/csv"));

            Assert.AreEqual("error message", ((ObjectResult)response.Result).Value.ToString());
        }
Example #3
0
        public async Task Wrong_format_file_returns_message()
        {
            var response = await _subject.Post(FormFileFactory.Get("test", 300, "big.csv", "text/plain"));

            Assert.AreEqual("File must be in CSV format", ((ObjectResult)response.Result).Value.ToString());
        }
Example #4
0
        public async Task Wrong_format_file_returns_400()
        {
            var response = await _subject.Post(FormFileFactory.Get("test", 300, "big.csv", "text/plain"));

            Assert.AreEqual(400, ((ObjectResult)response.Result).StatusCode);
        }
Example #5
0
        public async Task Too_large_file_returns_message()
        {
            var response = await _subject.Post(FormFileFactory.Get("test", 2000000, "big.csv", "text/csv"));

            Assert.AreEqual("File larger than max size of 1048576 bytes", ((ObjectResult)response.Result).Value.ToString());
        }
Example #6
0
        public async Task Too_large_file_returns_400()
        {
            var response = await _subject.Post(FormFileFactory.Get("test", 2000000, "big.csv", "text/csv"));

            Assert.AreEqual(400, ((ObjectResult)response.Result).StatusCode);
        }