public void TestToDTO() { var pnls = new List <string> { "2010-01-01,95045,501273,429834,-352913" }; var pnlsHeader = "Date,Strategy1,Strategy2,Strategy3,Strategy4"; var pnlMapper = new ProfitNLossMapper(); var pnlDTOs = pnlMapper.ToDTO(pnlsHeader, pnls); foreach (var profitNLossDto in pnlDTOs) { Assert.AreEqual("2010-01-01", profitNLossDto.Date.Date.ToString("yyyy-MM-dd")); } Assert.AreEqual(95045, pnlDTOs.First(x => x.Strategy == "Strategy1").Value); Assert.AreEqual(501273, pnlDTOs.First(x => x.Strategy == "Strategy2").Value); Assert.AreEqual(429834, pnlDTOs.First(x => x.Strategy == "Strategy3").Value); Assert.AreEqual(-352913, pnlDTOs.First(x => x.Strategy == "Strategy4").Value); }
public void LoadFiles(IHostingEnvironment env) { var dataLoader = new DataLoader(); var capitalPath = Path.Combine(env.ContentRootPath, "AppData", "capital.csv"); var capital = dataLoader.Load(capitalPath); var capitalMapper = new CapitalMapper(); var capitalDTOs = capitalMapper.ToDTO(capital[0], capital.Skip(1).ToList()); var pnlPath = Path.Combine(env.ContentRootPath, "AppData", "pnl.csv"); var pnls = dataLoader.Load(pnlPath); var pnlMapper = new ProfitNLossMapper(); var pnlDTOs = pnlMapper.ToDTO(pnls[0], pnls.Skip(1).ToList()); var propertiesth = Path.Combine(env.ContentRootPath, "AppData", "properties.csv"); var properties = dataLoader.Load(propertiesth); var propertiesMapper = new StrategyMapper(); var propertiesDTO = propertiesMapper.ToDTO(properties.Skip(1).ToList()); var uow = new UnitOfWork(); var strategiesRepo = uow.GetRepository <Strategy>(); var pnlRepo = uow.GetRepository <ProfitNLoss>(); var capitalRepo = uow.GetRepository <Capital>(); var count = strategiesRepo.GetQuery().Count(); if (count == 0) { List <Strategy> strategies; foreach (var property in propertiesDTO) { var strategy = new Strategy() { Region = property.Region, Name = property.Name }; strategiesRepo.Create(strategy); } uow.Commit(); strategies = strategiesRepo.GetQuery().ToList(); foreach (var capitalDTO in capitalDTOs) { var capitalEntity = new Capital(); capitalEntity.ID = Guid.NewGuid(); capitalEntity.Value = capitalDTO.Value; capitalEntity.Date = capitalDTO.Date; capitalEntity.Strategy = strategies.Where(x => x.Name == capitalDTO.Name).First(); capitalRepo.Create(capitalEntity); } foreach (var pnlDTO in pnlDTOs) { var capitalEntity = new ProfitNLoss(); capitalEntity.ID = Guid.NewGuid(); capitalEntity.Value = pnlDTO.Value; capitalEntity.Date = pnlDTO.Date; capitalEntity.Strategy = strategies.Where(x => x.Name == pnlDTO.Strategy).First(); pnlRepo.Create(capitalEntity); } uow.Commit(); } }