Esempio n. 1
0
        public void CallAdministerAssessment_WorkflowMessageStatusChangedEventRaised()
        {
            using (var serviceLocatorFixture = new ServiceLocatorFixture())
            {
                // Setup
                SetupServiceLocatorFixture(serviceLocatorFixture);

                var workflowMessage = new WorkflowMessage(Guid.NewGuid(), Guid.NewGuid(), string.Empty, Guid.NewGuid(), string.Empty, new Score());

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

                workflowMessage.AdministerAssessment();

                Assert.AreEqual(1, events.Count(), "Incorrect number of events.");
                Assert.AreEqual(typeof(WorkflowMessageStatusChangedEvent), events.First().GetType());
                Assert.AreEqual(WorkflowMessageStatus.InProgress, (events.First() as WorkflowMessageStatusChangedEvent).Status);
            }
        }
Esempio n. 2
0
        public void CallAdvance_CorrectEventsRaised()
        {
            using (var serviceLocatorFixture = new ServiceLocatorFixture())
            {
                // Setup
                SetupServiceLocatorFixture(serviceLocatorFixture);

                var workflowMessage = new WorkflowMessage(Guid.NewGuid(), Guid.NewGuid(), string.Empty, Guid.NewGuid(), string.Empty, new Score());

                workflowMessage.AdministerAssessment();

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

                var assessmentKey             = Guid.NewGuid();
                var assessmentCode            = Guid.NewGuid().ToString();
                var recommendedAssessmentKey  = Guid.NewGuid();
                var recommendedAssessmentCode = Guid.NewGuid().ToString();
                var score = new Score();
                workflowMessage.Advance(assessmentKey, assessmentCode, recommendedAssessmentKey, recommendedAssessmentCode, score);

                Assert.AreEqual(2, events.Count(), "Incorrect number of events.");
                Assert.IsTrue(events.Any(a => a.GetType() == typeof(WorkflowMessageStatusChangedEvent)), "Status Changed event not raised.");
                Assert.IsTrue(events.Any(a => a.GetType() == typeof(WorkflowMessageAdvancedEvent)), "Advanced Event not raised.");
                Assert.IsTrue(
                    (events.First(a => a.GetType() == typeof(WorkflowMessageStatusChangedEvent)) as WorkflowMessageStatusChangedEvent).Status ==
                    WorkflowMessageStatus.WaitingForResponse,
                    "Status event has wrong status.");
                var advanceEvent = events.First(a => a.GetType() == typeof(WorkflowMessageAdvancedEvent)) as WorkflowMessageAdvancedEvent;
                Assert.AreEqual(assessmentKey, advanceEvent.InitiatingAssessmentKey, "Advance event has wrong InitiatingAssessmentKey.");
                Assert.AreEqual(assessmentCode, advanceEvent.InitiatingAssessmentCode, "Advance event has wrong InitiatingAssessmentCode.");
                Assert.AreEqual(recommendedAssessmentKey, advanceEvent.RecommendedAssessmentDefinitionKey, "Advance event has wrong RecommendedAssessmentDefinitionKey.");
                Assert.AreEqual(recommendedAssessmentCode, advanceEvent.RecommendedAssessmentDefinitionCode, "Advance event has wrong RecommendedAssessmentDefinitionCode.");
                Assert.AreSame(score, advanceEvent.InitiatingAssessmentScore, "Advance event has wrong InitiatingAssessmentScore.");
                Assert.AreEqual(assessmentKey, workflowMessage.InitiatingAssessmentKey, "Worflow message has wrong InitiatingAssessmentKey.");
                Assert.AreEqual(assessmentCode, workflowMessage.InitiatingAssessmentCode, "Worflow message has wrong InitiatingAssessmentCode.");
                Assert.AreEqual(recommendedAssessmentKey, workflowMessage.RecommendedAssessmentDefinitionKey, "Worflow message has wrong RecommendedAssessmentDefinitionKey.");
                Assert.AreEqual(recommendedAssessmentCode, workflowMessage.RecommendedAssessmentDefinitionCode, "Worflow message has wrong RecommendedAssessmentDefinitionCode.");
                Assert.AreSame(score, workflowMessage.InitiatingAssessmentScore, "Worflow message has wrong InitiatingAssessmentScore.");
            }
        }
Esempio n. 3
0
        public void ExecuteShouldRecommendNidaAssessFurtherRuleThenClause_WorkflowMessageCreated()
        {
            using (var serviceLocatorFixture = new ServiceLocatorFixture())
            {
                // Setup
                SetupServiceLocatorFixture(serviceLocatorFixture);
                var assessmentDefKey = Guid.NewGuid();

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

                var assessmentInstance = new AssessmentInstanceFactory().Create(assessmentDefinition, Guid.NewGuid(), "TestName");
                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);
            }
        }
Esempio n. 4
0
        public void WorkflowStatesFlowCorrectly()
        {
            using (var serviceLocatorFixture = new ServiceLocatorFixture())
            {
                // Setup
                SetupServiceLocatorFixture(serviceLocatorFixture);

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

                var workflow = new WorkflowMessage(Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid().ToString(), Guid.NewGuid(), Guid.NewGuid().ToString(), new Score());

                Assert.AreEqual(WorkflowMessageStatus.WaitingForResponse, workflow.Status);

                events.Clear();
                workflow.Advance(Guid.NewGuid(), Guid.NewGuid().ToString(), Guid.NewGuid(), Guid.NewGuid().ToString(), new Score());

                Assert.AreEqual(0, events.Count());
                Assert.AreEqual(WorkflowMessageStatus.WaitingForResponse, workflow.Status);

                workflow.AdministerAssessment();

                Assert.AreEqual(WorkflowMessageStatus.InProgress, workflow.Status);

                events.Clear();
                workflow.Reject();

                Assert.AreEqual(0, events.Count());
                Assert.AreEqual(WorkflowMessageStatus.InProgress, workflow.Status);

                events.Clear();
                workflow.AdministerAssessment();

                Assert.AreEqual(0, events.Count());
                Assert.AreEqual(WorkflowMessageStatus.InProgress, workflow.Status);

                workflow.Advance(Guid.NewGuid(), Guid.NewGuid().ToString(), Guid.NewGuid(), Guid.NewGuid().ToString(), new Score());

                Assert.AreEqual(WorkflowMessageStatus.WaitingForResponse, workflow.Status);

                workflow.Reject();

                Assert.AreEqual(WorkflowMessageStatus.Rejected, workflow.Status);

                events.Clear();
                workflow.Reject();

                Assert.AreEqual(0, events.Count());
                Assert.AreEqual(WorkflowMessageStatus.Rejected, workflow.Status);

                events.Clear();
                workflow.AdministerAssessment();

                Assert.AreEqual(0, events.Count());
                Assert.AreEqual(WorkflowMessageStatus.Rejected, workflow.Status);

                events.Clear();
                workflow.Advance(Guid.NewGuid(), Guid.NewGuid().ToString(), Guid.NewGuid(), Guid.NewGuid().ToString(), new Score());

                Assert.AreEqual(0, events.Count());
                Assert.AreEqual(WorkflowMessageStatus.Rejected, workflow.Status);
            }
        }