public void GetStudentsCountForGroupFromEvent() { #region Mock.DB_1_Entities.Groups Initialize var group1 = new Mock.DB1_Context.Group() { Id = Guid.NewGuid(), Name = "Group1" }; var group2 = new Mock.DB1_Context.Group() { Id = Guid.NewGuid(), Name = "Group2" }; #endregion #region Mock.DB_1_Entities.Students Initialize var student1 = new Mock.DB1_Context.Student() { Id = Guid.NewGuid(), Name = "Student1", Group = group1 }; var student2 = new Mock.DB1_Context.Student() { Id = Guid.NewGuid(), Name = "Student2", Group = group1 }; var student3 = new Mock.DB1_Context.Student() { Id = Guid.NewGuid(), Name = "Student3", Group = group2 }; #endregion var db1Adapter = new DB1Adapter(); db1Adapter.AddEntity <Group>(group1); db1Adapter.AddEntity <Group>(group2); db1Adapter.AddEntity <Student>(student1); db1Adapter.AddEntity <Student>(student2); db1Adapter.AddEntity <Student>(student3); db1Adapter.SaveChanges(); #region Mock.DB_2_Entities.Events Initialize var event1 = new Mock.DB2_Context.Event() { Id = Guid.NewGuid(), Name = "eventForGroup1", GroupName = group1.Name }; var event2 = new Mock.DB2_Context.Event() { Id = Guid.NewGuid(), Name = "eventForGroup2", GroupName = group2.Name }; #endregion var db2Adapter = new DB2Adapter(); db2Adapter.AddEntity <Event>(event1); db2Adapter.AddEntity <Event>(event2); db2Adapter.SaveChanges(); var cqContext = new CQContext(null, db1Adapter, db2Adapter); var result = cqContext.GetEntities <Mock.DomainModel.Event>().Where(e => e.ID == event1.Id).SelectMany(e => e.Group.Students).Count(); Assert.AreEqual(2, result); }
public void GetEventByGroupID_GroupFromDB1_EventFromDB2() { #region Mock.DB_1_Entities.Groups Initialize var group1 = new Mock.DB1_Context.Group() { Id = Guid.NewGuid(), Name = "Group1" }; var group2 = new Mock.DB1_Context.Group() { Id = Guid.NewGuid(), Name = "Group2" }; #endregion var db1Adapter = new DB1Adapter(); db1Adapter.AddEntity <Group>(group1); db1Adapter.AddEntity <Group>(group2); db1Adapter.SaveChanges(); #region Mock.DB_2_Entities.Events Initialize var event1 = new Mock.DB2_Context.Event() { Id = Guid.NewGuid(), Name = "eventForGroup1", GroupName = group1.Name }; var event2 = new Mock.DB2_Context.Event() { Id = Guid.NewGuid(), Name = "eventForGroup2", GroupName = group2.Name }; #endregion var db2Adapter = new DB2Adapter(); db2Adapter.AddEntity <Event>(event1); db2Adapter.AddEntity <Event>(event2); db2Adapter.SaveChanges(); var mapper = new Mapper.Mapper(); mapper.CreateConfiguration <Mock.DB1_Context.Group, Mock.DomainModel.Group>() .AddMap(s => s.Id, d => d.ID) .AddMap(s => s.Name, d => d.Name); mapper.CreateConfiguration <Mock.DB2_Context.Event, Mock.DomainModel.Event>() .AddMap(s => s.Id, d => d.ID) .AddMap(s => s.Name, d => d.Name); var cqContext = new CQContext(mapper, db1Adapter, db2Adapter); var result = cqContext.GetEntities <Mock.DomainModel.Event>().FirstOrDefault(e => e.Group.ID == group1.Id); Assert.IsNotNull(result, "Event not found"); Assert.AreEqual(event1.Id, result.ID, "Wrong event"); }