public void ShouldSave()
        {
            new DatabaseTester().Clean();

            var creator = new Employee("1", "1", "1", "1");
            var assignee = new Employee("2", "2", "2", "2");
            var order = new ExpenseReport();
            order.Submitter = creator;
            order.Approver = assignee;
            order.Title = "foo";
            order.Description = "bar";
            order.ChangeStatus(ExpenseReportStatus.Approved);
            order.Number = "123";
            ISession session = DataContext.GetTransactedSession();
            session.SaveOrUpdate(creator);
            session.SaveOrUpdate(assignee);
            session.Transaction.Commit();

            var repository = new ExpenseReportRepository();
            repository.Save(order);

            session.Dispose();

            ISession session2 = DataContext.GetTransactedSession();
            var rehydratedReport = session2.Load<ExpenseReport>(order.Id);
            Assert.That(rehydratedReport.Id, Is.EqualTo(order.Id));
            Assert.That(rehydratedReport.Submitter.Id, Is.EqualTo(order.Submitter.Id));
            Assert.That(rehydratedReport.Approver.Id, Is.EqualTo(order.Approver.Id));
            Assert.That(rehydratedReport.Title, Is.EqualTo(order.Title));
            Assert.That(rehydratedReport.Description, Is.EqualTo(order.Description));
            Assert.That(rehydratedReport.Status, Is.EqualTo(order.Status));

            rehydratedReport.Number.ShouldEqual(order.Number);
        }
        public void ShouldSetLastSubmittedOnEachSubmission()
        {
            var order = new ExpenseReport();
            order.Number = "123";
            order.Status = ExpenseReportStatus.Draft;
            var employee = new Employee();
            order.Approver = employee;

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

            var command = new DraftToSubmittedCommand();
            command.Execute(new ExecuteTransitionCommand(order, null, employee, firstSubmitDate));

            Assert.That(order.FirstSubmitted, Is.EqualTo(firstSubmitDate));
            Assert.That(order.LastSubmitted, Is.EqualTo(firstSubmitDate));

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

            var command2 = new DraftToSubmittedCommand();
            command2.Execute(new ExecuteTransitionCommand(order, null, employee, secondSubmitDate));

            Assert.That(order.FirstSubmitted, Is.EqualTo(firstSubmitDate));
            Assert.That(order.LastSubmitted, Is.Not.EqualTo(firstSubmitDate));
            Assert.That(order.LastSubmitted, Is.EqualTo(secondSubmitDate));

            var thirdSubmitDate = new DateTime(2015,03,03);

            var command3 = new DraftToSubmittedCommand();
            command3.Execute(new ExecuteTransitionCommand(order, null, employee, thirdSubmitDate));

            Assert.That(order.FirstSubmitted, Is.EqualTo(firstSubmitDate));
            Assert.That(order.LastSubmitted, Is.Not.EqualTo(firstSubmitDate));
            Assert.That(order.LastSubmitted, Is.Not.EqualTo(secondSubmitDate));
            Assert.That(order.LastSubmitted, Is.EqualTo(thirdSubmitDate));
        }
        public void ShouldGetByNumber()
        {
            new DatabaseTester().Clean();

            var creator = new Employee("1", "1", "1", "1");
            var order1 = new ExpenseReport();
            order1.Submitter = creator;
            order1.Number = "123";
            var order2 = new ExpenseReport();
            order2.Submitter = creator;
            order2.Number = "456";

            ISession session = DataContext.GetTransactedSession();
            session.SaveOrUpdate(creator);
            session.SaveOrUpdate(order1);
            session.SaveOrUpdate(order2);
            session.Transaction.Commit();
            session.Dispose();

            var repository = new ExpenseReportRepository();
            ExpenseReport order123 = repository.GetSingle("123");
            ExpenseReport order456 = repository.GetSingle("456");

            Assert.That(order123.Id, Is.EqualTo(order1.Id));
            Assert.That(order456.Id, Is.EqualTo(order2.Id));
        }
        public void ShouldSetLastWithdrawnAndCancelledTime()
        {
            var order = new ExpenseReport();
            order.Number = "123";
            order.Status = ExpenseReportStatus.Approved;
            var employee = new Employee();
            order.Approver = employee;

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

            var command = new ApprovedToCancelledCommand();

            command.Execute(new ExecuteTransitionCommand(order, null, employee, cancelledDate));

            Assert.That(order.LastCancelled, Is.EqualTo(cancelledDate));
            Assert.That(order.LastWithdrawn, Is.EqualTo(cancelledDate));

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

            var command2 = new ApprovedToCancelledCommand();
            command2.Execute(new ExecuteTransitionCommand(order, null, employee, cancelledDate2));

            Assert.That(order.LastCancelled, Is.Not.EqualTo(cancelledDate));
            Assert.That(order.LastCancelled, Is.EqualTo(cancelledDate2));
        }
        public void ShouldExecuteDraftTransition()
        {
            new DatabaseTester().Clean();

            var report = new ExpenseReport();
            report.Number = "123";
            report.Status = ExpenseReportStatus.Draft;
            var employee = new Employee("jpalermo", "Jeffrey", "Palermo", "jeffrey @ clear dash measure.com");
            report.Submitter = employee;
            report.Approver = employee;

            using (ISession session = DataContext.GetTransactedSession())
            {
                session.SaveOrUpdate(employee);
                session.SaveOrUpdate(report);
                session.Transaction.Commit();
            }

            var command = new ExecuteTransitionCommand(report, "Save", employee, new DateTime(2001, 1, 1));

            IContainer container = DependencyRegistrarModule.EnsureDependenciesRegistered();
            var bus = container.GetInstance<Bus>();

            ExecuteTransitionResult result = bus.Send(command);
            result.NewStatus.ShouldEqual("Drafting");
        }
        public void ShouldSearchBySpecificationWithCreator()
        {
            new DatabaseTester().Clean();

            var creator1 = new Employee("1", "1", "1", "1");
            var creator2 = new Employee("2", "2", "2", "2");
            var order1 = new ExpenseReport();
            order1.Submitter = creator1;
            order1.Number = "123";
            var order2 = new ExpenseReport();
            order2.Submitter = creator2;
            order2.Number = "456";

            using (ISession session = DataContext.GetTransactedSession())
            {
                session.SaveOrUpdate(creator1);
                session.SaveOrUpdate(creator2);
                session.SaveOrUpdate(order1);
                session.SaveOrUpdate(order2);
                session.Transaction.Commit();
            }

            var specification = new ExpenseReportSpecificationQuery{Submitter = creator1};

            IContainer container = DependencyRegistrarModule.EnsureDependenciesRegistered();
            var bus = container.GetInstance<Bus>();
            MultipleResult<ExpenseReport> result = bus.Send(specification);
            ExpenseReport[] reports = result.Results;

            Assert.That(reports.Length, Is.EqualTo(1));
            Assert.That(reports[0].Id, Is.EqualTo(order1.Id));
        }
