public void ExtractESDATDataFromNoHeaderFileTest() { var mockDefaultValueProvider = new Mock <IWQDefaultValueProvider>(); mockDefaultValueProvider.Setup(x => x.OrganizationNameSampleCollection).Returns("Default organization name from provider"); var chemistryFileToImport = CreateCSVDataToImport(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DataFiles", "ChemistryFileExample.csv")); var sampleFileToImport = CreateCSVDataToImport(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DataFiles", "SampleFileExample.csv")); var testESDATDataToImport = new ESDATDataToImport(null, sampleFileToImport, chemistryFileToImport); var simpleValueAssginer = new SimpleValueAssigner(); var sampleDataImporter = ESDATTestHelper.BuildSampleDataFileImporter(); var sampleFileChildObjectExtractConfiguration = new SampleFileChildObjectExtractConfiguration(sampleDataImporter, "SampleFileData", simpleValueAssginer); var chemistryDataImporter = ESDATTestHelper.BuildChemistryFileImporter(); var chemistryFileChildObjectExtractConfiguration = new ChemistryFileChildObjectExtractConfiguration(chemistryDataImporter, "ChemistryData", simpleValueAssginer); var testESDATDataImporter = new ESDATDataImporter(ResultLevel.ERROR, mockDefaultValueProvider.Object); AddXMLExtractConfigurationsToImporter(testESDATDataImporter); testESDATDataImporter.AddExtractConfiguration(sampleFileChildObjectExtractConfiguration); testESDATDataImporter.AddExtractConfiguration(chemistryFileChildObjectExtractConfiguration); var extractResult = testESDATDataImporter.Extract <ESDATModel>(testESDATDataToImport); Assert.NotNull(extractResult); var entity = extractResult.ExtractedEntities.Cast <ESDATModel>().SingleOrDefault(); Assert.NotNull(entity); Assert.AreEqual("Default organization name from provider", entity.LabName); Assert.AreEqual(3, entity.SampleFileData.Count()); Assert.AreEqual(9, entity.ChemistryData.Count()); }
private ESDATModel extractEsdatModel() { var mockDefaultValueProvider = new Mock <IWQDefaultValueProvider>(); var headerFileToImport = ESDATTestHelper.CreateXMLDatoToImport(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DataFiles", "XMLSample.xml")); var chemistryFileToImport = ESDATTestHelper.CreateCSVDataToImport(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DataFiles", "ChemistryFileExample.csv")); var sampleFileToImport = ESDATTestHelper.CreateCSVDataToImport(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DataFiles", "SampleFileExample.csv")); var testESDATDataToImport = new ESDATDataToImport(headerFileToImport, sampleFileToImport, chemistryFileToImport); var simpleValueAssginer = new SimpleValueAssigner(); var sampleDataImporter = ESDATTestHelper.BuildSampleDataFileImporter(); var sampleFileChildObjectExtractConfiguration = new SampleFileChildObjectExtractConfiguration(sampleDataImporter, "SampleFileData", simpleValueAssginer); var chemistryDataImporter = ESDATTestHelper.BuildChemistryFileImporter(); var chemistryFileChildObjectExtractConfiguration = new ChemistryFileChildObjectExtractConfiguration(chemistryDataImporter, "ChemistryData", simpleValueAssginer); var testESDATDataImporter = new ESDATDataImporter(ResultLevel.ERROR, mockDefaultValueProvider.Object); ESDATTestHelper.AddXMLExtractConfigurationsToImporter(testESDATDataImporter); testESDATDataImporter.AddExtractConfiguration(sampleFileChildObjectExtractConfiguration); testESDATDataImporter.AddExtractConfiguration(chemistryFileChildObjectExtractConfiguration); var extractResult = testESDATDataImporter.Extract <ESDATModel>(testESDATDataToImport); return(extractResult.ExtractedEntities.First()); }
private IExtractConfiguration CreateSampleFileDataExtractConfiguration() { var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DataFiles", "SampleFileExample.csv"); var dataSource = new WindowsFileSystem(path); var dataFromFileSystem = dataSource.FetchData(); var dataToImport = new CSVDataToImport(dataFromFileSystem); var simpleValueAssginer = new SimpleValueAssigner(); var sampleDataImporter = ESDATTestHelper.BuildSampleDataFileImporter(); var childObjectExtractConfiguration = new SampleFileChildObjectExtractConfiguration(sampleDataImporter, "SampleFileData", simpleValueAssginer); return(childObjectExtractConfiguration); }
public static IDataImporter BuildESDATDataImporter(IWQDefaultValueProvider wqDefaultValueProvider) { var simpleValueAssginer = new SimpleValueAssigner(); var sampleDataImporter = BuildSampleDataFileImporter(); var sampleFileChildObjectExtractConfiguration = new SampleFileChildObjectExtractConfiguration(sampleDataImporter, "SampleFileData", simpleValueAssginer); var chemistryDataImporter = BuildChemistryFileImporter(); var chemistryFileChildObjectExtractConfiguration = new ChemistryFileChildObjectExtractConfiguration(chemistryDataImporter, "ChemistryData", simpleValueAssginer); var ESDATDataImporter = new ESDATDataImporter(ResultLevel.ERROR, wqDefaultValueProvider); AddXMLExtractConfigurationsToImporter(ESDATDataImporter); ESDATDataImporter.AddExtractConfiguration(sampleFileChildObjectExtractConfiguration); ESDATDataImporter.AddExtractConfiguration(chemistryFileChildObjectExtractConfiguration); return(ESDATDataImporter); }
public void ChemistryFilePropertyTest() { var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DataFiles", "SampleFileExample.csv"); var dataSource = new WindowsFileSystem(path); var dataFromFileSystem = dataSource.FetchData(); var dataToImport = new CSVDataToImport(dataFromFileSystem); var simpleValueAssginer = new SimpleValueAssigner(); var sampleDataImporter = ESDATTestHelper.BuildSampleDataFileImporter(); var childObjectExtractConfiguration = new SampleFileChildObjectExtractConfiguration(sampleDataImporter, "SampleFileData", simpleValueAssginer); Assert.AreEqual(typeof(SampleFileData), childObjectExtractConfiguration.ChildObjectType); var testESDATModel = new ESDATModel(); var extractResult = childObjectExtractConfiguration.ExtractData(testESDATModel, dataToImport); Assert.NotNull(extractResult); Assert.AreEqual(3, testESDATModel.SampleFileData.Count()); var firstSampleData = testESDATModel.SampleFileData.FirstOrDefault(); Assert.NotNull(firstSampleData); Assert.AreEqual("5828314", firstSampleData.SampleCode); Assert.AreEqual(new DateTime(2014, 9, 16), firstSampleData.SampledDateTime); Assert.AreEqual("FRL-1 @ 16:00", firstSampleData.FieldID); Assert.Null(firstSampleData.SampleDepth); Assert.AreEqual("Water", firstSampleData.MatrixType); Assert.AreEqual("Normal", firstSampleData.SampleType); Assert.AreEqual(string.Empty, firstSampleData.ParentSample); Assert.AreEqual("14J891101", firstSampleData.SDG); Assert.AreEqual("AGAT", firstSampleData.LabName); Assert.AreEqual("5828314", firstSampleData.LabSampleID); Assert.AreEqual(string.Empty, firstSampleData.Comments); Assert.AreEqual("14J891101", firstSampleData.LabReportNumber); }
public override IExtractedDataset <T> Extract <T>(IDataToImport dataToImport) { var extractedDataset = new ExtractedDataset <T>(_thresholdLevel); ChemistryFileChildObjectExtractConfiguration chemistryDataExtractConfiguration = null; SampleFileChildObjectExtractConfiguration sampleDataExtractConfiguration = null; var castedDataToImport = dataToImport as ESDATDataToImport; if (castedDataToImport == null) { extractedDataset.AddParsingResult(new BaseResult(ResultLevel.FATAL, "Data to Import needs to be ESDATDataToImport")); } try { chemistryDataExtractConfiguration = _extractConfigurations.Where(x => x is ChemistryFileChildObjectExtractConfiguration) .Cast <ChemistryFileChildObjectExtractConfiguration>() .SingleOrDefault(); } catch (Exception ex) { chemistryDataExtractConfiguration = null; extractedDataset.AddParsingResult(new BaseResult(ResultLevel.FATAL, "ESDAT data importer needs to have one and only one Chemistry file extract configuration")); } try { sampleDataExtractConfiguration = _extractConfigurations.Where(x => x is SampleFileChildObjectExtractConfiguration) .Cast <SampleFileChildObjectExtractConfiguration>() .SingleOrDefault(); } catch (Exception ex) { sampleDataExtractConfiguration = null; extractedDataset.AddParsingResult(new BaseResult(ResultLevel.FATAL, "ESDAT data importer needs to have one and only one Sample file extract configuration")); } var model = new T(); if (castedDataToImport.HeaderFileToImport == null) { var castedModel = model as ESDATModel; castedModel.LabName = _wqDefaultValueProvider.OrganizationNameSampleCollection; extractedDataset.AddParsingResults(new List <IResult> { new BaseResult(ResultLevel.WARN, "Header file is null, use the default organization name in the default value provider") }); } else { var headerFileExtractResults = ExtractHeaderFile(model, _extractConfigurations, castedDataToImport.HeaderFileToImport); extractedDataset.AddParsingResults(headerFileExtractResults); } if (chemistryDataExtractConfiguration != null && sampleDataExtractConfiguration != null) { var chemistryFileExtractResults = ExtractChemistryFileData(model, chemistryDataExtractConfiguration, castedDataToImport.ChemistryFileToImport); extractedDataset.AddParsingResults(chemistryFileExtractResults); var sampleFileExtractResults = ExtractSampleFileData(model, sampleDataExtractConfiguration, castedDataToImport.SampleFileToImport); extractedDataset.AddParsingResults(sampleFileExtractResults); } extractedDataset.AddParsingResults(new List <IResult> { new ParsingResult(ResultLevel.DEBUG, "Extract data into ESDAT model", model, null) }); return(extractedDataset); }
private IEnumerable <IResult> ExtractSampleFileData(object model, SampleFileChildObjectExtractConfiguration configuration, IDataToImport dataToImport) { var extractResults = configuration.ExtractData(model, dataToImport); return(extractResults); }
private ESDATModel extractEsdatModel() { var mockDefaultValueProvider = new Mock<IWQDefaultValueProvider>(); var headerFileToImport = ESDATTestHelper.CreateXMLDatoToImport(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DataFiles", "XMLSample.xml")); var chemistryFileToImport = ESDATTestHelper.CreateCSVDataToImport(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DataFiles", "ChemistryFileExample.csv")); var sampleFileToImport = ESDATTestHelper.CreateCSVDataToImport(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DataFiles", "SampleFileExample.csv")); var testESDATDataToImport = new ESDATDataToImport(headerFileToImport, sampleFileToImport, chemistryFileToImport); var simpleValueAssginer = new SimpleValueAssigner(); var sampleDataImporter = ESDATTestHelper.BuildSampleDataFileImporter(); var sampleFileChildObjectExtractConfiguration = new SampleFileChildObjectExtractConfiguration(sampleDataImporter, "SampleFileData", simpleValueAssginer); var chemistryDataImporter = ESDATTestHelper.BuildChemistryFileImporter(); var chemistryFileChildObjectExtractConfiguration = new ChemistryFileChildObjectExtractConfiguration(chemistryDataImporter, "ChemistryData", simpleValueAssginer); var testESDATDataImporter = new ESDATDataImporter(ResultLevel.ERROR, mockDefaultValueProvider.Object); ESDATTestHelper.AddXMLExtractConfigurationsToImporter(testESDATDataImporter); testESDATDataImporter.AddExtractConfiguration(sampleFileChildObjectExtractConfiguration); testESDATDataImporter.AddExtractConfiguration(chemistryFileChildObjectExtractConfiguration); var extractResult = testESDATDataImporter.Extract<ESDATModel>(testESDATDataToImport); return extractResult.ExtractedEntities.First(); }