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 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 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 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 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 (EfCoreContext dbContext = new StubbedDataContextFactory().GetContext()) { dbContext.Add(employee1); dbContext.Add(employee2); dbContext.Add(order1); dbContext.Add(order2); dbContext.SaveChanges(); } 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 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); }