public void AddPersonTest()
        {
            using (var context = ContextAdapterFactory.CreateAdapter(new AdventureWorks2008R2Entities()))
            {
                using (var unitOfWork = new UnitOfWork(context.CreateObjectContext()))
                {
                    var personRepo         = new Repository <Person>(context);
                    var businessEntityRepo = new Repository <BusinessEntity>(context);

                    var businessEntity = new BusinessEntity()
                    {
                        rowguid      = Guid.NewGuid(),
                        ModifiedDate = DateTime.Now
                    };

                    var person = new Person()
                    {
                        BusinessEntity = businessEntity,
                        FirstName      = "Laurent",
                        LastName       = "Grangeau",
                        PersonType     = "GC",
                        rowguid        = Guid.NewGuid(),
                        ModifiedDate   = DateTime.Now
                    };

                    businessEntityRepo.Create(businessEntity);
                    personRepo.Create(person);

                    unitOfWork.Commit();
                }
            }
        }
        public void FirstPersonTest()
        {
            using (var context = ContextAdapterFactory.CreateAdapter(new AdventureWorks2008R2Entities()))
            {
                var personRepo = new Repository <Person>(context);
                var predicate  = PredicateBuilder.True <Person>();

                var person = personRepo.First(predicate);
                Assert.IsNotNull(person);
            }
        }
        public void ReadAllPersonTest()
        {
            using (var context = ContextAdapterFactory.CreateAdapter(new AdventureWorks2008R2Entities()))
            {
                // Arrange
                var personRepo = new Repository <Person>(context);

                // Act
                var person = personRepo.ReadAll(p => p.BusinessEntity);

                // Assert
                Assert.IsTrue(person.Count() == 20021);
            }
        }
        public void UpdatePersonWithNewBusinessEntityTest()
        {
            var dateNow = DateTime.Now;

            using (var context = ContextAdapterFactory.CreateAdapter(new AdventureWorks2008R2Entities()))
            {
                using (var unitOfWork = new UnitOfWork(context.CreateObjectContext()))
                {
                    // Arrange
                    var personRepo = new Repository <Person>(context);

                    var predicate = PredicateBuilder.True <Person>();
                    predicate = predicate.And(p => p.LastName.Equals("Rizzi"));
                    predicate = predicate.And(p => p.BusinessEntityID == 1695);

                    var person = personRepo.Single(predicate, p => p.BusinessEntity);

                    person.ModifiedDate   = dateNow;
                    person.BusinessEntity = new BusinessEntity {
                        ModifiedDate = dateNow
                    };

                    // Act
                    personRepo.Update(person);
                    unitOfWork.Commit();
                }
            }

            using (var context = ContextAdapterFactory.CreateAdapter(new AdventureWorks2008R2Entities()))
            {
                using (var unitOfWork = new UnitOfWork(context.CreateObjectContext()))
                {
                    // Arrange
                    var personRepo = new Repository <Person>(context);

                    var predicate = PredicateBuilder.True <Person>();
                    predicate = predicate.And(p => p.LastName.Equals("Rizzi"));
                    predicate = predicate.And(p => p.BusinessEntityID == 1695);

                    // Act
                    var person = personRepo.Single(predicate, p => p.BusinessEntity);

                    // Assert
                    Assert.IsNotNull(person);
                    Assert.AreEqual <DateTime>(dateNow, person.ModifiedDate);
                    Assert.AreEqual <DateTime>(dateNow, person.BusinessEntity.ModifiedDate);
                }
            }
        }
        public void ReadRessourceTest()
        {
            using (var entities = new FOOEntities())
            {
                using (var context = ContextAdapterFactory.CreateAdapter(entities))
                {
                    var repo      = new Repository <RessourceInt>(context);
                    var ressource = repo.ReadAll(BuildMereFilleInclusionsInt2().ToArray()).AsQueryable();

                    foreach (var item in ressource)
                    {
                        LoadIntObject(context, item);
                    }
                }
            }
        }
        public void SinglePersonTest()
        {
            using (var context = ContextAdapterFactory.CreateAdapter(new AdventureWorks2008R2Entities()))
            {
                var personRepo = new Repository <Person>(context);

                var predicate = PredicateBuilder.True <Person>();
                predicate = predicate.And(p => p.LastName.Equals("Grangeau"));
                predicate = predicate.And(p => p.BusinessEntityID == 20782);

                var person = personRepo.Single(predicate, p => p.BusinessEntity);
                var entId  = person.BusinessEntity.BusinessEntityID;

                Assert.IsNotNull(person);
            }
        }
        public void ReadPersonTest()
        {
            using (var context = ContextAdapterFactory.CreateAdapter(new AdventureWorks2008R2Entities()))
            {
                // Arrange
                var personRepo = new Repository <Person>(context);
                var predicate  = PredicateBuilder.Create <Person>(p => p.LastName.Equals("Grangeau"));
                predicate = predicate.And(p => p.BusinessEntityID == 20782);

                // Act
                var persons = personRepo.Read(predicate, p => p.BusinessEntity);

                // Assert
                Assert.IsNotNull(persons);
                Assert.IsTrue(persons.Any());
                Assert.IsNotNull(persons.Select(t => t.BusinessEntity));
            }
        }
        public void DeletePersonTest()
        {
            using (var context = ContextAdapterFactory.CreateAdapter(new AdventureWorks2008R2Entities()))
            {
                using (var unitOfWork = new UnitOfWork(context.CreateObjectContext()))
                {
                    var personRepo = new Repository <Person>(context);
                    var predicate  = PredicateBuilder.True <Person>();

                    predicate = predicate.And(p => p.LastName.Equals("Grangeau"));
                    predicate = predicate.And(p => p.BusinessEntityID == 20780);

                    var person = personRepo.First(predicate, p => p.BusinessEntity);

                    personRepo.Delete(person);
                    unitOfWork.Commit();
                }
            }
        }