Пример #1
0
        public void ShouldApplyAddedToWorkflowEvent()
        {
            using (var serviceLocatorFixture = new ServiceLocatorFixture())
            {
                // Setup
                SetupServiceLocatorFixture(serviceLocatorFixture);

                var events = new List <IDomainEvent>();
                CommitEvent.RegisterAll(events.Add);

                // Exercise
                Guid defGuid     = CombGuid.NewCombGuid();
                Guid patientGuid = CombGuid.NewCombGuid();
                var  source      = new AssessmentInstance(defGuid, patientGuid, assessmentName);
                Guid workflowKey = CombGuid.NewCombGuid();
                source.AddToWorkflow(workflowKey);

                // Verify
                Assert.AreEqual(2, events.Count);
                var addedToWorkflowEvent = events[1];
                Assert.IsNotNull(addedToWorkflowEvent);
                Assert.AreEqual(typeof(AssessmentAddedToWorkflowEvent), addedToWorkflowEvent.GetType());
                Assert.AreEqual((addedToWorkflowEvent as AssessmentAddedToWorkflowEvent).WorkflowKey, workflowKey);
                Assert.AreEqual(2, source.Version);
            }
        }
        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);
            }
        }