public void Executive_Employee_Aggregate_Inherits_From_Person_Tests() { var context = new RepositoryContext(connectionName); context.RegisterCommandRepositoryFactory <PersonEntity>(() => new PersonCommandRepository()); context.RegisterCommandRepositoryFactory <EmployeeEntity>(() => new EmployeeCommandRepository()); context.RegisterCommandRepositoryFactory <ExecutiveEntity>(() => new ExecutiveCommandRepository()); // Insert var saveAggregate = new SaveExecutiveEmployeePersonCommandAggregate(context, firstName: "Allan", salary: 200000, bonus: 1000000); saveAggregate.Save(); var executiveEntity = saveAggregate.RootEntity; Assert.IsNotNull(executiveEntity.Id); var executiveId = executiveEntity.Id; // Read context.RegisterQueryRepository <ExecutiveEntity>(new ExecutiveQueryRepository()); context.RegisterQueryRepository <EmployeeEntity>(new EmployeeQueryRepository()); context.RegisterQueryRepository <PersonEntity>(new PersonQueryRepository()); var queryAggregate = new ExecutiveEmployeePersonQueryAggregate(context); queryAggregate.Get(executiveId, null); executiveEntity = queryAggregate.RootEntity; Assert.AreEqual(executiveId, executiveEntity.Id); Assert.AreEqual(1000000, executiveEntity.Bonus); Assert.AreEqual(200000, queryAggregate.Employee.Salary); Assert.AreEqual("Allan", queryAggregate.Person.FirstName); // Update saveAggregate.RootEntity.Bonus = 1100000; saveAggregate.Employee.Salary = 190000; saveAggregate.Person.FirstName = "Alejandro"; saveAggregate.Save(); // Read after update queryAggregate.Get(executiveId, null); executiveEntity = queryAggregate.RootEntity; Assert.AreEqual(executiveId, executiveEntity.Id); Assert.AreEqual(1100000, executiveEntity.Bonus); Assert.AreEqual(190000, queryAggregate.Employee.Salary); Assert.AreEqual("Alejandro", queryAggregate.Person.FirstName); // Delete var deleteAggregate = new DeleteExecutiveEmployeePersonCommandAggregate(context, executiveId); deleteAggregate.Save(); queryAggregate.Get(executiveId, null); Assert.IsNull(queryAggregate.RootEntity); }
public async Task Executive_Employee_Aggregate_Inherits_From_Person_Save_Async_Tests() { var context = new RepositoryContext(connectionName); context.RegisterCommandRepositoryFactory <PersonEntity>(() => new PersonCommandRepository()); context.RegisterCommandRepositoryFactory <EmployeeEntity>(() => new EmployeeCommandRepository()); context.RegisterCommandRepositoryFactory <ExecutiveEntity>(() => new ExecutiveCommandRepository()); // Insert var saveAggregate = new SaveExecutiveEmployeePersonCommandAggregate(context, firstName: "Scottish", salary: 175000, bonus: 900000); await saveAggregate.SaveAsync(); var executiveEntity = saveAggregate.RootEntity; Assert.IsNotNull(executiveEntity.Id); var executiveId = executiveEntity.Id; // Read context.RegisterQueryRepository <ExecutiveEntity>(new ExecutiveQueryRepository()); context.RegisterQueryRepository <EmployeeEntity>(new EmployeeQueryRepository()); context.RegisterQueryRepository <PersonEntity>(new PersonQueryRepository()); var queryAggregate = new ExecutiveEmployeePersonQueryAggregate(context); await queryAggregate.GetAsync(executiveId, null); executiveEntity = queryAggregate.RootEntity; Assert.AreEqual(executiveId, executiveEntity.Id); Assert.AreEqual(900000, executiveEntity.Bonus); Assert.AreEqual(175000, queryAggregate.Employee.Salary); Assert.AreEqual("Scottish", queryAggregate.Person.FirstName); // Update saveAggregate.RootEntity.Bonus = 1000000; saveAggregate.Employee.Salary = 180000; saveAggregate.Person.FirstName = "Scott"; await saveAggregate.SaveAsync(); // Read after update await queryAggregate.GetAsync(executiveId, null); executiveEntity = queryAggregate.RootEntity; Assert.AreEqual(executiveId, executiveEntity.Id); Assert.AreEqual(1000000, executiveEntity.Bonus); Assert.AreEqual(180000, queryAggregate.Employee.Salary); Assert.AreEqual("Scott", queryAggregate.Person.FirstName); // Delete var deleteAggregate = new DeleteExecutiveEmployeePersonCommandAggregate(context, executiveId); await deleteAggregate.SaveAsync(); queryAggregate.Get(executiveId, null); Assert.IsNull(queryAggregate.RootEntity); }