public void ParseFileTest() { // Arrange var ordersFilePath = Path.Combine(TestContext.DeploymentDirectory, "FixedWidthOrders.csv"); using (var reader = new StreamReader(ordersFilePath)) { var fileParser = new PositionalValuesFileParser<SimpleOrder>(); // Act var parseResults = fileParser.Read(reader, includeHeaders: false); // Assert Assert.IsTrue(_orders.SequenceEqual(parseResults.Select(parseResult => parseResult.Instance))); } }
public void ParseFileWithErrorsTest() { // Arrange var ordersWithErrorsFilePath = Path.Combine(TestContext.DeploymentDirectory, "FixedWidthOrdersWithErrors.csv"); using (var reader = new StreamReader(ordersWithErrorsFilePath)) { var fileParser = new PositionalValuesFileParser<SimpleOrder>(); // Act var parseResults = fileParser.Read(reader, includeHeaders: false); // Assert var actualLinesWithError = default(int); var actualFieldsWithError = default(int); foreach (var parseResult in parseResults) { Assert.IsNull(parseResult.Instance); if (parseResult.Errors.Any()) { actualLinesWithError++; actualFieldsWithError += parseResult.Errors.Count(); } } // In the FixedWidthOrdersWithErrors.csv file created when the test class is initialized // There are three lines with errors so the logger must be called three times var expectedLinesWithErrors = 3; Assert.AreEqual<int>(expectedLinesWithErrors, actualLinesWithError); // And there must be eight errors in the fields being parsed var expectedErrorsInFields = 8; Assert.AreEqual<int>(expectedErrorsInFields, actualFieldsWithError); } }