예제 #1
0
        public void ShouldGetNoValidStateCommandsForWrongUser()
        {
            var facilitator = new WorkflowFacilitator(new StubbedCalendar(new DateTime(2000, 1, 1)));
            var report      = new ExpenseReport();
            var employee    = new Employee();

            IStateCommand[] commands = facilitator.GetValidStateCommands(report, employee);

            Assert.That(commands.Length, Is.EqualTo(0));
        }
예제 #2
0
        public void ShouldReturnAllStateCommandsInCorrectOrder()
        {
            var facilitator = new WorkflowFacilitator(new StubbedCalendar(new DateTime(2000, 1, 1)));

            IStateCommand[] commands = facilitator.GetAllStateCommands(new ExpenseReport(), new Employee());

            Assert.That(commands.Length, Is.EqualTo(3));

            Assert.That(commands[0], Is.InstanceOf(typeof(DraftingCommand)));
            Assert.That(commands[1], Is.InstanceOf(typeof(DraftToSubmittedCommand)));
            Assert.That(commands[2], Is.InstanceOf(typeof(SubmittedToApprovedCommand)));
        }
        public void ShouldGetNoValidStateCommandsForWrongUser()
        {
            var facilitator = new WorkflowFacilitator();
            var report      = new ExpenseReport();
            var employee    = new Employee();

            IStateCommand[] commands = facilitator.GetValidStateCommands(new ExecuteTransitionCommand {
                Report = report, CurrentUser = employee
            });

            Assert.That(commands.Length, Is.EqualTo(0));
        }
        public void ShouldReturnAllStateCommandsInCorrectOrder()
        {
            var facilitator = new WorkflowFacilitator();

            IStateCommand[] commands = facilitator.GetAllStateCommands();

            Assert.That(commands.Length, Is.EqualTo(4));

            Assert.That(commands[0], Is.InstanceOf(typeof(DraftingCommand)));
            Assert.That(commands[1], Is.InstanceOf(typeof(DraftToSubmittedCommand)));
            Assert.That(commands[2], Is.InstanceOf(typeof(DraftToCancelledCommand)));
            Assert.That(commands[3], Is.InstanceOf(typeof(SubmittedToApprovedCommand)));
        }
예제 #5
0
        public ExecuteTransitionResult Handle(ExecuteTransitionCommand command)
        {
            IStateCommand[] commands        = new WorkflowFacilitator().GetValidStateCommands(command);
            IStateCommand   matchingCommand =
                Array.Find(commands, delegate(IStateCommand obj) { return(obj.Matches(command.Command)); });

            matchingCommand.Execute(command);

            _bus.Send(new ExpenseReportSaveCommand {
                ExpenseReport = command.Report
            });
            _bus.Send(new AddExpenseReportFactCommand(new ExpenseReportFact(command.Report, command.CurrentDate)));

            return(new ExecuteTransitionResult
            {
                NewStatus = command.Report.Status.FriendlyName,
                NextStep = NextStep.Edit
            });
        }