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);
            }
        }
コード例 #2
0
        public void ShouldCreateExpenseReportFact()
        {
            new DatabaseTester().Clean();

            var fact = new ExpenseReportFact()
            {
                Approver = "",
                Id = Guid.NewGuid(),
                Number = "1",
                Status = "Submitter",
                Submitter = "Me",
                TimeStamp = new DateTime(2015,01,01),
                Total = 123.456m,
            };
        
            var command = new AddExpenseReportFactCommand(fact);
            var handler = new AddExpenseReportFactHandler();
            handler.Handle(command);

            using (ISession session = DataContext.GetTransactedSession())
            {
                var facts = session.CreateCriteria<ExpenseReportFact>().List<ExpenseReportFact>();
                Assert.That(facts.Count, Is.EqualTo(1));
            }
        }
        public void ShouldPersistExportReportFact()
        {
            new DatabaseTester().Clean();
            var employee = new Employee("somethingelse", "Jeffrey", "Palermo", "jeffrey @ clear dash measure.com");
            employee.Id = Guid.NewGuid();
            var report = new ExpenseReport
            {
                Number = "123",
                Status = ExpenseReportStatus.Draft,
                Submitter = employee
            };

            DateTime setDate = new DateTime(2015, 1, 1);
            ExpenseReportFact expenseReportFact = new ExpenseReportFact(report, setDate);

            var command = new AddExpenseReportFactCommand(expenseReportFact);

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

            bus.Send(command);

            using (ISession session = DataContext.GetTransactedSession())
            {
                session.Save(expenseReportFact);
                session.Transaction.Commit();
            }

            ExpenseReportFact reHydratedExpenseReportFact;

            using (ISession session = DataContext.GetTransactedSession())
            {
                reHydratedExpenseReportFact = session.Load<ExpenseReportFact>(expenseReportFact.Id);
            }

            reHydratedExpenseReportFact.Approver.ShouldEqual(expenseReportFact.Approver);
            reHydratedExpenseReportFact.Number.ShouldEqual(expenseReportFact.Number);
            reHydratedExpenseReportFact.Status.ShouldEqual(expenseReportFact.Status);
            reHydratedExpenseReportFact.Submitter.ShouldEqual(expenseReportFact.Submitter);
            reHydratedExpenseReportFact.TimeStamp.ShouldEqual(expenseReportFact.TimeStamp);
            reHydratedExpenseReportFact.Total.ShouldEqual(expenseReportFact.Total);
        }