private IQualityCheckingResult DoesValueMeetRuleItem(Core.Action action, ChemistryValueCheckingRuleItem ruleItem)
        {
            if (action == null || action.FeatureActions == null || !action.FeatureActions.Any())
            {
                return new QualityCheckingResult("No result found for the action.", false, QualityCheckingResultLevel.Info);
            }

            // Assume chemistry action contains only one result
            var result = action.FeatureActions.FirstOrDefault().Results.FirstOrDefault();

            if (result == null)
            {
                return new QualityCheckingResult("No result found for the action.", false, QualityCheckingResultLevel.Info);
            }

            var resultStringBuilder = new StringBuilder();
            var needCorrection = false;

            // Assume only one measurement result value
            var measurementResultValue = result.MeasurementResult.MeasurementResultValues.FirstOrDefault();

            if (measurementResultValue == null)
            {
                resultStringBuilder.AppendLine("Sample Result: " + ResultToString(result) + " does not contain data.");
            }
            else
            {
                if (measurementResultValue.DataValue == ruleItem.CorrectionValue)
                {
                    resultStringBuilder.AppendLine(
                        string.Format(validManualQualityResultFormat, ResultToString(result))
                    );
                }
                else
                {
                    resultStringBuilder.AppendLine(
                        string.Format(invalidManualQualityResultFormat,
                                      ResultToString(result),
                                      measurementResultValue.DataValue,
                                      ruleItem.CorrectionValue)
                    );

                    needCorrection = true;
                }
            }


            var qcResult = new QualityCheckingResult(resultStringBuilder.ToString(), needCorrection, QualityCheckingResultLevel.Info);

            return qcResult;
        }
        private Core.Action CorrectChemistryData(Core.Action action, ChemistryValueCheckingRuleItem ruleItem)
        {
            var newVersionOfData = _dataVersioningHelper.CloneActionData(action);

            // Assume only one measurement result value
            var measurementresultValue = newVersionOfData.FeatureActions.FirstOrDefault().Results.FirstOrDefault().MeasurementResult.MeasurementResultValues.FirstOrDefault();

            measurementresultValue.DataValue = (double)ruleItem.CorrectionValue;

            return newVersionOfData;
        }
        private IQualityCheckingResult GenerateCorrectChemistryDataNewVersion(Core.Action action, ChemistryValueCheckingRuleItem ruleItem)
        {
            var newVersionOfData = CorrectChemistryData(action, ruleItem);

            var newRelationAction = new RelatedAction();

            newRelationAction.Action = action;
            newRelationAction.Action1 = newVersionOfData;
            newRelationAction.RelationshipTypeCV = QualityAssuranceConstants.SubVersionRelationCVType;
            newRelationAction.CV_RelationshipType = _relationShipTypeCVRepository.GetAll()
                .Where(x => x.Name == QualityAssuranceConstants.SubVersionRelationCVType).FirstOrDefault();

            action.RelatedActions.Add(newRelationAction);

            return new QualityCheckingResult("Create new version for correction data.", false, QualityCheckingResultLevel.Info);
        }
        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 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 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);
        }