Example #1
0
        public static void SetupTheDatabase(TestContext testContext)
        {
            _connection = Effort.DbConnectionFactory.CreateTransient();

            using (var uow = new TestDbContext(_connection))
            {
                var company1 = uow.Companies.Add(new Company
                {
                    Name = "Company 1",
                    Address = new CompanyAddress() { Id = 1, Street = "Campinho" },
                    Contacts = new List<CompanyContactBase>
                    {
                        new CompanyContact
                        {
                            FirstName = "Bob",
                            LastName = "Brown",
                            Infos = new List<ContactInfo>
                            {
                                new ContactInfo
                                {
                                    Description = "Home",
                                    Email = "*****@*****.**",
                                    PhoneNumber = "0255525255"
                                }
                            }
                        }
                    },
                });

                var company2 = uow.Companies.Add(new Company
                {
                    Name = "Company 2",
                    Contacts = new List<CompanyContactBase>
                    {
                        new CompanyContact
                        {
                            FirstName = "Tim",
                            LastName = "Jones",
                            Infos = new List<ContactInfo>
                            {
                                new ContactInfo
                                {
                                    Description = "Work",
                                    Email = "*****@*****.**",
                                    PhoneNumber = "456456456456"
                                }
                            }
                        }
                    }
                });

                var project1 = uow.Projects.Add(new Project
                {
                    Name = "Major Project 1",
                    Deadline = DateTime.Now,
                    Stakeholders = new List<Company> { company2 }
                });

                var project2 = uow.Projects.Add(new Project
                {
                    Name = "Major Project 2",
                    Deadline = DateTime.Now,
                    Stakeholders = new List<Company> { company1 }
                });

                var manager1 = uow.Managers.Add(new Manager
                {
                    PartKey = "manager1",
                    PartKey2 = 1,
                    FirstName = "Trent"
                });
                var manager2 = uow.Managers.Add(new Manager
                {
                    PartKey = "manager2",
                    PartKey2 = 2,
                    FirstName = "Timothy"
                });

                var employee = new Employee
                {
                    Manager = manager1,
                    Key = "Asdf",
                    FirstName = "Test employee",
                };

                uow.Employees.Add(employee);

                project2.LeadCoordinator = manager2;

                uow.Commit();
            }
        }
Example #2
0
        public void EnsureWeCanUseCyclicRelationsOnOwnedCollections()
        {
            Manager manager;
            using (var uow = new TestDbContext(_connection))
            {
                manager = uow.Managers.Include(p => p.Employees).First();

                var newEmployee = new Employee {Key = "assdf", FirstName = "Test Employee", Manager = manager};
                manager.Employees.Add(newEmployee);

                uow.Commit();
            }
            using (var uow = new TestDbContext(_connection))
            {
                Assert.AreEqual(manager.FirstName, uow.Employees.Include(p => p.Manager).Single(p => p.Key == "assdf").Manager.FirstName);
            }
            using (var uow = new TestDbContext(_connection))
            {
                Assert.AreEqual("Test Employee", uow.Managers.Include(p => p.Employees).Single(p => p.PartKey == manager.PartKey).Employees.Single(p => p.Key == "assdf").FirstName);
            }
        }