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); } }
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; var container = DependencyRegistrarModule.EnsureDependenciesRegistered(); var context = container.GetInstance <EfCoreContext>(); context.Update(report); context.SaveChanges(); var bus = container.GetInstance <Bus>(); for (var j = 0; j < commandsToRun.Length; j++) { var timestamp = startingDate.AddSeconds(j); var command = new ExecuteTransitionCommand(report, commandsToRun[j], employee, timestamp); bus.Send(command); } }
public void ShouldEagerFetchAssociations() { new DatabaseTester().Clean(); var employee = new Employee("1", "1", "1", "1"); var employee2 = new Employee("2", "2", "2", "2"); var employee3 = new Employee("3", "3", "3", "3"); var report1 = new ExpenseReport(); report1.Submitter = employee; report1.Approver = employee3; report1.Number = "123"; report1.ChangeStatus(employee2, DateTime.Now, ExpenseReportStatus.Draft, ExpenseReportStatus.Submitted); using (EfCoreContext context = new StubbedDataContextFactory().GetContext()) { context.Add(report1); context.SaveChanges(); } IContainer container = DependencyRegistrarModule.EnsureDependenciesRegistered(); var bus = container.GetInstance <Bus>(); ExpenseReport report123 = bus.Send(new ExpenseReportByNumberQuery { ExpenseReportNumber = "123" }).Result; Assert.That(report123.Id, Is.EqualTo(report1.Id)); report123.AuditEntries.Count().ShouldEqual(1); report123.AuditEntries.ToArray()[0].Employee.ShouldEqual(employee2); report123.Submitter.ShouldEqual(employee); report123.Approver.ShouldEqual(employee3); }
public void ShouldGetAllEmployees() { new DatabaseTester().Clean(); var one = new Employee("1", "first1", "last1", "email1"); var two = new Employee("2", "first2", "last2", "email2"); var three = new Employee("3", "first3", "last3", "email3"); using (EfCoreContext context = new StubbedDataContextFactory().GetContext()) { context.Add(one); context.Add(two); context.Add(three); context.SaveChanges(); } IContainer container = DependencyRegistrarModule.EnsureDependenciesRegistered(); var bus = container.GetInstance <Bus>(); Employee[] employees = bus.Send(EmployeeSpecificationQuery.All).Results; Assert.That(employees.Length, Is.EqualTo(3)); Assert.That(employees[0].UserName, Is.EqualTo("1")); Assert.That(employees[0].FirstName, Is.EqualTo("first1")); Assert.That(employees[0].LastName, Is.EqualTo("last1")); Assert.That(employees[0].EmailAddress, Is.EqualTo("email1")); }
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)); }
private static void Setup() { var employee = new Employee("jpalermo", "Jeffrey", "Palermo", "jeffrey @ clear dash measure.com"); var container = DependencyRegistrarModule.EnsureDependenciesRegistered(); var context = container.GetInstance <EfCoreContext>(); context.Update(employee); context.SaveChanges(); var startingDate = new DateTime(1974, 8, 4); for (var i = 0; i < 25; i++) { RunToDraft(new NumberGenerator().GenerateNumber(), employee, 13 * i, startingDate.AddMinutes(i), "Save Draft"); } for (var i = 0; i < 25; i++) { RunToDraft(new NumberGenerator().GenerateNumber(), employee, 13 * i, startingDate.AddMinutes(i), "Save Draft", "Submit"); } for (var i = 0; i < 25; i++) { RunToDraft(new NumberGenerator().GenerateNumber(), employee, 13 * i, startingDate.AddMinutes(i), "Save Draft", "Submit", "Approve"); } for (var i = 0; i < 25; i++) { RunToDraft(new NumberGenerator().GenerateNumber(), employee, 13 * i, startingDate.AddMinutes(i), "Save Draft", "Submit", "Approve"); } }
public void ShouldGetByNumber() { new DatabaseTester().Clean(); var employee = new Employee("1", "1", "1", "1"); var report1 = new ExpenseReport(); report1.Submitter = employee; report1.Number = "123"; var report2 = new ExpenseReport(); report2.Submitter = employee; report2.Number = "456"; using (EfCoreContext context = new StubbedDataContextFactory().GetContext()) { context.Add(employee); context.Add(report1); context.Add(report2); context.SaveChanges(); } IContainer container = DependencyRegistrarModule.EnsureDependenciesRegistered(); var bus = container.GetInstance <Bus>(); ExpenseReport report123 = bus.Send(new ExpenseReportByNumberQuery { ExpenseReportNumber = "123" }).Result; ExpenseReport report456 = bus.Send(new ExpenseReportByNumberQuery { ExpenseReportNumber = "456" }).Result; Assert.That(report123.Id, Is.EqualTo(report1.Id)); Assert.That(report456.Id, Is.EqualTo(report2.Id)); }
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 ShouldProveOwnedEntityMappingForStatus() { new DatabaseTester().Clean(); var employee = new Employee("1", "1", "1", "1"); var testTime = new DateTime(2015, 1, 1); var report = new ExpenseReport { Submitter = employee, Title = "TestExpenseReport", Description = "This is an expense report test", Number = "123", Total = 100.25m, Status = ExpenseReportStatus.Approved }; report.ChangeStatus(employee, testTime, ExpenseReportStatus.Submitted, ExpenseReportStatus.Approved); report.ChangeStatus(employee, testTime, ExpenseReportStatus.Approved, ExpenseReportStatus.Cancelled); var container = DependencyRegistrarModule.EnsureDependenciesRegistered(); var context = container.GetInstance <EfCoreContext>(); context.Add(report); context.SaveChanges(); IQueryable <AuditEntry> entries = context.Set <AuditEntry>().Include(x => x.ExpenseReport) .Include(x => x.Employee).Where(x => x.ExpenseReport.Id == report.Id); entries.Count().ShouldEqual(2); }
public void ShouldGetAllEmployees() { new DatabaseTester().Clean(); var one = new Employee("1", "first1", "last1", "email1"); var two = new Employee("2", "first2", "last2", "email2"); var three = new Employee("3", "first3", "last3", "email3"); using (ISession session = DataContext.GetTransactedSession()) { session.SaveOrUpdate(one); session.SaveOrUpdate(two); session.SaveOrUpdate(three); session.Transaction.Commit(); } IContainer container = DependencyRegistrarModule.EnsureDependenciesRegistered(); var bus = container.GetInstance <Bus>(); Employee[] employees = bus.Send(EmployeeSpecificationQuery.All).Results; Assert.That(employees.Length, Is.EqualTo(3)); Assert.That(employees[0].UserName, Is.EqualTo("1")); Assert.That(employees[0].FirstName, Is.EqualTo("first1")); Assert.That(employees[0].LastName, Is.EqualTo("last1")); Assert.That(employees[0].EmailAddress, Is.EqualTo("email1")); }
public void ShouldPersistMultipleInstancesOfSameEmployee() { new DatabaseTester().Clean(); var employee = new Employee("1", "1", "1", "1"); var report = new ExpenseReport { Submitter = employee, Approver = employee, Title = "TestExpenseReport", Description = "This is an expense report test", Number = "123", Total = 100.25m }; IContainer container = DependencyRegistrarModule.EnsureDependenciesRegistered(); EfCoreContext context = container.GetInstance <EfCoreContext>(); context.Add(report); context.SaveChanges(); Employee approver = container.GetInstance <EfCoreContext>().Find <Employee>(employee.Id); Employee submitter = container.GetInstance <EfCoreContext>().Find <Employee>(employee.Id); report.Approver = approver; report.Submitter = submitter; EfCoreContext context2 = container.GetInstance <EfCoreContext>(); context2.Update(report); context2.SaveChanges(); }
public void Should_resolve_interfaces() { var container = DependencyRegistrarModule.EnsureDependenciesRegistered(); var repository = container.GetInstance <IVisitorRepository>(); repository.ShouldNotBeNull(); repository.ShouldBeType <VisitorRepository>(); }
public void ShouldUseSameInstanceOfDataContextFactory() { IContainer container = DependencyRegistrarModule.EnsureDependenciesRegistered(); var factory1 = container.GetInstance <EfCoreContext>(); var factory2 = container.GetInstance <EfCoreContext>(); object.ReferenceEquals(factory1, factory2).ShouldBeTrue(); }
public void ShouldSave() { 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"; using (EfCoreContext context = new StubbedDataContextFactory().GetContext()) { context.Add(creator); context.Add(assignee); context.SaveChanges(); } IContainer container = DependencyRegistrarModule.EnsureDependenciesRegistered(); var bus = container.GetInstance <Bus>(); bus.Send(new ExpenseReportSaveCommand { ExpenseReport = report }); ExpenseReport rehydratedReport; using (EfCoreContext context = new StubbedDataContextFactory().GetContext()) { rehydratedReport = context.Find <ExpenseReport>(report.Id); context.Entry(rehydratedReport).Reference(x => x.Submitter).Load(); context.Entry(rehydratedReport).Reference(x => x.Approver).Load(); } rehydratedReport.Id.ShouldEqual(report.Id); rehydratedReport.Submitter.Id.ShouldEqual(report.Submitter.Id); rehydratedReport.Approver.Id.ShouldEqual(report.Approver.Id); rehydratedReport.Title.ShouldEqual(report.Title); rehydratedReport.Description.ShouldEqual(report.Description); rehydratedReport.Status.ShouldEqual(report.Status); rehydratedReport.Number.ShouldEqual(report.Number); }
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"; report.AddAuditEntry(new AuditEntry(creator, DateTime.Now, ExpenseReportStatus.Submitted, ExpenseReportStatus.Approved, report)); using (EfCoreContext context = new StubbedDataContextFactory().GetContext()) { context.Add(creator); context.Add(assignee); context.SaveChanges(); } IContainer container = DependencyRegistrarModule.EnsureDependenciesRegistered(); var bus = container.GetInstance <Bus>(); bus.Send(new ExpenseReportSaveCommand { ExpenseReport = report }); ExpenseReport rehydratedReport; using (EfCoreContext context = new StubbedDataContextFactory().GetContext()) { rehydratedReport = context.Find <ExpenseReport>(report.Id); context.Entry(rehydratedReport).Collection(r => r.AuditEntries).Load(); } var x = report.AuditEntries.ToArray()[0]; var y = rehydratedReport.AuditEntries.ToArray()[0]; y.EndStatus.ShouldEqual(x.EndStatus); y.BeginStatus.ShouldEqual(x.BeginStatus); y.EmployeeName.ShouldEqual(x.EmployeeName); }
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"; report.AddAuditEntry(new AuditEntry(creator, DateTime.Now, ExpenseReportStatus.Submitted, ExpenseReportStatus.Approved)); using (ISession session = DataContext.GetTransactedSession()) { session.SaveOrUpdate(creator); session.SaveOrUpdate(assignee); session.Transaction.Commit(); } IContainer container = DependencyRegistrarModule.EnsureDependenciesRegistered(); var bus = container.GetInstance <Bus>(); bus.Send(new ExpenseReportSaveCommand { ExpenseReport = report }); ExpenseReport rehydratedReport; using (ISession session2 = DataContext.GetTransactedSession()) { rehydratedReport = session2.Load <ExpenseReport>(report.Id); } var x = report.GetAuditEntries()[0]; var y = rehydratedReport.GetAuditEntries()[0]; y.EndStatus.ShouldEqual(x.EndStatus); y.BeginStatus.ShouldEqual(x.BeginStatus); y.EmployeeName.ShouldEqual(x.EmployeeName); }
public void ShouldCreateExpense() { new DatabaseTester().Clean(); var creator = new Employee("1", "1", "1", "1"); var assignee = new Employee("2", "2", "2", "2"); var report = new ExpenseReport { Submitter = creator, Approver = assignee, Title = "foo", Description = "bar", Number = "123" }; var request = new AddExpenseCommand { Report = report, CurrentUser = creator, Amount = 100.00m, Description = "foo", CurrentDate = new DateTime(2000, 1, 1) }; using (ISession session = DataContext.GetTransactedSession()) { session.SaveOrUpdate(assignee); session.SaveOrUpdate(creator); session.SaveOrUpdate(report); session.Transaction.Commit(); } IContainer container = DependencyRegistrarModule.EnsureDependenciesRegistered(); var bus = container.GetInstance <Bus>(); bus.Send(request); ExpenseReport loadedReport; using (ISession session = DataContext.GetTransactedSession()) { loadedReport = session.Load <ExpenseReport>(report.Id); } loadedReport.GetExpenses().Count().ShouldEqual(1); loadedReport.GetExpenses()[0].Amount.ShouldEqual(100); loadedReport.GetExpenses()[0].Description.ShouldEqual("foo"); }
public void ShouldSearchBySpecificationWithFullSpecification() { new DatabaseTester().Clean(); var employee1 = new Employee("1", "1", "1", "1"); var employee2 = new Employee("2", "2", "2", "2"); var order1 = new ExpenseReport(); order1.Submitter = employee2; order1.Approver = employee1; order1.Number = "123"; order1.Status = ExpenseReportStatus.Submitted; var order2 = new ExpenseReport(); order2.Submitter = employee1; order2.Approver = employee2; order2.Number = "456"; order2.Status = ExpenseReportStatus.Draft; using (ISession session = DataContext.GetTransactedSession()) { session.SaveOrUpdate(employee1); session.SaveOrUpdate(employee2); session.SaveOrUpdate(order1); session.SaveOrUpdate(order2); session.Transaction.Commit(); } var specification = new ExpenseReportSpecificationQuery() { Submitter = employee2, Approver = employee1, Status = ExpenseReportStatus.Submitted }; 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)); }
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); }
public void ShouldSearchBySpecificationWithStatus() { new DatabaseTester().Clean(); var employee1 = new Employee("1", "1", "1", "1"); var employee2 = new Employee("2", "2", "2", "2"); var order1 = new ExpenseReport(); order1.Submitter = employee2; order1.Approver = employee1; order1.Number = "123"; order1.Status = ExpenseReportStatus.Submitted; var order2 = new ExpenseReport(); order2.Submitter = employee1; order2.Approver = employee2; order2.Number = "456"; order2.Status = ExpenseReportStatus.Draft; using (EfCoreContext dbContext = new StubbedDataContextFactory().GetContext()) { dbContext.Add(employee1); dbContext.Add(employee2); dbContext.Add(order1); dbContext.Add(order2); dbContext.SaveChanges(); } var specification = new ExpenseReportSpecificationQuery() { Status = ExpenseReportStatus.Submitted }; 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)); }
public void ShouldFindMatchedEmployee() { new DatabaseTester().Clean(); var one = new Employee("1", "first1", "last1", "email1"); var two = new Employee("2", "first2", "last2", "email2"); var three = new Employee("3", "first3", "last3", "email3"); using (ISession session = DataContext.GetTransactedSession()) { session.SaveOrUpdate(one); session.SaveOrUpdate(two); session.SaveOrUpdate(three); session.Transaction.Commit(); } IContainer container = DependencyRegistrarModule.EnsureDependenciesRegistered(); var bus = container.GetInstance <Bus>(); SingleResult <Employee> result = bus.Send(new EmployeeByUserNameQuery("1")); result.Result.ShouldEqual(one); }
public void ShouldFindMatchedEmployee() { new DatabaseTester().Clean(); var one = new Employee("1", "first1", "last1", "email1"); var two = new Employee("2", "first2", "last2", "email2"); var three = new Employee("3", "first3", "last3", "email3"); using (EfCoreContext context = new StubbedDataContextFactory().GetContext()) { context.Add(one); context.Add(two); context.Add(three); context.SaveChanges(); } IContainer container = DependencyRegistrarModule.EnsureDependenciesRegistered(); var bus = container.GetInstance <Bus>(); SingleResult <Employee> result = bus.Send(new EmployeeByUserNameQuery("1")); result.Result.ShouldEqual(one); }
public void ShouldEagerFetchAssociations() { new DatabaseTester().Clean(); var employee1 = new Employee("1", "1", "1", "1"); var employee2 = new Employee("2", "2", "2", "2"); var report = new ExpenseReport(); report.Submitter = employee1; report.Approver = employee1; report.Number = "123"; report.ChangeStatus(employee2, DateTime.Now, ExpenseReportStatus.Draft, ExpenseReportStatus.Submitted);; using (EfCoreContext dbContext = new StubbedDataContextFactory().GetContext()) { dbContext.Add(employee1); dbContext.Add(report); dbContext.SaveChanges(); } var specification = new ExpenseReportSpecificationQuery() { Status = ExpenseReportStatus.Submitted }; 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(report.Id)); reports[0].Submitter.ShouldEqual(employee1); reports[0].Approver.ShouldEqual(employee1); reports[0].AuditEntries.ToArray()[0].Employee.ShouldEqual(employee2); }
public void ShouldSaveWithMultipleInstancesOfEmployee() { new ZDataLoader().PopulateDatabase(); IContainer container = DependencyRegistrarModule.EnsureDependenciesRegistered(); var bus = container.GetInstance <Bus>(); Employee approver = bus.Send(new EmployeeByUserNameQuery(ZDataLoader.KnownEmployeeUsername)).Result; Employee submitter = bus.Send(new EmployeeByUserNameQuery(ZDataLoader.KnownEmployeeUsername)).Result; ExpenseReport expenseReport = new ExpenseReport(); expenseReport.Number = ZDataLoader.KnownExpenseReportNumber; expenseReport.Submitter = submitter; expenseReport.Approver = approver; expenseReport.Title = "some title"; expenseReport.Description = "some descriptioni"; expenseReport.Total = 34; using (var context = container.GetInstance <EfCoreContext>()) { context.Update(expenseReport); context.SaveChanges(); } }
public void Clean() { DependencyRegistrarModule.Reset(); new DatabaseEmptier().DeleteAllData(); }