public void Setup()
        {
            var measurementResultValue = new MeasurementResultValue();
            measurementResultValue.DataValue = MeasurementValue;
            var measurementResult = new MeasurementResult();
            measurementResult.MeasurementResultValues.Add(measurementResultValue);
            var result = new Result();
            result.ResultDateTime = DateTime.Today;
            result.MeasurementResult = measurementResult;
            var samplingFeature = new SamplingFeature();
            samplingFeature.SamplingFeatureTypeCV = "Specimen";
            var featureAction = new FeatureAction();
            featureAction.SamplingFeature = samplingFeature;
            featureAction.Results.Add(result);
            var action = new Core.Action();
            action.ActionID = ActionId;
            action.FeatureActions.Add(featureAction);
            var actions = new List<Core.Action>();
            actions.Add(action);
            supportedData = actions;

            var mockVersionHelper = new Mock<IDataVersioningHelper>();
            mockVersionHelper.Setup(x => x.GetLatestVersionActionData(It.IsAny<Hatfield.EnviroData.Core.Action>())).Returns(action);
            mockVersionHelper.Setup(x => x.CloneActionData(It.IsAny<Hatfield.EnviroData.Core.Action>())).Returns(cloneAction(action));

            var mockRepository = new Mock<IRepository<CV_RelationshipType>>();
            testTool = new ChemistryValueCheckingTool(mockVersionHelper.Object, mockRepository.Object);

            mockChemistryValueCheckingRule = new Mock<ChemistryValueCheckingRule>();
        }
        public ResultMessageViewModel QAQCChemistryData(IEnumerable<ChemistryQAQCDataEditViewModel> data)
        {
            var versioningHelper = new DataVersioningHelper(_wqDefaultValueProvider);
                        
            var items = from qaqcData in data
                        select new ChemistryValueCheckingRuleItem { 
                            ActionId = qaqcData.ActionId,
                            CorrectionValue = qaqcData.NewResultValue
                        };
            var rule = new ChemistryValueCheckingRule { 
                Items = items.ToList()
            };

            var dataFetchCriteria = new GetActionDataByIdsCriteria(_actionRepository, rule);

            var chemistryQAQCTool = new ChemistryValueCheckingTool(versioningHelper, _relatedActionTypeRepository);

            try
            { 
                //Check
                //var qaqcResult = chemistryQAQCTool.Check(dataFetchCriteria.FetchData(), rule);

                //Correct
                var qaqcResult = chemistryQAQCTool.Correct(dataFetchCriteria.FetchData(), rule);

                if(qaqcResult.NeedCorrection)
                {
                    var numberOfActionSaved = _actionRepository.SaveChanges();
                }

                if (qaqcResult.Level == QualityCheckingResultLevel.Info)
                {
                    var message = ConstructResultMessage(qaqcResult, "QA/QC data is saved.");
                    return new ResultMessageViewModel(ResultMessageViewModel.RESULT_LEVEL_INFO, message);
                }
                else
                {
                    var message = ConstructResultMessage(qaqcResult, "QA/QC data does not saved. Please check the result message for more detail.");
                    return new ResultMessageViewModel(ResultMessageViewModel.RESULT_LEVEL_FATAL, message);
                }
                
            }
            catch(Exception ex)
            {
                var message = "QA/QC data fail due to " + ex.StackTrace;
                return new ResultMessageViewModel(ResultMessageViewModel.RESULT_LEVEL_FATAL, message);
            }
            
        }