//Commment this out so auto-build would not run this unit test //[Test] public void DBTest() { var dbContext = new ODM2Entities(); var duplicateChecker = new ODM2DuplicateChecker(dbContext); var esdatModel = extractEsdatModel(); var WQDefaultValueProvider = new StaticWQDefaultValueProvider(); var wayToHandleNewData = WayToHandleNewData.CreateInstanceForNewData; var results = new List <IResult>(); var sampleCollectionFactory = new ESDATSampleCollectionMapperFactory(duplicateChecker, WQDefaultValueProvider, wayToHandleNewData, results); var chemistryFactory = new ESDATChemistryMapperFactory(duplicateChecker, WQDefaultValueProvider, wayToHandleNewData, results); var mapper = new SampleCollectionActionMapper(duplicateChecker, sampleCollectionFactory, WQDefaultValueProvider, chemistryFactory, wayToHandleNewData, results); var converter = new ESDATConverter(mapper); var action = converter.Map(esdatModel); dbContext.Add(action); dbContext.SaveChanges(); }
//Commment this out so auto-build would not run this unit test //[Test] //[TestCase(WayToHandleNewData.CreateInstanceForNewData)] //[TestCase(WayToHandleNewData.WarningForNewData)] public void ResultsTest(WayToHandleNewData wayToHandleNewData) { var dbContext = new Mock <IDbContext>().Object; var duplicateChecker = new ODM2DuplicateChecker(dbContext); var esdatModel = extractEsdatModel(); var WQDefaultValueProvider = new StaticWQDefaultValueProvider(); var results = new List <IResult>(); var sampleCollectionFactory = new ESDATSampleCollectionMapperFactory(duplicateChecker, WQDefaultValueProvider, wayToHandleNewData, results); var chemistryFactory = new ESDATChemistryMapperFactory(duplicateChecker, WQDefaultValueProvider, wayToHandleNewData, results); var mapper = new SampleCollectionActionMapper(duplicateChecker, sampleCollectionFactory, WQDefaultValueProvider, chemistryFactory, wayToHandleNewData, results); var converter = new ESDATConverter(mapper); var resultsList = converter.Convert(esdatModel); var errorCount = 0; var warningCount = 0; foreach (IResult result in resultsList) { Console.WriteLine(result.Level + ": " + result.Message); if (result.Level.Equals(ResultLevel.ERROR) || result.Level.Equals(ResultLevel.FATAL)) { errorCount++; } else if (result.Level.Equals(ResultLevel.WARN)) { warningCount++; } } Console.WriteLine(String.Format("{0} error(s), and {1} warning(s) found.", errorCount, warningCount)); Assert.AreEqual(0, errorCount, String.Format("{0} error(s) found.", errorCount)); Assert.AreEqual(0, warningCount, String.Format("{0} warning(s) found", warningCount)); }
private IEnumerable <ResultMessageViewModel> PersistESDATData(ESDATDataToImport esdatDataToImport, IDataImporter importer) { var extractedResults = importer.Extract <ESDATModel>(esdatDataToImport); if (!extractedResults.IsExtractedSuccess) { var failResults = from parsingResult in ImportResultHelper.FilterWarningAndErrorResult(extractedResults.AllParsingResults) select new ResultMessageViewModel ( parsingResult.Level.ToString(), parsingResult.Message ); return(failResults); } else { var esdatModel = extractedResults.ExtractedEntities.First(); var allResults = (from parsingResult in extractedResults.AllParsingResults select new ResultMessageViewModel(parsingResult.Level.ToString(), parsingResult.Message)).ToList(); var duplicateChecker = new ODM2DuplicateChecker(_dbContext); var convertResult = new List <IResult>(); var sampleCollectionFactory = new ESDATSampleCollectionMapperFactory(duplicateChecker, _wqDefaultValueProvider, wayToHandleNewData, convertResult); var chemistryFactory = new ESDATChemistryMapperFactory(duplicateChecker, _wqDefaultValueProvider, wayToHandleNewData, convertResult); var mapper = new SampleCollectionActionMapper(duplicateChecker, sampleCollectionFactory, _wqDefaultValueProvider, chemistryFactory, wayToHandleNewData, convertResult); var converter = new ESDATConverter(mapper); var convertResults = converter.Convert(esdatModel); var convertResultViewModels = from converResult in convertResults select new ResultMessageViewModel(converResult.Level.ToString(), converResult.Message); allResults.AddRange(convertResultViewModels.ToList()); var convertParsingResult = convertResults.Where(x => x is IParsingResult).FirstOrDefault(); if (convertParsingResult == null) { var failResult = new ResultMessageViewModel(ResultMessageViewModel.RESULT_LEVEL_ERROR, "System is not able to find the converted value from the converted results."); allResults.Add(failResult); } else { var action = (Action)((IParsingResult)convertParsingResult).Value; _dbContext.Add <Hatfield.EnviroData.Core.Action>(action); _dbContext.SaveChanges(); allResults.Add(new ResultMessageViewModel ( ResultMessageViewModel.RESULT_LEVEL_INFO, "Import success" )); } return(allResults); } }