Exemplo n.º 1
0
        public void By_default_schedule_timer_to_fire_immediately()
        {
            var timerItem = TimerItem.New(_timerIdentity, null);

            var decision = timerItem.GetScheduleDecisions();

            Assert.That(decision, Is.EqualTo(new [] { new ScheduleTimerDecision(_timerIdentity, new TimeSpan()) }));
        }
Exemplo n.º 2
0
        public void By_default_return_continue_workflow_action()
        {
            var workflow = new WorkflowWithTimer();

            var workflowAction = _timerFiredEvent.Interpret(workflow);

            Assert.That(workflowAction, Is.EqualTo(WorkflowAction.ContinueWorkflow(TimerItem.New(Identity.Timer(_timerName), null))));
        }
Exemplo n.º 3
0
        private TimerItem CreateTimerItemFor(IEnumerable <HistoryEvent> eventGraph)
        {
            var workflowHistoryEvents = new WorkflowHistoryEvents(eventGraph);
            var workflow = new Mock <IWorkflow>();

            workflow.SetupGet(w => w.WorkflowHistoryEvents).Returns(workflowHistoryEvents);
            return(TimerItem.New(_timerIdentity, workflow.Object));
        }
Exemplo n.º 4
0
        public void By_default_schedule_timer_to_fire_immediately()
        {
            var timerItem = TimerItem.New(_timerIdentity, _workflow.Object);

            var decisions = timerItem.ScheduleDecisions().ToArray();

            Assert.That(decisions.Length, Is.EqualTo(1));
            decisions[0].AssertWorkflowItemTimer(_timerIdentity.ScheduleId(), TimeSpan.Zero);
        }
Exemplo n.º 5
0
        public void Should_return_schedule_workflow_action_if_timer_is_fired_to_reschedule_a_timer_item()
        {
            var workflow        = new WorkflowWithTimer();
            var rescheduleTimer = CreateRescheduleTimerFiredEvent(Identity.Timer(_timerName), _fireAfter);

            var workflowAction = rescheduleTimer.Interpret(workflow);

            Assert.That(workflowAction, Is.EqualTo(WorkflowAction.Schedule(TimerItem.New(Identity.Timer(_timerName), null))));
        }
Exemplo n.º 6
0
        public void Should_return_the_scheduling_decision_for_workflow_item()
        {
            var workflowItem   = TimerItem.New(Identity.Timer("Somename"), _workflow.Object);
            var workflowAction = WorkflowAction.Schedule(workflowItem);

            var decisions = workflowAction.GetDecisions();

            Assert.That(decisions, Is.EquivalentTo(workflowItem.GetScheduleDecisions()));
        }
        public void Returns_the_scheduling_decision_for_workflow_item()
        {
            var workflowItem   = TimerItem.New(Identity.Timer("Somename"), _workflow.Object);
            var workflowAction = WorkflowAction.JumpTo(null, workflowItem);

            var decisions = workflowAction.Decisions(Mock.Of <IWorkflow>());

            Assert.That(decisions, Is.EquivalentTo(workflowItem.ScheduleDecisions()));
        }
Exemplo n.º 8
0
        public void Can_be_configured_to_schedule_timer_to_fire_after_timeout()
        {
            var timerItem = TimerItem.New(_timerIdentity, null);

            timerItem.FireAfter(TimeSpan.FromSeconds(3));
            var decision = timerItem.GetScheduleDecisions();

            Assert.That(decision, Is.EqualTo(new [] { new ScheduleTimerDecision(_timerIdentity, TimeSpan.FromSeconds(3)) }));
        }
Exemplo n.º 9
0
        public void Can_be_returned_as_workflow_action_when_scheduling_the_timer()
        {
            var workflow = new WorkflowToReturnScheduleTimerAction();
            var completedActivityEvent = CreateCompletedActivityEvent(ActivityName, ActivityVersion, PositionalName);

            var workflowAction = completedActivityEvent.Interpret(workflow);

            Assert.That(workflowAction, Is.EqualTo(WorkflowAction.JumpTo(TimerItem.New(Identity.Timer("SomeTimer"), null))));
        }
