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); }
public void ShouldRetrieveAllExpenseReports() { new DatabaseTester().Clean(); var report = new ExpenseReport { Title = "TestExpens", Description = "This is an ", Number = "123", Status = ExpenseReportStatus.Cancelled }; var report2 = new ExpenseReport { Title = "TestExpens", Description = "This is an ", Number = "123", Status = ExpenseReportStatus.Cancelled }; using (var context = new StubbedDataContextFactory().GetContext()) { context.AddRange(report, report2); context.SaveChanges(); } ListExpenseReportsHandler handler = new ListExpenseReportsHandler(new StubbedDataContextFactory().GetContext()); var expenseReports = handler.Handle(new ListExpenseReportsCommand()); expenseReports.Length.ShouldBe(2); expenseReports.ShouldContain(report); expenseReports.ShouldContain(report2); }
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 (EfCoreContext context = new StubbedDataContextFactory().GetContext()) { context.UpdateRange(employee, report); context.SaveChanges(); } var command = new ExecuteTransitionCommand(report, "Save Draft", 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 ShouldPersist() { new DatabaseTester().Clean(); var report = new ExpenseReport { Title = "TestExpens", Description = "This is an ", Number = "123", Status = ExpenseReportStatus.Cancelled }; using (var context = new StubbedDataContextFactory().GetContext()) { context.Add(report); context.SaveChanges(); } ExpenseReport rehydratedExpenseReport; using (var context = new StubbedDataContextFactory().GetContext()) { rehydratedExpenseReport = context.Find <ExpenseReport>(report.Id); } rehydratedExpenseReport.Title.ShouldBe(report.Title); rehydratedExpenseReport.Description.ShouldBe(report.Description); rehydratedExpenseReport.Number.ShouldBe(report.Number); rehydratedExpenseReport.Status.ShouldBe(report.Status); }
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(); } }
public void ShouldReproduceOwnedInstanceBug() { new DatabaseTester().Clean(); var employee = new Employee("jpalermo", "Jeffrey", "Palermo", "jeffrey @ clear dash measure.com"); using (var context = new StubbedDataContextFactory().GetContext()) { context.Add(employee); context.SaveChanges(); } var report = new ExpenseReport(); report.Number = "123"; report.Status = ExpenseReportStatus.Draft; report.Submitter = employee; report.Approver = employee; report.Total = 34; using (var context = new StubbedDataContextFactory().GetContext()) { context.Update(report); context.SaveChanges(); } var submitted = ExpenseReportStatus.Submitted; report.AddAuditEntry( new AuditEntry(employee, DateTime.Now, ExpenseReportStatus.Draft, submitted, report)); report.Status = submitted.Clone(); using (var context = new StubbedDataContextFactory().GetContext()) { context.Update(report); context.SaveChanges(); } using (var context = new StubbedDataContextFactory().GetContext()) { var statuses = new Dictionary <string, int>(); new SqlExecuter().ExecuteSql( "select count(1), status from ExpenseReport group by status" , reader => statuses.Add(reader.GetString(1), reader.GetInt32(0))); Assert.That(statuses["SBM"], Is.EqualTo(1)); } }
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); }
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)); }
public void ShouldResolveAndExecuteAHandler() { new DatabaseTester().Clean(); var report = new ExpenseReport { Title = "TestExpens", Description = "This is an ", Number = "123", Status = ExpenseReportStatus.Cancelled }; using (var context = new StubbedDataContextFactory().GetContext()) { context.AddRange(report); context.SaveChanges(); } var container = new DatabaseTester().GetContainer(); var bus = container.GetInstance <Bus>(); var reports = bus.Send(new ListExpenseReportsCommand());; reports.Length.ShouldBe(1); }
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 (EfCoreContext context = new StubbedDataContextFactory().GetContext()) { context.Add(expenseReportFact); context.SaveChanges(); } using (EfCoreContext context = new StubbedDataContextFactory().GetContext()) { var reportFact = context.Find <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 EfCoreMappingShouldPersist() { new DatabaseTester().Clean(); var one = new Employee("1", "first1", "last1", "email1"); using (EfCoreContext context = new StubbedDataContextFactory().GetContext()) { context.Add(one); context.SaveChanges(); } Employee rehydratedEmployee; using (EfCoreContext context = new StubbedDataContextFactory().GetContext()) { rehydratedEmployee = context.Find <Employee>(one.Id); } rehydratedEmployee.UserName.ShouldEqual(one.UserName); rehydratedEmployee.FirstName.ShouldEqual(one.FirstName); rehydratedEmployee.LastName.ShouldEqual(one.LastName); rehydratedEmployee.EmailAddress.ShouldEqual(one.EmailAddress); }
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)); }
public void PopulateDatabase() { new DatabaseTester().Clean(); EfCoreContext session = new StubbedDataContextFactory().GetContext(); //Trainer1 var jpalermo = new Employee(KnownEmployeeUsername, "Jeffrey", "Palermo", "*****@*****.**"); session.Add(jpalermo); //Person 1 //Person 2 //Person 3 var damian = new Employee("damian", "Damian", "Brady", "*****@*****.**"); session.Add(damian); //Person 4 var scott = new Employee("Scott Wilson", "Scott", "Wilson", "*****@*****.**"); session.Add(scott); //Person 5 //Person 6 var paul = new Employee("paul", "Paul", "Stovell", "*****@*****.**"); session.Add(paul); //Person 7 //Person 8 var steve = new Employee("Steve Hickman", "Steve", "Hickman", "*****@*****.**"); session.Add(steve); //Person 9 //Person 10 //Person 11 //Person 12 //Person 13 var hsimpson = new Employee("hsimpson", "Homer", "Simpson", "*****@*****.**"); session.Add(hsimpson); foreach (ExpenseReportStatus status in ExpenseReportStatus.GetAllItems()) { var report = new ExpenseReport(); report.Number = Guid.NewGuid().ToString().Substring(0, 5).ToUpper(); report.Submitter = jpalermo; report.Approver = jpalermo; report.Status = status; report.Title = "Expense report starting in status " + status; report.Description = "Foo, foo, foo, foo " + status; new DateTime(2000, 1, 1, 8, 0, 0); report.ChangeStatus(jpalermo, DateTime.Now, ExpenseReportStatus.Draft, ExpenseReportStatus.Draft); report.ChangeStatus(jpalermo, DateTime.Now, ExpenseReportStatus.Draft, ExpenseReportStatus.Submitted); report.ChangeStatus(jpalermo, DateTime.Now, ExpenseReportStatus.Submitted, ExpenseReportStatus.Approved); session.Add(report); } var report2 = new ExpenseReport(); report2.Number = KnownExpenseReportNumber; report2.Submitter = jpalermo; report2.Approver = jpalermo; report2.Status = ExpenseReportStatus.Draft; report2.Title = "Expense report starting in Draft status "; report2.Description = "Foo, foo, foo, foo "; new DateTime(2000, 1, 1, 8, 0, 0); session.Add(report2); session.SaveChanges(); session.Dispose(); }