コード例 #1
0
        public void ShouldNotBeValidInWrongStatus()
        {
            var order = new ExpenseReport();
            order.Status = ExpenseReportStatus.Submitted;
            var employee = new Employee();
            order.Submitter = employee;

            var command = new SubmittedToApprovedCommand(order, employee);
            Assert.That(command.IsValid(), Is.False);
        }
        public void ShouldNotBeValidInWrongStatus()
        {
            var report = new ExpenseReport();
            report.Status = ExpenseReportStatus.Draft;
            var employee = new Employee();
            report.Approver = employee;

            var command = new SubmittedToApprovedCommand();
            Assert.That(command.IsValid(new ExecuteTransitionCommand(report, null, employee, new DateTime())), Is.False);
        }
        public void ShouldBeValid()
        {
            var order = new ExpenseReport();
            order.Status = ExpenseReportStatus.Submitted;
            var employee = new Employee();
            order.Approver = employee;

            var command = new SubmittedToApprovedCommand();
            Assert.That(command.IsValid(new ExecuteTransitionCommand(order, null, employee, new DateTime())), Is.True);
        }
コード例 #4
0
        public void ShouldNotBeValidWithWrongEmployee()
        {
            var order = new ExpenseReport();
            order.Status = ExpenseReportStatus.Draft;
            var employee = new Employee();
            var differentEmployee = new Employee();
            order.Approver = employee;

            var command = new SubmittedToApprovedCommand(order, differentEmployee);
            Assert.That(command.IsValid(), Is.False);
        }
        public void ShouldBeValidWithOnBehalfApprover()
        {
            var report = new ExpenseReport();
            report.Status = ExpenseReportStatus.Submitted;
            var manager = new Manager();
            var assistant = new Employee();
            manager.AdminAssistant = assistant;
            report.Approver = manager;

            var command = new SubmittedToApprovedCommand();
            Assert.That(command.IsValid(new ExecuteTransitionCommand(report, null, assistant, new DateTime())), Is.True);
        }
コード例 #6
0
        public void ShouldTransitionStateProperly()
        {
            var order = new ExpenseReport();
            order.Number = "123";
            order.Status = ExpenseReportStatus.Submitted;
            var employee = new Employee();
            order.Approver = employee;

            var mocks = new MockRepository();
            var commandVisitor = mocks.DynamicMock<IStateCommandVisitor>();
            commandVisitor.Save(order);
            commandVisitor.GoToEdit(order);
            mocks.ReplayAll();

            var command = new SubmittedToApprovedCommand(order, employee);
            command.Execute(commandVisitor);

            mocks.VerifyAll();
            Assert.That(order.Status, Is.EqualTo(ExpenseReportStatus.Approved));
        }
        public void ShouldSetLastApprovedEachTime()
        {
            var report = new ExpenseReport();
            report.Number = "123";
            report.Status = ExpenseReportStatus.Submitted;
            var employee = new Employee();
            report.Approver = employee;

            var approvedDate = new DateTime(2015,01,01);

            var command = new SubmittedToApprovedCommand();
            command.Execute(new ExecuteTransitionCommand(report, null, employee, approvedDate));

            Assert.That(report.LastApproved, Is.EqualTo(approvedDate));

            var approvedDate2 = new DateTime(2015, 02, 02);

            var command2 = new SubmittedToApprovedCommand();
            command2.Execute(new ExecuteTransitionCommand(report, null, employee, approvedDate2));

            Assert.That(report.LastApproved, Is.Not.EqualTo(approvedDate));
            Assert.That(report.LastApproved, Is.EqualTo(approvedDate2));
        }
        public void ShouldTransitionStateProperly()
        {
            var report = new ExpenseReport();
            report.Number = "123";
            report.Status = ExpenseReportStatus.Submitted;
            var employee = new Employee();
            report.Approver = employee;

            var command = new SubmittedToApprovedCommand();
            command.Execute(new ExecuteTransitionCommand(report, null, employee, new DateTime()));

            Assert.That(report.Status, Is.EqualTo(ExpenseReportStatus.Approved));
        }