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);
            }
            
        }
        public void DataNeedsCorrectionTest()
        {
            var rule = new ChemistryValueCheckingRule();
            var ruleItem = new ChemistryValueCheckingRuleItem();
            var correctionValue = MeasurementValue + 1;
            ruleItem.CorrectionValue = correctionValue;
            ruleItem.ActionId = ActionId;
            rule.Items.Add(ruleItem);

            var qcResult = testTool.Correct(supportedData, rule);
            var castedData = (IEnumerable<Core.Action>)supportedData;

            Assert.NotNull(qcResult);
            Assert.AreEqual("See the inner list for detailed results.", qcResult.Message);
            Assert.AreEqual(QualityCheckingResultLevel.Info, qcResult.Level);
            Assert.True(qcResult.NeedCorrection);
            Assert.AreEqual(correctionValue, castedData.First().RelatedActions.First().
                Action1.FeatureActions.First().Results.First().MeasurementResult.MeasurementResultValues.First().DataValue);
        }
        public void DoesNotNeedCorrectionCheckTest()
        {
            var rule = new ChemistryValueCheckingRule();
            var ruleItem = new ChemistryValueCheckingRuleItem();
            ruleItem.CorrectionValue = MeasurementValue;
            ruleItem.ActionId = ActionId;
            rule.Items.Add(ruleItem);

            var qcResult = testTool.Check(supportedData, rule);

            Assert.IsFalse(qcResult.NeedCorrection);
            Assert.AreEqual(QualityCheckingResultLevel.Info, qcResult.Level);
        }
        public void DataDoesNotNeedCorrectionTest()
        {
            var rule = new ChemistryValueCheckingRule();
            var ruleItem = new ChemistryValueCheckingRuleItem();
            ruleItem.CorrectionValue = MeasurementValue;
            ruleItem.ActionId = ActionId;
            rule.Items.Add(ruleItem);

            var qcResult = testTool.Correct(supportedData, rule);

            Assert.NotNull(qcResult);
            Assert.AreEqual("Sample data meets quality checking rule. No correction is needed.", qcResult.Message);
            Assert.AreEqual(QualityCheckingResultLevel.Info, qcResult.Level);
            Assert.False(qcResult.NeedCorrection);
        }