Exemplo n.º 1
0
        public void ShouldCascadeDeleteAuditEntries()
        {
            new DatabaseTester().Clean();

            var creator  = new Employee("1", "1", "1", "1");
            var assignee = new Employee("2", "2", "2", "2");
            var report   = new ExpenseReport();

            report.Submitter   = creator;
            report.Approver    = assignee;
            report.Title       = "foo";
            report.Description = "bar";
            report.ChangeStatus(ExpenseReportStatus.Approved);
            report.Number = "123";
            var auditEntry = new AuditEntry(creator, DateTime.Now, ExpenseReportStatus.Submitted,
                                            ExpenseReportStatus.Approved, report);

            report.AddAuditEntry(auditEntry);

            using (EfCoreContext context = new StubbedDataContextFactory().GetContext())
            {
                context.Add(creator);
                context.Add(assignee);
                context.Add(auditEntry);
                context.Add(report);
                context.SaveChanges();
            }

            ExpenseReport rehydratedExpenseReport;

            using (EfCoreContext context = new StubbedDataContextFactory().GetContext())
            {
                rehydratedExpenseReport = context.Set <ExpenseReport>()
                                          .Single(s => s.Id == report.Id);
                context.Entry(rehydratedExpenseReport).Collection(x => x.AuditEntries).Load();
            }

            rehydratedExpenseReport.AuditEntries.ToArray().Length.ShouldEqual(1);
            var entryId = rehydratedExpenseReport.AuditEntries.ToArray()[0].Id;

            using (EfCoreContext context = new StubbedDataContextFactory().GetContext())
            {
                context.Remove(rehydratedExpenseReport);
                context.SaveChanges();
            }

            using (EfCoreContext context = new StubbedDataContextFactory().GetContext())
            {
                context.Set <AuditEntry>().Count(entry => entry.Id == entryId).ShouldEqual(0);
                context.SaveChanges();
            }
        }
Exemplo n.º 2
0
        public void ShouldSaveAuditEntries()
        {
            new DatabaseTester().Clean();

            var creator  = new Employee("1", "1", "1", "1");
            var assignee = new Employee("2", "2", "2", "2");
            var report   = new ExpenseReport();

            report.Submitter   = creator;
            report.Approver    = assignee;
            report.Title       = "foo";
            report.Description = "bar";
            report.ChangeStatus(ExpenseReportStatus.Approved);
            report.Number = "123";
            var auditEntry = new AuditEntry(creator, DateTime.Now, ExpenseReportStatus.Submitted,
                                            ExpenseReportStatus.Approved, report);

            report.AddAuditEntry(auditEntry);

            using (EfCoreContext context = new StubbedDataContextFactory().GetContext())
            {
                context.Add(creator);
                context.Add(assignee);
                context.Add(auditEntry);
                context.Add(report);
                context.SaveChanges();
            }

            ExpenseReport rehydratedExpenseReport;

            using (EfCoreContext context = new StubbedDataContextFactory().GetContext())
            {
                rehydratedExpenseReport = context.Set <ExpenseReport>()
                                          .Single(s => s.Id == report.Id);
                context.Entry <ExpenseReport>(rehydratedExpenseReport).Collection(x => x.AuditEntries).Load();
            }

            var x1 = report.AuditEntries.ToArray()[0];
            var y1 = rehydratedExpenseReport.AuditEntries.ToArray()[0];

            Assert.That(y1.EndStatus, Is.EqualTo(x1.EndStatus));
        }