public void Ensure_if_there_is_a_comma_inside_a_quote_we_ignore_it_and_do_not_Return_it()
        {
            var details = $@"31/12/2018,D/D,""'RandomShop,,,,, Payment"",-3.99,43703.30,'tony M,'001631-00541111,";
            var sut     = new CsvSplitterAndStripper();

            var result = sut.GetPartsOfLine(details);

            result.Count().ShouldBe(7);
            var collection = result as List <string> ?? result.ToList();

            collection[0].ShouldBe("31/12/2018");
            collection[1].ShouldBe("D/D");
            collection[2].ShouldBe("'RandomShop Payment");
            collection[3].ShouldBe("-3.99");
            collection[4].ShouldBe("43703.30");
            collection[5].ShouldBe("'tony M");
            collection[6].ShouldBe("'001631-00541111");
        }
        public void Ensure_we_split_lines_correctly()
        {
            var details = $@"31/12/2018,D/D,'RandomShop Payment,-3.99,43703.30,'tony M,'001631-00541111,";
            var sut     = new CsvSplitterAndStripper();

            var result = sut.GetPartsOfLine(details);

            result.Count().ShouldBe(7);
            var collection = result as List <string> ?? result.ToList();

            collection[0].ShouldBe("31/12/2018");
            collection[1].ShouldBe("D/D");
            collection[2].ShouldBe("'RandomShop Payment");
            collection[3].ShouldBe("-3.99");
            collection[4].ShouldBe("43703.30");
            collection[5].ShouldBe("'tony M");
            collection[6].ShouldBe("'001631-00541111");
        }
        public override IEnumerable <StandardBankOutputModel> Import(string path)
        {
            if (!FileWrapper.FileExists(path))
            {
                throw new ArgumentException("file path not found");
            }

            var lines = FileWrapper.ReadFile(path);

            if (lines == null || !lines.Any())
            {
                throw new InvalidDataException("file found but no data was found");
            }

            var enumerable = lines as string[] ?? lines.ToArray();
            var outputList = new List <NatwestBankImportModel>();

            // ReSharper disable once LoopCanBeConvertedToQuery
            foreach (var line in enumerable.Where(x => !x.Contains("Date, Type, Description,")))
            {
                var parts = CsvSplitterAndStripper.GetPartsOfLine(line);

                var collection = parts as string[] ?? parts.ToArray();
                var amount     = decimal.Parse(collection[3]);
                // try parse might be nice but if it fails would we want to continue and skip a row ??? that could be worse than just throwing a exception to discuss with client before implementing
                outputList.Add(new NatwestBankImportModel
                {
                    TransactionDate = DateTime.Parse(collection[0]),
                    Type            = collection[1],
                    Description     = collection[2].TrimStart('\''),
                    // remove ' at start is in here and not stripper as for natest  they add them to start of all descriptions specific to natwest so removed in the natwest implementation
                    TransactionAmount   = amount < 0 ? amount * -1 : amount,
                    TransactionIsCredit = amount >= 0,
                    Balance             = decimal.Parse(collection[4]),
                    AccountName         = collection[5],
                    AccountNumber       = collection[6],
                });
            }

            return(outputList);
        }