Esempio n. 1
0
        public void ExecuteShouldRecommendDastRuleThenClause_WorkflowMessageCreated()
        {
            using (var serviceLocatorFixture = new ServiceLocatorFixture())
            {
                // Setup
                SetupServiceLocatorFixture(serviceLocatorFixture);
                var assessmentDefKey = Guid.NewGuid();
                var ruleCollection   =
                    new NidaWorkflowRuleCollection(
                        BuildIAssessmentDefinitionRepositoryMock(assessmentDefKey).Object,
                        BuildIRepositoryMock(null).Object,
                        new Mock <IAssessmentInstanceRepository>().Object);

                var assessmentDefinition = Substitute.For <AssessmentDefinition>();

                var assessmentInstance = new AssessmentInstanceFactory().Create(assessmentDefinition, Guid.NewGuid(), "TestName");
                assessmentInstance.ScoreComplete(new CodedConcept(new CodeSystem("", "", ""), "", ""), "test");
                var messageCollector  = new MessageCollector();
                var ruleEngineContext = new RuleEngineContext <AssessmentInstance>(assessmentInstance);
                ruleEngineContext.WorkingMemory.AddContextObject <IMessageCollector>(messageCollector, "MessageCollector");

                foreach (var action in ruleCollection.ShouldRecommendDastRule.ThenClauses)
                {
                    action(ruleEngineContext);
                }

                Assert.AreEqual(1, messageCollector.Messages.Count(), "Incorrect Number of messages.");
                Assert.AreEqual(typeof(WorkflowMessage), messageCollector.Messages.First().GetType());
                var workflowMessage = messageCollector.Messages.First() as WorkflowMessage;
                Assert.AreEqual(assessmentInstance.Key, workflowMessage.InitiatingAssessmentKey);
                Assert.AreEqual(DrugAbuseScreeningTest.AssessmentCodedConcept.Code, workflowMessage.RecommendedAssessmentDefinitionCode);
            }
        }
Esempio n. 2
0
        public void NidaDrugAbuseScreeningTestRuleSetContainsCorrectRules()
        {
            var ruleCollection = new NidaWorkflowRuleCollection(new Mock <IAssessmentDefinitionRepository>().Object, new Mock <IWorkflowMessageRepository>().Object, new Mock <IAssessmentInstanceRepository>().Object);

            Assert.AreEqual(1, ruleCollection.DrugAbuseScreeningTestRuleSet.Count());
            Assert.AreEqual(ruleCollection.ShouldRecommendNidaAssessFurtherRule, ruleCollection.DrugAbuseScreeningTestRuleSet.First());
        }
Esempio n. 3
0
        public void AllRulesAndRuleSetsDefined()
        {
            var ruleCollection = new NidaWorkflowRuleCollection(new Mock <IAssessmentDefinitionRepository>().Object, new Mock <IWorkflowMessageRepository>().Object, new Mock <IAssessmentInstanceRepository>().Object);

            foreach (var propertyInfo in typeof(NidaWorkflowRuleCollection).GetProperties())
            {
                Assert.IsNotNull(propertyInfo.GetMethod.Invoke(ruleCollection, null), string.Format("Property {0} is null.", propertyInfo.Name));
            }
        }
        public void ExecuteShouldRecommendNidaAssessFurtherRuleThenClause_WorkflowMessageCreated()
        {
            using (var serviceLocatorFixture = new ServiceLocatorFixture())
            {
                // Setup
                SetupServiceLocatorFixture(serviceLocatorFixture);
                var assessmentDefKey = Guid.NewGuid();

                var assessmentInstance = new AssessmentInstance(Guid.NewGuid(), Guid.NewGuid(), "");
                var workflowMessage    = new WorkflowMessage(Guid.NewGuid(),
                                                             Guid.NewGuid(),
                                                             string.Empty,
                                                             assessmentInstance.AssessmentDefinitionKey,
                                                             DrugAbuseScreeningTest.AssessmentCodedConcept.Code,
                                                             null);
                workflowMessage.AdministerAssessment();
                assessmentInstance.AddToWorkflow(workflowMessage.Key);
                var ruleCollection =
                    new NidaWorkflowRuleCollection(
                        BuildIAssessmentDefinitionRepositoryMock(assessmentDefKey).Object,
                        BuildIRepositoryMock(workflowMessage).Object,
                        new Mock <IAssessmentInstanceRepository>().Object);
                assessmentInstance.ScoreComplete(new CodedConcept(new CodeSystem("", "", ""), "", ""), "test");
                var messageCollector  = new MessageCollector();
                var ruleEngineContext = new RuleEngineContext <AssessmentInstance>(assessmentInstance);
                ruleEngineContext.WorkingMemory.AddContextObject <IMessageCollector>(messageCollector, "MessageCollector");

                foreach (var action in ruleCollection.ShouldRecommendNidaAssessFurtherRule.ThenClauses)
                {
                    action(ruleEngineContext);
                }

                Assert.AreEqual(1, messageCollector.Messages.Count(), "Incorrect Number of messages.");
                Assert.AreEqual(typeof(WorkflowMessage), messageCollector.Messages.First().GetType());
                Assert.AreSame(workflowMessage, messageCollector.Messages.First());
                Assert.AreEqual(NidaAssessFurther.AssessmentCodedConcept.Code, (messageCollector.Messages.First() as WorkflowMessage).RecommendedAssessmentDefinitionCode);
            }
        }