コード例 #1
0
        public void ParseCsvFileTestReturnsNotHeadedModelForNotHeadedFile()
        {
            // Arrange
            var filePath = "InputData.csv";
            TestParserHelper parserHelper   = new TestParserHelper();
            TestFileHelper   tstHelper      = new TestFileHelper(filePath, parserHelper.notHeadedContent);
            CsvFileHandler   csvFileHandler = new CsvFileHandler(
                new ValidationService(), new FileService(tstHelper.config.Object),
                new ParsingService());

            // Expected result
            var expectedResult = new CsvHandleResult();

            expectedResult.Success          = true;
            expectedResult.ParsedCsvContent = parserHelper.expectedResultNoHeader;

            // Act
            var actualResult =
                csvFileHandler.ParseCsvFile(tstHelper.fileMock.Object, false);

            // Assert
            Assert.IsNotNull(actualResult);
            Assert.IsNotNull(actualResult.Result);
            Assert.AreEqual(expectedResult, actualResult.Result);
        }
コード例 #2
0
        public void ParseCsvTestReturnsModelForMissingFieldsFile()
        {
            // Arrange
            ParsingService parsingService = new ParsingService();
            var            filePath       = string.Format(
                @"{0}\TestFiles\InputDataMissingFields.csv",
                AppDomain.CurrentDomain.BaseDirectory);

            // Expected result
            TestParserHelper parserHelper   = new TestParserHelper();
            DataModel        expectedResult = parserHelper.missingFieldsExpectedResult;

            // Act
            DataModel actualResult = parsingService.ParseCsv(filePath, true);

            // Assert
            Assert.IsNotNull(actualResult);
            Assert.AreEqual(expectedResult, actualResult);
        }
コード例 #3
0
        public void PostTestReturnsHeadedModelForHeadedFile()
        {
            // Arrange
            var filePath = "InputData.csv";
            TestParserHelper parserHelper   = new TestParserHelper();
            TestFileHelper   tstHelper      = new TestFileHelper(filePath, parserHelper.headedContent);
            FilesController  fileController = new FilesController(tstHelper.config.Object,
                                                                  new CsvFileHandler(new ValidationService(),
                                                                                     new FileService(tstHelper.config.Object),
                                                                                     new ParsingService()));

            // Expected result
            var expectedCsvResult = new CsvHandleResult();

            expectedCsvResult.Success          = true;
            expectedCsvResult.ParsedCsvContent = parserHelper.headedExpectedResult;
            var expectedResult = new OkObjectResult(new
            {
                isHeadedFiles = true,
                resultList    = new List <CsvHandleResult>()
                {
                    expectedCsvResult
                }
            });

            // Act
            var actualResult =
                fileController.Post(new List <IFormFile>()
            {
                tstHelper.fileMock.Object
            }, true);

            // Assert
            Assert.IsNotNull(actualResult);
            Assert.IsNotNull(actualResult.Result);
            Assert.AreEqual(expectedResult.StatusCode,
                            ((OkObjectResult)actualResult.Result).StatusCode);
            Assert.AreEqual(expectedResult.Value.ToString(),
                            ((OkObjectResult)actualResult.Result).Value.ToString());
        }