示例#1
0
        public ScenarioCampaignResultsFileProcessorTest()
        {
            _mockAuditEventRepository = new Mock <IAuditEventRepository>();
            _mockSalesAreaRepository  = new Mock <ISalesAreaRepository>();
            _context = new RunWithScenarioReference(Guid.NewGuid(), Guid.NewGuid());
            var dataSnapshot = new Mock <IOutputDataSnapshot>();

            int id = 1;

            _dummySalesArea = _fixture
                              .Build <SalesArea>()
                              .Do(s => s.CustomId = id++)
                              .CreateMany(5);

            _ = _mockSalesAreaRepository.Setup(m => m.GetAll()).Returns(_dummySalesArea);
            _ = dataSnapshot.Setup(x => x.AllSalesAreas)
                .Returns(new Lazy <IEnumerable <SalesArea> >(_mockSalesAreaRepository.Object.GetAll));

            var importSettings = CSVImportSettings.GetImportSettings(
                Path.Combine(TestRootDataFolder, "lmkii_scen_camp_reqm_summ.csv"),
                typeof(ScenarioCampaignResultHeaderMap),
                typeof(ScenarioCampaignResultIndexMap)
                );

            var scenarioCampaignResultsImportRepository = new CSVScenarioCampaignResultsImportRepository(importSettings);

            _expectedItems = scenarioCampaignResultsImportRepository.GetAll();

            _processor = new ScenarioCampaignResultsFileProcessor(dataSnapshot.Object, _mockAuditEventRepository.Object);
        }
        public ScenarioCampaignResult ProcessFile(Guid scenarioId, string folder)
        {
            string pathToFile = FileHelpers.GetPathToFileIfExists(folder, FileName);
            var    result     = new ScenarioCampaignResult {
                Id = scenarioId
            };

            if (string.IsNullOrEmpty(pathToFile))
            {
                _audit.Insert(AuditEventFactory.CreateAuditEventForWarningMessage(0, 0, $"File {pathToFile} was not found."));

                return(result);
            }

            _audit.Insert(AuditEventFactory.CreateAuditEventForInformationMessage(0,
                                                                                  0, $"Processing output file {pathToFile}"));

            var importSettings = CSVImportSettings.GetImportSettings(pathToFile, typeof(ScenarioCampaignResultHeaderMap), typeof(ScenarioCampaignResultIndexMap));
            IScenarioCampaignResultsImportRepository repository = new CSVScenarioCampaignResultsImportRepository(importSettings);

            var data = repository.GetAll();

            var salesAreaIndex = _dataSnapshot.AllSalesAreas.Value.ToDictionary(c => c.CustomId);

            foreach (var importItem in data)
            {
                salesAreaIndex.TryGetValue(importItem.SalesAreaNo, out var salesArea);

                result.Items.Add(MapImportItem(importItem, salesArea));
            }

            _audit.Insert(AuditEventFactory.CreateAuditEventForInformationMessage(0,
                                                                                  0, $"Processed output file {pathToFile}"));

            return(result);
        }