Exemplo n.º 7
0
        public void PropertiesShouldGetAndSetValuesProperly()
        {
            var report = new ExpenseReport();
            Guid guid = Guid.NewGuid();
            var creator = new Employee();
            var assignee = new Employee();
            DateTime auditDate = new DateTime(2000, 1, 1, 8, 0, 0);
            AuditEntry testAudit = new AuditEntry(creator, auditDate, ExpenseReportStatus.Submitted, ExpenseReportStatus.Approved);

            report.Id = guid;
            report.Title = "Title";
            report.Description = "Description";
            report.Status = ExpenseReportStatus.Approved;
            report.Number = "Number";
            report.Submitter = creator;
            report.Approver = assignee;
            report.AddAuditEntry(testAudit);

            Assert.That(report.Id, Is.EqualTo(guid));
            Assert.That(report.Title, Is.EqualTo("Title"));
            Assert.That(report.Description, Is.EqualTo("Description"));
            Assert.That(report.Status, Is.EqualTo(ExpenseReportStatus.Approved));
            Assert.That(report.Number, Is.EqualTo("Number"));
            Assert.That(report.Submitter, Is.EqualTo(creator));
            Assert.That(report.Approver, Is.EqualTo(assignee));
            Assert.That(report.GetAuditEntries()[0].BeginStatus, Is.EqualTo(ExpenseReportStatus.Submitted));
            Assert.That(report.GetAuditEntries()[0].EndStatus, Is.EqualTo(ExpenseReportStatus.Approved));
            Assert.That(report.GetAuditEntries()[0].Date, Is.EqualTo(auditDate));
            Assert.That(report.GetAuditEntries()[0].ArchivedEmployeeName, Is.EqualTo(" "));
        }
        public void ShouldAddFact()
        {
            new DatabaseTester().Clean();

            var creator = new Employee("1", "1", "1", "1");
            var assignee = new Employee("2", "2", "2", "2");
            var expenseReport = new ExpenseReport
            {
                Submitter = creator,
                Approver = assignee,
                Title = "foo",
                Description = "bar",
                Number = "123"
            };
            expenseReport.ChangeStatus(ExpenseReportStatus.Approved);
            ExpenseReportFact expenseReportFact = new ExpenseReportFact(expenseReport,new DateTime(2012,1,1));

            using (ISession session = DataContext.GetTransactedSession())
            {
                //session.SaveOrUpdate(expenseReport);
                session.SaveOrUpdate(expenseReportFact);
                session.Transaction.Commit();
            }

            using (ISession session = DataContext.GetTransactedSession())
            {
                var reportFact = session.Load<ExpenseReportFact>(expenseReportFact.Id);
                reportFact.Total.ShouldEqual(expenseReportFact.Total);
                reportFact.TimeStamp.ShouldEqual(expenseReportFact.TimeStamp);
                reportFact.Number.ShouldEqual(expenseReportFact.Number);
                reportFact.Status.ShouldEqual(expenseReportFact.Status);
                reportFact.Submitter.ShouldEqual(expenseReportFact.Submitter);
                reportFact.Approver.ShouldEqual(expenseReportFact.Approver);
            }
        }
        public void ShouldGetByNumber()
        {
            new DatabaseTester().Clean();

            var creator = new Employee("1", "1", "1", "1");
            var order1 = new ExpenseReport();
            order1.Submitter = creator;
            order1.Number = "123";
            var report = new ExpenseReport();
            report.Submitter = creator;
            report.Number = "456";

            using (ISession session = DataContext.GetTransactedSession())
            {
                session.SaveOrUpdate(creator);
                session.SaveOrUpdate(order1);
                session.SaveOrUpdate(report);
                session.Transaction.Commit();
            }

            IContainer container = DependencyRegistrarModule.EnsureDependenciesRegistered();
            var bus = container.GetInstance<Bus>();

            ExpenseReport order123 = bus.Send(new ExpenseReportByNumberQuery {ExpenseReportNumber = "123"}).Result;
            ExpenseReport order456 = bus.Send(new ExpenseReportByNumberQuery {ExpenseReportNumber = "456"}).Result;

            Assert.That(order123.Id, Is.EqualTo(order1.Id));
            Assert.That(order456.Id, Is.EqualTo(report.Id));
        }
