public void ReadFileTest()
        {
            var baseDir  = AppDomain.CurrentDomain.BaseDirectory;
            var filePath = Path.Combine(baseDir, "TestFiles", "CSVTestData.csv");

            var csvTestDataTextReader = new StreamReader(filePath);

            var data = CsvHelpers.ReadFile <FinancialTransaction>(csvTestDataTextReader, typeof(FinancialTransactionMapper));

            Assert.IsTrue(data?.Count > 0 && data?[0].Id == 123);
        }
        public List <FinancialTransaction> Calculate(Stream file, FileFormatEnum format)
        {
            List <FinancialTransaction> result = new List <FinancialTransaction>();

            try
            {
                using (var textReader = new StreamReader(file))
                {
                    switch (format)
                    {
                    case FileFormatEnum.XML:
                        result = XmlHelpers.ReadFile <Portfolio>(file)?.Trade;
                        break;

                    case FileFormatEnum.CSV:
                        result = CsvHelpers.ReadFile <FinancialTransaction>(textReader, typeof(FinancialTransactionMapper));
                        break;

                    default:
                        break;
                    }
                }

                using (var dbContext = new DatabaseContext())
                {
                    //Maybe save this list to cache is better solution - somthing like redis
                    var companies   = dbContext.Companies.Include(t => t.Currency).ToList();
                    var currentDate = Convert.ToDateTime(ConfigurationReader.ReadAppConfig("CurrentDate", "2016, 4, 1"));
                    Parallel.ForEach(result, (FinancialTransactionItem) =>
                    {
                        var company = companies.FirstOrDefault(t => t.Name == FinancialTransactionItem.Name.Trim());
                        if (company == null)
                        {
                            FinancialTransactionItem.Result = "Invalid Company Name";
                        }
                        else
                        {
                            var expireDate = Convert.ToDateTime(FinancialTransactionItem.ExpiryDate);

                            double yearOfExpiery = expireDate.YearsDiffrent(currentDate);
                            CallPutFlag callPutFlag;
                            if (!Enum.TryParse(FinancialTransactionItem.CallPutFlag, out callPutFlag))
                            {
                                FinancialTransactionItem.Result = "Invalid Data";
                            }
                            else
                            {
                                FinancialTransactionItem.Price  = _blackScholes.CalculateBlackScholes(callPutFlag, company.StockPrice, FinancialTransactionItem.StrikePrice, yearOfExpiery, company.Currency.RiskFreeRate, company.Volatility);
                                FinancialTransactionItem.Result = "Success";
                            }
                        }
                    });
                }
            }
            catch (Exception ex)
            {
                result = new List <FinancialTransaction>();
                log.Error($"Error occured in {this.GetType().FullName} - {MethodBase.GetCurrentMethod().Name}", ex);
            }

            return(result);
        }