Exemplo n.º 1
0
        public void CalculateCompleteness_SkippedItems_CompletenessTotalCorrect()
        {
            using (var serviceLocatorFixture = new ServiceLocatorFixture())
            {
                // Setup
                SetupServiceLocatorFixture(serviceLocatorFixture);
                var itemDefinitions = GetItemDefinitions();

                var ruleCollection = Substitute.For <IAssessmentRuleCollection> ();
                var rule           = Substitute.For <IItemSkippingRule> ();
                rule.SkippedItemDefinitions.Returns(itemDefinitions.Where(i => i.CodedConcept.Code == "3"));
                ruleCollection.ItemSkippingRules.Returns(new List <IItemSkippingRule> {
                    rule
                });
                serviceLocatorFixture.StructureMapContainer.Configure(
                    c => c.For <IAssessmentRuleCollection>().Use(ruleCollection).Named("Test"));


                var assessmentDefinition = Substitute.For <AssessmentDefinition>();
                assessmentDefinition.GetAllItemDefinitionsOfType(Arg.Any <ItemType>()).Returns(itemDefinitions);
                var assessmentInstance = new AssessmentInstance(assessmentDefinition, Guid.NewGuid(), "Test", false);

                var completeness = assessmentInstance.CalculateCompleteness();

                Assert.AreEqual(itemDefinitions.Count(i => i.GetIsRequired()) - 1, completeness.Total);
            }
        }
 /// <summary>Calculates the completeness.</summary>
 /// <param name="assessment">The assessment.</param>
 /// <param name="sectionDefinition">The section definition.</param>
 /// <returns>A <see cref="CompletenessResults" />.</returns>
 public CompletenessResults CalculateCompleteness(AssessmentInstance assessment, ItemDefinition sectionDefinition = null)
 {
     if (sectionDefinition != null)
     {
         var requiredQuestions = AssessmentDefinition.GetAllItemDefinitionsOfTypeInContainer(sectionDefinition, ItemType.Question).Where(i => i.GetIsRequired());
         var totalRequired     = requiredQuestions.Count( );
         var skippedTotal      = requiredQuestions.Select(i => i.CodedConcept.Code).Intersect(assessment.SkippedItemDefinitions.Select(i => i.CodedConcept.Code)).Count();
         var answeredTotal     = requiredQuestions.Select(i => i.CodedConcept.Code).Intersect(assessment.ItemInstances.Select(i => i.ItemDefinitionCode)).Count();
         return(new CompletenessResults("Report", totalRequired - skippedTotal, answeredTotal));
     }
     return(assessment.CalculateCompleteness());
 }
Exemplo n.º 3
0
        public void CalculateCompleteness_NothingSkipped_CompletenessTotalCorrect()
        {
            using (var serviceLocatorFixture = new ServiceLocatorFixture())
            {
                // Setup
                SetupServiceLocatorFixture(serviceLocatorFixture);

                var assessmentDefinition = Substitute.For <AssessmentDefinition> ();
                var itemDefinitions      = GetItemDefinitions();
                assessmentDefinition.GetAllItemDefinitionsOfType(Arg.Any <ItemType> ()).Returns(itemDefinitions);
                var assessmentInstance = new AssessmentInstance(assessmentDefinition, Guid.NewGuid(), "Test", false);

                var completeness = assessmentInstance.CalculateCompleteness();

                Assert.AreEqual(itemDefinitions.Count(i => i.GetIsRequired()), completeness.Total);
            }
        }