public void AddLargestNumber() { const string inputDir = @"d:\root\in"; const string inputFileName = @"myfile.csv"; var inputFilePath = Path.Combine(inputDir, inputFileName); const string outputDir = @"d:\root\out"; const string outputFileName = @"myfileout.csv"; var outputFilePath = Path.Combine(outputDir, outputFileName); var csvLines = new StringBuilder(); csvLines.AppendLine("OrderNumber,CustomerNumber,Description,Quantity"); csvLines.AppendLine("42, 100001, Shirt, II"); csvLines.AppendLine("43, 200002, Shorts, I"); csvLines.AppendLine("@ This is a comment"); csvLines.AppendLine(""); csvLines.AppendLine("44, 300003, Cap, V"); var mockFileInput = new MockFileData(csvLines.ToString()); var mockFileSystem = new MockFileSystem(); mockFileSystem.AddFile(inputFilePath, mockFileInput); mockFileSystem.AddDirectory(outputDir); var sut = new CsvFileProcessor(inputFilePath, outputFilePath, mockFileSystem); sut.Process(); Assert.True(mockFileSystem.FileExists(outputFilePath)); MockFileData processedFile = mockFileSystem.GetFile(outputFilePath); Approvals.Verify(processedFile.TextContents); }
public void OutputProcessedOrderCsvData() { const string inputDir = @"c:\root\in"; const string inputFileName = "myfile.csv"; var inputFilePath = Path.Combine(inputDir, inputFileName); const string outputDir = @"c:\root\out"; const string outputFileName = "myfileout.csv"; var outputFilePath = Path.Combine(outputDir, outputFileName); var csvLines = new StringBuilder(); csvLines.AppendLine("OrderNumber,CustomerNumber,Description,Quantity"); csvLines.AppendLine("42, 100001, Shirt, II"); csvLines.AppendLine("43, 200002, Shorts, I"); csvLines.AppendLine("@ This is a comment"); csvLines.AppendLine(""); csvLines.Append("44, 300003, Cap, V"); var mockInputFile = new MockFileData(csvLines.ToString()); var mockFileSystem = new MockFileSystem(); mockFileSystem.AddFile(inputFilePath, mockInputFile); mockFileSystem.AddDirectory(outputDir); var sut = new CsvFileProcessor(inputFilePath, outputFilePath, mockFileSystem); sut.Process(); Assert.True(mockFileSystem.FileExists(outputFilePath)); var processedFile = mockFileSystem.GetFile(outputFilePath); var lines = processedFile.TextContents.SplitLines(); //Assert.Equal("OrderNumber,Customer,Amount", lines[0]); //Assert.Equal("42,100001,2", lines[1]); //Assert.Equal("43,200002,1", lines[2]); //Assert.Equal("44,300003,5", lines[3]); Approvals.Verify(processedFile.TextContents); }
public void OutputProcessedPolicyXmlData() { // Create mock file system to test program const string inputDir = @"c:\root\in"; const string inputFileName = "myFile.csv"; string inputFilePath = Path.Combine(inputDir, inputFileName); const string outputDir = @"c:\root\out"; const string outputFileName = "myFileOut.xml"; string outputFilePath = Path.Combine(outputDir, outputFileName); // Create dummy test data to test program produces correct values StringBuilder csvLines = new StringBuilder(); csvLines.AppendLine("policy_number,policy_start_date,premiums,membership,discretionary_bonus,uplift_percentage"); csvLines.AppendLine("A100001,01/06/1986,10000,Y,1000,40"); csvLines.AppendLine("A100002,01/01/1990,12500,N,1350,37.5"); csvLines.AppendLine("A100003,31/12/1989,15250,N,1600,42"); csvLines.AppendLine("B100001,01/01/1995,12000,Y,2000,41"); csvLines.AppendLine("B100002,01/01/1970,18000,N,3000,43"); csvLines.AppendLine("B100003,20/07/1969,20000,Y,4000,45"); csvLines.AppendLine("C100001,01/01/1992,13000,N,1000,42"); csvLines.AppendLine("C100002,31/12/1989,15000,Y,2000,44"); csvLines.Append("C100003,01/01/1990,17000,Y,3000,46"); MockFileData mockInputFile = new MockFileData(csvLines.ToString()); MockFileSystem mockFileSystem = new MockFileSystem(); mockFileSystem.AddFile(inputFilePath, mockInputFile); mockFileSystem.AddDirectory(outputDir); CsvFileProcessor csvFileProcessor = new CsvFileProcessor(inputFilePath, outputFilePath, mockFileSystem); csvFileProcessor.Process(); Assert.True(mockFileSystem.FileExists(outputFilePath)); MockFileData processedFile = mockFileSystem.GetFile(outputFilePath); Approvals.Verify(processedFile.TextContents); }