Exemplo n.º 10
0
        public void ShouldShowFriendlyStatusValuesAsStrings()
        {
            var report = new ExpenseReport();
            report.Status = ExpenseReportStatus.Submitted;

            Assert.That(report.FriendlyStatus, Is.EqualTo("Submitted"));
        }
Exemplo n.º 11
0
 public void ShouldChangeStatus()
 {
     var report = new ExpenseReport();
     report.Status = ExpenseReportStatus.Draft;
     report.ChangeStatus(ExpenseReportStatus.Submitted);
     Assert.That(report.Status, Is.EqualTo(ExpenseReportStatus.Submitted));
 }
        private static void RunToDraft(string number, Employee employee, int total, DateTime startingDate, params string[] commandsToRun)
        {
            var report = new ExpenseReport();
            report.Number = number;
            report.Status = ExpenseReportStatus.Draft;
            report.Submitter = employee;
            report.Approver = employee;
            report.Total = total;

            using (ISession session = DataContext.GetTransactedSession())
            {
                session.SaveOrUpdate(report);
                session.Transaction.Commit();
            }

            IContainer container = DependencyRegistrarModule.EnsureDependenciesRegistered();
            var bus = container.GetInstance<Bus>();

            for (int j = 0; j < commandsToRun.Length; j++)
            {
                DateTime timestamp = startingDate.AddSeconds(j);
                var command = new ExecuteTransitionCommand(report, commandsToRun[j], employee, timestamp);
                bus.Send(command);
            }
        }
Exemplo n.º 13
0
        public IStateCommand[] GetValidStateCommands(ExpenseReport expenseReport, Employee currentUser)
        {
            var commands = new List<IStateCommand>(
                GetAllStateCommands(expenseReport, currentUser));
            commands.RemoveAll(delegate(IStateCommand obj) { return !obj.IsValid(); });

            return commands.ToArray();
        }
 public ExecuteCommandResult(ExpenseReport expenseReport, string command)
     : this(expenseReport, command, 
     new WorkflowFacilitator(new Calendar()), 
     new StateCommandVisitor(), new UserSession(), DependencyResolver.Current.GetService<INotifier>())
 {
     _expenseReport = expenseReport;
     _command = command;
 }
        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));
        }
Exemplo n.º 16
0
 public ExpenseReport Build(Employee creator)
 {
     ExpenseReport expenseReport = new ExpenseReport();
     expenseReport.Number = _numberGenerator.GenerateNumber();
     expenseReport.Submitter = creator;
     expenseReport.CreatedDate = _calendar.GetCurrentTime();
     expenseReport.Status = ExpenseReportStatus.Draft;
     return expenseReport;
 }
        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));
        }