Exemplo n.º 10
0
        public void Returns_cancel_timer_decision_for_timer_item_when_it_is_active()
        {
            SetupWorkflowToReturns(_builder.TimerStartedGraph(Identity.Timer("TimerName"), TimeSpan.FromSeconds(2)));
            var timerItem      = TimerItem.New(Identity.Timer("TimerName"), _workflow.Object);
            var workflowAction = WorkflowAction.Cancel(timerItem);

            var decisions = workflowAction.GetDecisions();

            Assert.That(decisions, Is.EqualTo(new[] { new CancelTimerDecision(Identity.Timer("TimerName")) }));
        }
Exemplo n.º 11
0
        public void Return_empty_when_when_condition_is_evaluated_to_false()
        {
            var timerItem = TimerItem.New(_timerIdentity, Mock.Of <IWorkflow>());

            timerItem.When(t => false);

            var decisions = timerItem.GetScheduleDecisions();

            Assert.That(decisions, Is.Empty);
        }
Exemplo n.º 12
0
        public void Can_be_configured_to_schedule_timer_to_fire_after_timeout_using_lambda()
        {
            var timerItem = TimerItem.New(_timerIdentity, _workflow.Object);

            timerItem.FireAfter(_ => TimeSpan.FromSeconds(4));
            var decisions = timerItem.ScheduleDecisions().ToArray();

            Assert.That(decisions.Length, Is.EqualTo(1));
            decisions[0].AssertWorkflowItemTimer(_timerIdentity.ScheduleId(), TimeSpan.FromSeconds(4));
        }
Exemplo n.º 13
0
        public void Fire_after_lambda_handler_override_the_fire_after_timeout()
        {
            var timerItem = TimerItem.New(_timerIdentity, _workflow.Object);

            timerItem.FireAfter(_ => TimeSpan.FromSeconds(3)).FireAfter(TimeSpan.FromSeconds(4));
            var decisions = timerItem.ScheduleDecisions().ToArray();

            Assert.That(decisions.Length, Is.EqualTo(1));
            decisions[0].AssertWorkflowItemTimer(_timerIdentity.ScheduleId(), TimeSpan.FromSeconds(3));
        }
Exemplo n.º 14
0
        public void Timerof_test()
        {
            var eventGraph             = _builder.TimerFiredGraph(Identity.Timer("Timer1"), TimeSpan.FromSeconds(2));
            var activityCompletedEvent = new TimerFiredEvent(eventGraph.First(), eventGraph);
            var workflow = new TestWorkflow();

            var activity = workflow.GetTimerOf(activityCompletedEvent);

            Assert.That(activity, Is.EqualTo(TimerItem.New(Identity.Timer("Timer1"), workflow)));
        }
Exemplo n.º 15
0
        public void Can_get_single_parent_timer()
        {
            var parentTimers = new[]
            {
                TimerItem.New(Identity.Timer("name1"), Mock.Of <IWorkflow>()),
            };

            _workflowItem.SetupGet(w => w.ParentTimers).Returns(parentTimers);

            Assert.That(_workflowItem.Object.ParentTimer(), Is.EqualTo(parentTimers[0]));
        }
Exemplo n.º 16
0
        public void Schedule_the_timer_with_default_scheduleid_when_it_has_not_already_scheduled()
        {
            var identity       = Identity.Timer("Somename");
            var workflowItem   = TimerItem.New(identity, _workflow.Object);
            var workflowAction = WorkflowAction.JumpTo(null, workflowItem);

            var decisions = workflowAction.Decisions(Mock.Of <IWorkflow>()).ToArray();

            Assert.That(decisions.Count(), Is.EqualTo(1));
            decisions[0].AssertWorkflowItemTimer(identity.ScheduleId(), TimeSpan.Zero);
        }
