public void ScaffoldTest()
        {
            var esdatModel = new ESDATModel();

            var mockDb = new Mock<IDbContext>();
            var mockDbContext = mockDb.Object;
            var duplicateChecker = new ODM2DuplicateChecker(mockDbContext);
            var defaultValueProvider = new StaticWQDefaultValueProvider();
            var wayToHandleNewData = WayToHandleNewData.ThrowExceptionForNewData;
            var results = new List<IResult>();
            var mapper = new RelatedActionMapper(duplicateChecker, defaultValueProvider, wayToHandleNewData, results);

            var action1 = new Core.Action();
            action1.ActionID = 101;

            var action2 = new Core.Action();
            action2.ActionID = 102;

            mapper.SetRelationship(action1, "relationshipTypeCV", action2);

            var relatedAction = mapper.Draft(esdatModel);

            Assert.AreEqual(action1.ActionID, relatedAction.ActionID);
            Assert.AreEqual("relationshipTypeCV", relatedAction.RelationshipTypeCV);
            Assert.AreEqual(action2.ActionID, relatedAction.RelatedActionID);
            Assert.AreEqual(action1, relatedAction.Action);
            Assert.AreEqual(action2, relatedAction.Action1);
        }
        public static void Main(string[] args)
        {
            var dbContext = new ODM2Entities();

            var relationActionTypeRepository = new Repository<CV_RelationshipType>(dbContext);
            var wqDataRepository = new WQDataRepository(dbContext);

            var staticWQDefaultValueProvider = new StaticWQDefaultValueProvider();
            staticWQDefaultValueProvider.Init();

            Console.WriteLine("Start Quality Checking Process...");

            var qcChainConfiguration = ConfigureQualityCheckingChain(true, wqDataRepository, "Test", false, "Water");

            var versioningHelper = new DataVersioningHelper(staticWQDefaultValueProvider);
            var factory = new DataQualityCheckingToolFactory(versioningHelper, relationActionTypeRepository);
            var qualiltyChecker = new WaterQualityDataQualityChecker(qcChainConfiguration, factory, wqDataRepository);

            var qcResults = qualiltyChecker.Check();

            foreach(var result in qcResults)
            {
                Console.WriteLine(string.Format("{0}: {1}", result.Level, result.Message));
            
            }

            Console.WriteLine("Press any keys to continue...");
            Console.ReadLine();
        }
        public void ScaffoldTest()
        {
            var chemistry = new ChemistryFileData();
            chemistry.OriginalChemName = "XYZ";

            var esdatModel = new ESDATModel();
            var sample = new SampleFileData();
            var mockDb = new Mock<IDbContext>();
            var mockDbContext = mockDb.Object;
            var duplicateChecker = new ODM2DuplicateChecker(mockDbContext);
            var defaultValueProvider = new StaticWQDefaultValueProvider();
            var wayToHandleNewData = WayToHandleNewData.ThrowExceptionForNewData;
            var results = new List<IResult>();
            var mapper = new ChemistryVariableMapper(duplicateChecker, defaultValueProvider, wayToHandleNewData, results);

            var variable = mapper.Draft(esdatModel, chemistry);            

            Assert.AreEqual(defaultValueProvider.DefaultVariableTypeCVChemistry, variable.VariableTypeCV);
            Assert.AreEqual(chemistry.ChemCode, variable.VariableCode);

            // This is temporarily hard-coded
            Assert.AreEqual("1,1,1-Trichloroethane", variable.VariableNameCV);

            Assert.AreEqual(chemistry.OriginalChemName, variable.VariableDefinition);
            Assert.AreEqual(defaultValueProvider.DefaultVariableSpeciationCV, variable.SpeciationCV);
            Assert.AreEqual(defaultValueProvider.DefaultVariableNoDataValue, variable.NoDataValue);
        }
        public void Scaffold()
        {
            var esdatModel = new ESDATModel();

            var mockDb = new Mock<IDbContext>();
            var mockDbContext = mockDb.Object;
            var duplicateChecker = new ODM2DuplicateChecker(mockDbContext);
            var defaultValueProvider = new StaticWQDefaultValueProvider();
            var wayToHandleNewData = WayToHandleNewData.ThrowExceptionForNewData;
            var results = new List<IResult>();
            var mapper = new ProcessingLevelMapper(duplicateChecker, defaultValueProvider, wayToHandleNewData, results);

            var processingLevel = mapper.Draft(esdatModel);

            Assert.AreEqual(defaultValueProvider.DefaultProcessingLevelCode, processingLevel.ProcessingLevelCode);
        }
        public void ScaffoldTest()
        {
            var esdatModel = new ESDATModel();

            var mockDb = new Mock<IDbContext>();
            var mockDbContext = mockDb.Object;
            var duplicateChecker = new ODM2DuplicateChecker(mockDbContext);
            var defaultValueProvider = new StaticWQDefaultValueProvider();
            var wayToHandleNewData = WayToHandleNewData.ThrowExceptionForNewData;
            var results = new List<IResult>();
            var mapper = new SampleCollectionSamplingFeatureMapper(duplicateChecker, defaultValueProvider, wayToHandleNewData, results);

            var samplingFeature = mapper.Draft(esdatModel);

            Assert.AreEqual(defaultValueProvider.DefaultSamplingFeatureTypeCVSampleCollection, samplingFeature.SamplingFeatureTypeCV);
            Assert.AreEqual(defaultValueProvider.DefaultSamplingFeatureCode, samplingFeature.SamplingFeatureCode);
            Assert.AreEqual(new Guid(), samplingFeature.SamplingFeatureUUID);
        }
        public void ScaffoldTest()
        {
            var esdatModel = new ESDATModel();

            var mockDb = new Mock<IDbContext>();
            var mockDbContext = mockDb.Object;
            var duplicateChecker = new ODM2DuplicateChecker(mockDbContext);
            var defaultValueProvider = new StaticWQDefaultValueProvider();
            var wayToHandleNewData = WayToHandleNewData.ThrowExceptionForNewData;
            var results = new List<IResult>();
            var mapper = new SampleCollectionUnitMapper(duplicateChecker, defaultValueProvider, wayToHandleNewData, results);

            var unit = mapper.Draft(esdatModel);

            Assert.AreEqual(defaultValueProvider.DefaultUnitsTypeCVSampleCollection, unit.UnitsTypeCV);
            Assert.AreEqual(mapper.AbbereviateUnit(defaultValueProvider.DefaultUnitsTypeCVSampleCollection), unit.UnitsAbbreviation);
            Assert.AreEqual(defaultValueProvider.DefaultUnitsTypeCVSampleCollection, unit.UnitsName);
        }
        public void ScaffoldTest()
        {
            var esdatModel = new ESDATModel();

            var mockDb = new Mock<IDbContext>();
            var mockDbContext = mockDb.Object;
            var duplicateChecker = new ODM2DuplicateChecker(mockDbContext);
            var defaultValueProvider = new StaticWQDefaultValueProvider();
            var wayToHandleNewData = WayToHandleNewData.ThrowExceptionForNewData;
            var results = new List<IResult>();
            var mapper = new SampleCollectionMethodMapper(duplicateChecker, defaultValueProvider, wayToHandleNewData, results);

            var method = mapper.Draft(esdatModel);

            Assert.AreEqual(defaultValueProvider.DefaultMethodTypeCVSampleCollection, method.MethodTypeCV);
            Assert.AreEqual(string.Empty, method.MethodCode);
            Assert.AreEqual(defaultValueProvider.DefaultMethodTypeCVSampleCollection, method.MethodName);
        }
        public void ScaffoldChemistryTest()
        {
            var esdatModel = new ESDATModel();

            var mockDb = new Mock<IDbContext>();
            var mockDbContext = mockDb.Object;
            var duplicateChecker = new ODM2DuplicateChecker(mockDbContext);
            var defaultValueProvider = new StaticWQDefaultValueProvider();
            var wayToHandleNewData = WayToHandleNewData.ThrowExceptionForNewData;
            var results = new List<IResult>();
            var mapper = new DatasetsResultMapper(duplicateChecker, defaultValueProvider, wayToHandleNewData, results);

            var datasetsResult = mapper.Draft(esdatModel);

            Assert.AreEqual(0, datasetsResult.BridgeID);
            Assert.AreEqual(0, datasetsResult.DatasetID);
            Assert.AreEqual(0, datasetsResult.ResultID);
        }
        public void Scaffold()
        {
            var esdatModel = new ESDATModel();

            var mockDb = new Mock<IDbContext>();
            var mockDbContext = mockDb.Object;
            var duplicateChecker = new ODM2DuplicateChecker(mockDbContext);
            var defaultValueProvider = new StaticWQDefaultValueProvider();
            var wayToHandleNewData = WayToHandleNewData.ThrowExceptionForNewData;
            var results = new List<IResult>();
            var mapper = new PersonMapper(duplicateChecker, defaultValueProvider, wayToHandleNewData, results);

            var affiliation = new Affiliation();
            var person = mapper.Draft(esdatModel);

            Assert.AreEqual(defaultValueProvider.DefaultPersonFirstName, person.PersonFirstName);
            Assert.AreEqual(defaultValueProvider.DefaultPersonMiddleName, person.PersonMiddleName);
            Assert.AreEqual(defaultValueProvider.DefaultPersonLastName, person.PersonLastName);
        }
        public void ScaffoldTest()
        {
            var esdatModel = new ESDATModel();

            var mockDb = new Mock<IDbContext>();
            var mockDbContext = mockDb.Object;
            var duplicateChecker = new ODM2DuplicateChecker(mockDbContext);
            var defaultValueProvider = new StaticWQDefaultValueProvider();
            var wayToHandleNewData = WayToHandleNewData.ThrowExceptionForNewData;
            var results = new List<IResult>();
            var mapper = new ActionByMapper(duplicateChecker, defaultValueProvider, wayToHandleNewData, results);

            var action = new Core.Action();
            action.ActionID = 101;

            var actionBy = mapper.Draft(esdatModel);

            Assert.AreEqual(true, actionBy.IsActionLead);
        }
        public void ScaffoldTest()
        {
            var esdatModel = new ESDATModel();
            esdatModel.DateReported = DateTime.Now;

            var mockDb = new Mock<IDbContext>();
            var mockDbContext = mockDb.Object;
            var duplicateChecker = new ODM2DuplicateChecker(mockDbContext);
            var defaultValueProvider = new StaticWQDefaultValueProvider();
            var wayToHandleNewData = WayToHandleNewData.ThrowExceptionForNewData;
            var results = new List<IResult>();
            var SampleCollectionFactory = new ESDATSampleCollectionMapperFactory(duplicateChecker, defaultValueProvider, wayToHandleNewData, results);
            var chemistryFactory = new ESDATChemistryMapperFactory(duplicateChecker, defaultValueProvider, wayToHandleNewData, results);
            var mapper = new SampleCollectionActionMapper(duplicateChecker, SampleCollectionFactory, defaultValueProvider, chemistryFactory, wayToHandleNewData, results);

            var action = mapper.Draft(esdatModel);

            Assert.AreEqual(defaultValueProvider.ActionTypeCVSampleCollection, action.ActionTypeCV);
            Assert.AreEqual(esdatModel.DateReported, action.BeginDateTime);
        }
        //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();
        }
        public void ScaffoldTest()
        {
            var chemistry = new ChemistryFileData();

            var esdatModel = new ESDATModel();
            var sample = new SampleFileData();
            var mockDb = new Mock<IDbContext>();
            var mockDbContext = mockDb.Object;
            var duplicateChecker = new ODM2DuplicateChecker(mockDbContext);
            var defaultValueProvider = new StaticWQDefaultValueProvider();
            var wayToHandleNewData = WayToHandleNewData.ThrowExceptionForNewData;
            var results = new List<IResult>();
            var mapper = new ChemistryMeasurementResultMapper(duplicateChecker, defaultValueProvider, wayToHandleNewData, results);

            var measurementResult = mapper.Draft(esdatModel, chemistry);

            Assert.AreEqual(defaultValueProvider.MeasurementResultCensorCodeCVChemistry, measurementResult.CensorCodeCV);
            Assert.AreEqual(defaultValueProvider.MeasurementResultQualityCodeCVChemistry, measurementResult.QualityCodeCV);
            Assert.AreEqual(defaultValueProvider.MeasurementResultAggregationStatisticCVChemistry, measurementResult.AggregationStatisticCV);
        }
        public void ScaffoldTest()
        {
            var chemistry = new ChemistryFileData();

            var esdatModel = new ESDATModel();
            var sample = new SampleFileData();
            var mockDb = new Mock<IDbContext>();
            var mockDbContext = mockDb.Object;
            var duplicateChecker = new ODM2DuplicateChecker(mockDbContext);
            var defaultValueProvider = new StaticWQDefaultValueProvider();
            var wayToHandleNewData = WayToHandleNewData.ThrowExceptionForNewData;
            var results = new List<IResult>();
            var mapper = new ChemistryFeatureActionMapper(duplicateChecker, defaultValueProvider, wayToHandleNewData, results);

            var featureAction = mapper.Draft(esdatModel, chemistry);

            Assert.AreEqual(0, featureAction.FeatureActionID);
            Assert.AreEqual(0, featureAction.SamplingFeatureID);
            Assert.AreEqual(0, featureAction.ActionID);
        }
        public void ScaffoldTest()
        {
            var esdatModel = new ESDATModel();

            var mockDb = new Mock<IDbContext>();
            var mockDbContext = mockDb.Object;
            var duplicateChecker = new ODM2DuplicateChecker(mockDbContext);
            var defaultValueProvider = new StaticWQDefaultValueProvider();
            var wayToHandleNewData = WayToHandleNewData.ThrowExceptionForNewData;
            var results = new List<IResult>();
            var mapper = new DatasetMapper(duplicateChecker, defaultValueProvider, wayToHandleNewData, results);

            var datasetsResult = new DatasetsResult();
            var dataSet = mapper.Draft(esdatModel);

            Assert.AreEqual(defaultValueProvider.DefaultDatasetTypeCV, dataSet.DatasetTypeCV);
            Assert.AreEqual(esdatModel.LabRequestId.ToString(), dataSet.DatasetCode);
            Assert.AreEqual(String.Format("{0}: {1} ({2})", esdatModel.LabName, esdatModel.LabRequestId.ToString(), esdatModel.DateReported), dataSet.DatasetTitle);
            Assert.AreEqual(string.Empty, dataSet.DatasetAbstract);
        }
        public void ScaffoldTest()
        {
            var chemistry = new ChemistryFileData();
            chemistry.Result = 101;
            chemistry.AnalysedDate = DateTime.Now;

            var esdatModel = new ESDATModel();
            var sample = new SampleFileData();
            var mockDb = new Mock<IDbContext>();
            var mockDbContext = mockDb.Object;
            var duplicateChecker = new ODM2DuplicateChecker(mockDbContext);
            var defaultValueProvider = new StaticWQDefaultValueProvider();
            var wayToHandleNewData = WayToHandleNewData.ThrowExceptionForNewData;
            var results = new List<IResult>();
            var mapper = new ChemistryMeasurementResultValueMapper(duplicateChecker, defaultValueProvider, wayToHandleNewData, results);

            var measurementResultValue = mapper.Draft(esdatModel, chemistry);

            Assert.AreEqual(chemistry.Result, measurementResultValue.DataValue);
            Assert.AreEqual(chemistry.AnalysedDate, measurementResultValue.ValueDateTime);
        }
        public void ScaffoldTest()
        {
            var chemistry = new ChemistryFileData();

            var esdatModel = new ESDATModel();
            var sample = new SampleFileData();
            var mockDb = new Mock<IDbContext>();
            var mockDbContext = mockDb.Object;
            var duplicateChecker = new ODM2DuplicateChecker(mockDbContext);
            var defaultValueProvider = new StaticWQDefaultValueProvider();
            var wayToHandleNewData = WayToHandleNewData.ThrowExceptionForNewData;
            var results = new List<IResult>();
            var mapper = new ChemistryResultMapper(duplicateChecker, defaultValueProvider, wayToHandleNewData, results);

            var result = mapper.Draft(esdatModel, chemistry);

            Assert.AreEqual(defaultValueProvider.ResultTypeCVChemistry, result.ResultTypeCV);
            Assert.AreEqual(chemistry.AnalysedDate, result.ResultDateTime);
            Assert.AreEqual(defaultValueProvider.ResultSampledMediumCVChemistry, result.SampledMediumCV);
            Assert.AreEqual(1, result.ValueCount);
        }
        public void ScaffoldTest()
        {
            var chemistry = new ChemistryFileData();
            chemistry.AnalysedDate = DateTime.Now;

            var esdatModel = new ESDATModel();
            var mockDb = new Mock<IDbContext>();
            var mockDbContext = mockDb.Object;
            var duplicateChecker = new ODM2DuplicateChecker(mockDbContext);
            var defaultValueProvider = new StaticWQDefaultValueProvider();
            var wayToHandleNewData = WayToHandleNewData.ThrowExceptionForNewData;
            var results = new List<IResult>();
            var factory = new ESDATChemistryMapperFactory(duplicateChecker, defaultValueProvider, wayToHandleNewData, results);
            var mapper = new ChemistryActionMapper(duplicateChecker, factory, defaultValueProvider, wayToHandleNewData, results);

            var action = mapper.Draft(esdatModel, chemistry);

            Assert.AreEqual(defaultValueProvider.ActionTypeCVChemistry, action.ActionTypeCV);
            Assert.AreEqual(chemistry.ExtractionDate, action.BeginDateTime);
            Assert.AreEqual(chemistry.AnalysedDate, action.EndDateTime);
        }
        //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));
        }
        public void Scaffold()
        {
            var esdatModel = new ESDATModel();

            var labName = "XYZ Labs";
            var sample = new SampleFileData();
            sample.LabName = labName;

            var chemistry = new ChemistryFileData();

            var mockDb = new Mock<IDbContext>();
            var mockDbContext = mockDb.Object;
            var duplicateChecker = new ODM2DuplicateChecker(mockDbContext);
            var defaultValueProvider = new StaticWQDefaultValueProvider();
            var wayToHandleNewData = WayToHandleNewData.ThrowExceptionForNewData;
            var results = new List<IResult>();
            var mapper = new SampleCollectionOrganizationMapper(duplicateChecker, defaultValueProvider, wayToHandleNewData, results);

            var organization = mapper.Draft(esdatModel);

            Assert.AreEqual(defaultValueProvider.OrganizationTypeCVSampleCollection, organization.OrganizationTypeCV);
            Assert.AreEqual(mapper.GetOrganizationCode(defaultValueProvider.OrganizationNameSampleCollection), organization.OrganizationCode);
            Assert.AreEqual(defaultValueProvider.OrganizationNameSampleCollection, organization.OrganizationName);
        }