public void Validate_Should_ReturnTrueWithoutErrorMessage_When_AllFieldsAreValid() { var fields = new[] { "Invoice0000001", "1,000.00", "USD", "20/02/2019 12:33:16", "Approved" }; var result = _validator.Validate(fields, out string error); Assert.IsTrue(result); Assert.AreEqual(string.Empty, error); }
public IList <TransactionItem> Read(Stream stream) { var result = new List <TransactionItem>(); var errorList = new List <string>(); using (TextFieldParser parser = new TextFieldParser(stream, Encoding.Default)) { parser.TextFieldType = FieldType.Delimited; parser.SetDelimiters(","); while (!parser.EndOfData) { var fields = parser.ReadFields(); if (fields.Length != 5) { throw new UnKnowFormatException(); } if (_validator.Validate(fields, out string error)) { result.Add(new TransactionItem { TransactionId = fields[0], Amount = decimal.Parse(fields[1]), CurrencyCode = fields[2], TransactionDate = DateTime.ParseExact(fields[3], "dd/MM/yyyy HH:mm:ss", CultureInfo.InvariantCulture), Status = StaticValue.CsvStatusList[fields[4]] }); } else { errorList.Add(error); } } } if (errorList.Any()) { var errorMessage = string.Join(Environment.NewLine, errorList); throw new TransactionValidateErrorException(errorMessage); } return(result); }