Exemplo n.º 17
0
        public void Parent_timers_test()
        {
            var workflowWithParentActivity = new WorkflowWithParentTimer("parent1");
            var childActivity = new ActivityItem(Identity.New("child", "1.0"), workflowWithParentActivity);

            childActivity.AfterTimer("parent1");

            var parentActivities = childActivity.ParentTimers;

            Assert.That(parentActivities, Is.EquivalentTo(new[] { TimerItem.New(Identity.Timer("parent1"), null), }));
            Assert.That(parentActivities.First().Name, Is.EqualTo("parent1"));
        }
Exemplo n.º 18
0
        public void Invalid_arguments_test()
        {
            var timerItem = (IFluentTimerItem)TimerItem.New(_timerIdentity, null);

            Assert.Throws <ArgumentNullException>(() => timerItem.OnCancelled(null));
            Assert.Throws <ArgumentNullException>(() => timerItem.OnFailedCancellation(null));
            Assert.Throws <ArgumentNullException>(() => timerItem.OnFired(null));
            Assert.Throws <ArgumentNullException>(() => timerItem.OnStartFailure(null));
            Assert.Throws <ArgumentNullException>(() => timerItem.When(null));

            Assert.Throws <ArgumentException>(() => timerItem.AfterActivity(null, "1.0"));
            Assert.Throws <ArgumentException>(() => timerItem.AfterActivity("1.0", null));
            Assert.Throws <ArgumentException>(() => timerItem.AfterTimer(null));
        }
Exemplo n.º 19
0
        public void Returns_cancel_timer_decision_for_timer_item_when_it_is_active_with_reset_schedule_id()
        {
            const string runId = "runid";

            _builder.AddWorkflowRunId(runId);
            var scheduleId = Identity.Timer("TimerName").ScheduleId(runId + "Reset");

            _builder.AddProcessedEvents(_eventGraph.TimerStartedGraph(scheduleId, TimeSpan.FromSeconds(2)).ToArray());
            _workflow.SetupGet(w => w.WorkflowHistoryEvents).Returns(_builder.Result());
            var timerItem      = TimerItem.New(Identity.Timer("TimerName"), _workflow.Object);
            var workflowAction = WorkflowAction.Cancel(timerItem);

            var decisions = workflowAction.Decisions(Mock.Of <IWorkflow>());

            Assert.That(decisions, Is.EqualTo(new[] { new CancelTimerDecision(scheduleId) }));
        }
Exemplo n.º 20
0
        public void Reuse_the_scheduleid_when_it_has_already_scheduled()
        {
            const string runId      = "runid";
            var          identity   = Identity.Timer("Somename");
            var          scheduleId = identity.ScheduleId(runId + "Reset");

            _builder.AddWorkflowRunId(runId);
            _builder.AddProcessedEvents(_graphBuilder.TimerStartedGraph(scheduleId, TimeSpan.Zero).ToArray());
            _workflow.SetupGet(w => w.WorkflowHistoryEvents).Returns(_builder.Result());

            var workflowItem   = TimerItem.New(identity, _workflow.Object);
            var workflowAction = WorkflowAction.JumpTo(null, workflowItem);

            var decisions = workflowAction.Decisions(Mock.Of <IWorkflow>()).ToArray();

            Assert.That(decisions.Count(), Is.EqualTo(1));
            decisions[0].AssertWorkflowItemTimer(scheduleId, TimeSpan.Zero);
        }
Exemplo n.º 21
0
 private static ITimerItem CreateTimer(string name)
 {
     return(TimerItem.New(Identity.Timer(name), Mock.Of <IWorkflow>()));
 }
Exemplo n.º 22
0
 public void Equality_tests()
 {
     Assert.True(WorkflowAction.Schedule(TimerItem.New(Identity.Timer("Somename"), _workflow.Object)).Equals(WorkflowAction.Schedule(TimerItem.New(Identity.Timer("Somename"), _workflow.Object))));
     Assert.False(WorkflowAction.Schedule(TimerItem.New(Identity.Timer("Somename"), _workflow.Object)).Equals(WorkflowAction.Schedule(TimerItem.New(Identity.Timer("Somename1"), _workflow.Object))));
 }