Esempio n. 1
0
        public void ShouldPersist()
        {
            new DatabaseTester().Clean();

            var      one            = new Manager("username", "Endurance", "Idehen", "Email");
            Employee adminAssistant = new Employee("Assistant", "Someone", "Else", "Email2");

            one.AdminAssistant = adminAssistant;
            using (EfCoreContext context = new StubbedDataContextFactory().GetContext())
            {
                context.Add(one);
                context.Add(adminAssistant);
                context.SaveChanges();
            }

            Manager rehydratedEmployee;

            using (EfCoreContext context = new StubbedDataContextFactory().GetContext())
            {
                rehydratedEmployee = context.Set <Manager>().Include(x => x.AdminAssistant).Single(x => x.Id == one.Id);
            }

            rehydratedEmployee.UserName.ShouldEqual(one.UserName);
            rehydratedEmployee.FirstName.ShouldEqual(one.FirstName);
            rehydratedEmployee.LastName.ShouldEqual(one.LastName);
            rehydratedEmployee.EmailAddress.ShouldEqual(one.EmailAddress);
            rehydratedEmployee.AdminAssistant.ShouldEqual(adminAssistant);
        }
Esempio n. 2
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();
            }
        }
Esempio n. 3
0
        public void ShouldPersitAuditEntry()
        {
            // Clean the database
            new DatabaseTester().Clean();
            // Make employees
            var employee = new Employee("1", "1", "1", "1");
            var testTime = new DateTime(2015, 1, 1);
            // popluate ExpenseReport
            var report = new ExpenseReport
            {
                Submitter   = employee,
                Title       = "TestExpenseReport",
                Description = "This is an expense report test",
                Number      = "123",
                Total       = 100.25m
            };
            var entry = new AuditEntry(employee, testTime, ExpenseReportStatus.Approved, ExpenseReportStatus.Cancelled,
                                       report);

            entry.ExpenseReport = report;


            using (var context = new StubbedDataContextFactory().GetContext())
            {
                context.Add(employee);
                context.Add(report);
                context.Add(entry);
                context.SaveChanges();
            }

            AuditEntry rehydratedEntry;

            using (var context = new StubbedDataContextFactory().GetContext())
            {
                rehydratedEntry = context.Set <AuditEntry>().Include(x => x.ExpenseReport)
                                  .Include(x => x.Employee).Single(x => x.Id == entry.Id);
            }

            rehydratedEntry.Employee.ShouldEqual(employee);
            rehydratedEntry.ExpenseReport.ShouldEqual(report);
            rehydratedEntry.BeginStatus.ShouldEqual(ExpenseReportStatus.Approved);
            rehydratedEntry.EndStatus.ShouldEqual(ExpenseReportStatus.Cancelled);
            rehydratedEntry.Date.ShouldEqual(testTime);
        }
Esempio n. 4
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));
        }
Esempio n. 5
0
        public void ShouldSaveExpenseReport()
        {
            new DatabaseTester().Clean();
            var report = new ExpenseReport
            {
                Title       = "TestExpense",
                Description = "This is an ",
                Number      = "000000",
                Status      = ExpenseReportStatus.Cancelled
            };
            var handler = new NewExpenseReportsHandler(new StubbedDataContextFactory().GetContext());

            var command   = new NewExpenseReportCommand(report);
            var newReport = handler.Handle(command);

            using (var context = new StubbedDataContextFactory().GetContext())
            {
                var savedReport = context.Set <ExpenseReport>()
                                  .Single(expenseReport => expenseReport.Number == "000000");
                savedReport.Number.ShouldBe(newReport.Number);
            }
        }
Esempio n. 6
0
        public void ShouldSaveExpenseReportWithNewProperties()
        {
            // Clean the database
            new DatabaseTester().Clean();
            // Make employees
            var      submitter = new Employee("1", "1", "1", "1");
            var      approver  = new Employee("2", "2", "2", "2");
            DateTime testTime  = new DateTime(2015, 1, 1);
            // popluate ExpenseReport
            var report = new ExpenseReport
            {
                Submitter      = submitter,
                Approver       = approver,
                Title          = "TestExpenseReport",
                Description    = "This is an expense report test",
                Number         = "123",
                MilesDriven    = 100,
                Created        = testTime,
                FirstSubmitted = testTime,
                LastSubmitted  = testTime,
                LastWithdrawn  = testTime,
                LastCancelled  = testTime,
                LastApproved   = testTime,
                LastDeclined   = testTime,
                Total          = 100.25m
            };

            report.ChangeStatus(ExpenseReportStatus.Approved);
            var auditEntry = new AuditEntry(submitter, DateTime.Now, ExpenseReportStatus.Submitted,
                                            ExpenseReportStatus.Approved, report);

            report.AddAuditEntry(auditEntry);

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

            ExpenseReport rehydratedExpenseReport;

            using (EfCoreContext context = new StubbedDataContextFactory().GetContext())
            {
                rehydratedExpenseReport = context.Set <ExpenseReport>().Include(x => x.Approver)
                                          .Include(x => x.Submitter).Single(x => x.Id == report.Id);
            }

            rehydratedExpenseReport.Approver.ShouldEqual(approver);
            rehydratedExpenseReport.Submitter.ShouldEqual(submitter);
            rehydratedExpenseReport.Title.ShouldEqual("TestExpenseReport");
            rehydratedExpenseReport.Description.ShouldEqual("This is an expense report test");
            rehydratedExpenseReport.Number.ShouldEqual("123");
            rehydratedExpenseReport.Status.ShouldEqual(ExpenseReportStatus.Approved);
            Assert.That(rehydratedExpenseReport.MilesDriven, Is.EqualTo(report.MilesDriven));
            Assert.That(rehydratedExpenseReport.Created, Is.EqualTo(report.Created));
            Assert.That(rehydratedExpenseReport.FirstSubmitted, Is.EqualTo(report.FirstSubmitted));
            Assert.That(rehydratedExpenseReport.LastSubmitted, Is.EqualTo(report.LastSubmitted));
            Assert.That(rehydratedExpenseReport.LastWithdrawn, Is.EqualTo(report.LastWithdrawn));
            Assert.That(rehydratedExpenseReport.LastCancelled, Is.EqualTo(report.LastCancelled));
            Assert.That(rehydratedExpenseReport.LastApproved, Is.EqualTo(report.LastApproved));
            Assert.That(rehydratedExpenseReport.LastDeclined, Is.EqualTo(report.LastDeclined));
            Assert.That(rehydratedExpenseReport.Total, Is.EqualTo(report.Total));
        }