Exemplo n.º 18
0
        public virtual IStateCommand[] GetAllStateCommands(ExpenseReport expenseReport, Employee currentUser)
        {
            var commands = new List<IStateCommand>();
            commands.Add(new DraftingCommand(expenseReport, currentUser));
            commands.Add(new DraftToSubmittedCommand(expenseReport, currentUser));
            commands.Add(new SubmittedToApprovedCommand(expenseReport, currentUser));

            return commands.ToArray();
        }
 public void Save(ExpenseReport expenseReport)
 {
     using (ISession session = DataContext.GetTransactedSession())
     {
         ITransaction transaction = session.BeginTransaction();
         session.SaveOrUpdate(expenseReport);
         transaction.Commit();
     }
 }
 public ExecuteCommandResult(ExpenseReport expenseReport, string command, IWorkflowFacilitator facilitator, IStateCommandVisitor visitor, IUserSession session, INotifier notifier)
 {
     _expenseReport = expenseReport;
     _session = session;
     _notifier = notifier;
     _command = command;
     _facilitator = facilitator;
     _visitor = visitor;
 }
        public void ShouldBeValid()
        {
            var order = new ExpenseReport();
            order.Status = ExpenseReportStatus.Draft;
            var employee = new Employee();
            order.Submitter = employee;

            var command = new DraftToCancelledCommand();
            Assert.That(command.IsValid(new ExecuteTransitionCommand(order, null, employee, new DateTime())), Is.True);
        }
        public void ShouldNotBeValidInWrongStatus()
        {
            var order = new ExpenseReport();
            order.Status = ExpenseReportStatus.Submitted;
            var employee = new Employee();
            order.Submitter = employee;

            var command = new ApprovedToCancelledCommand();
            Assert.That(command.IsValid(new ExecuteTransitionCommand{Report = order, CurrentUser = employee}), Is.False);
        }
        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 order = new ExpenseReport();
            order.Status = ExpenseReportStatus.Submitted;
            var employee = new Employee();
            order.Submitter = employee;

            var command = new DraftingCommand();
            Assert.That(command.IsValid(new ExecuteTransitionCommand(order, null, employee, new DateTime())), Is.False);
        }
        public void ShouldNotBeValidWithWrongEmployee()
        {
            var report = new ExpenseReport();
            report.Status = ExpenseReportStatus.Draft;
            var employee = new Employee();
            report.Submitter = employee;

            var command = new DraftingCommand();
            Assert.That(command.IsValid(new ExecuteTransitionCommand(report, null, new Employee(), new DateTime())), 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 ShouldNotBeValidWithWrongEmployee()
        {
            var order = new ExpenseReport();
            order.Status = ExpenseReportStatus.Cancelled;
            var employee = new Employee();
            order.Approver = employee;

            var command = new DraftToCancelledCommand();
            Assert.That(command.IsValid(new ExecuteTransitionCommand(order, null, employee, new DateTime())), Is.False);
        }
        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 ShouldNotBeValidWithWrongApprover()
        {
            var order = new ExpenseReport();
            order.Status = ExpenseReportStatus.Submitted;
            var employee = new Employee();
            order.Approver = employee;
            var differentEmployee = new Employee();

            var command = new SubmittedToApprovedCommand();
            Assert.That(command.IsValid(new ExecuteTransitionCommand(order, null, differentEmployee, new DateTime())), Is.False);
        }
Exemplo n.º 30
0
 public void PropertiesShouldInitializeToProperDefaults()
 {
     var report = new ExpenseReport();
     Assert.That(report.Id, Is.EqualTo(Guid.Empty));
     Assert.That(report.Title, Is.EqualTo(string.Empty));
     Assert.That(report.Description, Is.EqualTo(string.Empty));
     Assert.That(report.Status, Is.EqualTo(ExpenseReportStatus.Draft));
     Assert.That(report.Number, Is.EqualTo(null));
     Assert.That(report.Submitter, Is.EqualTo(null));
     Assert.That(report.Approver, Is.EqualTo(null));
     Assert.That(report.GetAuditEntries().Length, Is.EqualTo(0));
 }
Exemplo n.º 31
0
 protected bool Equals(ExpenseReport other)
 {
     return(Id.Equals(other.Id));
 }
 public AuditEntry(Employee employee, DateTime date, ExpenseReportStatus beginStatus, ExpenseReportStatus endStatus, ExpenseReport report)
 {
     Employee         = employee;
     EmployeeName     = Employee.GetFullName();
     Date             = date;
     _beginStatusCode = beginStatus.Code;
     _endStatusCode   = endStatus.Code;
     ExpenseReport    = report;
 }