Ejemplo n.º 1
0
        public void Process_WhenFilesExistAndPositiveRecordsFound()
        {
            var fileRecords = new List <TouFile>()
            {
                new TouFile()
                {
                    Energy = 1.44M
                },
                new TouFile()
                {
                    Energy = 2.46M
                }
            };

            var options = Options.Create(new CsvSettings()
            {
                CsvFilePath = _testFilesPath
            });
            var fileName = CreateRandomFile(_testFilesPath, "TOU_");

            _touFileProcessor.Setup(p => p.GetAllRecords($"{_testFilesPath}\\{fileName}")).Returns(fileRecords);
            _touFileProcessor.Setup(p => p.CalculateMedian(fileRecords)).Returns(1.95M);

            using (var outFile = new FileUtility($"{_outputPath}\\outFile.txt"))
            {
                var csvFileService = new CsvFileService(_touFileProcessor.Object, _lpFileProcessor.Object, options);
                csvFileService.Process();
            }

            var lines = File.ReadAllLines($"{_outputPath}\\outFile.txt");

            Assert.Equal(2, lines.Length);
            Assert.True(lines[0].IndexOf("1.95") > 0);
        }
Ejemplo n.º 2
0
        public void Process_WhenFilesExistAndNoRecordsFound()
        {
            var fileRecords = new List <LpFile>()
            {
                new LpFile()
                {
                    Value = 1.5M
                },
                new LpFile()
                {
                    Value = 1.6M
                }
            };

            var options = Options.Create(new CsvSettings()
            {
                CsvFilePath = _testFilesPath
            });
            var fileName = CreateRandomFile(_testFilesPath, "LP_");

            _lpFileProcessor.Setup(p => p.GetAllRecords($"{_testFilesPath}\\{fileName}")).Returns(fileRecords);
            _lpFileProcessor.Setup(p => p.CalculateMedian(fileRecords)).Returns(1.55M);

            using (var outFile = new FileUtility($"{_outputPath}\\outFileSingleRecord.txt"))
            {
                var csvFileService = new CsvFileService(_touFileProcessor.Object, _lpFileProcessor.Object, options);
                csvFileService.Process();
            }

            var lines = File.ReadAllLines($"{_outputPath}\\outFileSingleRecord.txt");

            Assert.Empty(lines);
        }
Ejemplo n.º 3
0
        public void Process_WheninvalidFileThenNoRecordFound()
        {
            var options = Options.Create(new CsvSettings()
            {
                CsvFilePath = _testFilesPath
            });
            var fileName = CreateRandomFile(_testFilesPath, "PDS_");

            using (var outFile = new FileUtility($"{_outputPath}\\outFileNoRecord.txt"))
            {
                var csvFileService = new CsvFileService(_touFileProcessor.Object, _lpFileProcessor.Object, options);
                csvFileService.Process();
            }

            var lines = File.ReadAllLines($"{_outputPath}\\outFileNoRecord.txt");

            Assert.Empty(lines);
        }