コード例 #1
0
        public void EntityDeleteTestForEagerLoad()
        {
            using (var testRep = new TestRepository())
            {
                testRep.Database.Delete();
            }

            using (ITestRepository testRep = new TestRepository())
            {
                var personOne = new Person {Name = "PersonOne"};
                var personTwo = new Person { Name = "PersonTwo" };
                var personThree = new Person { Name = "PersonThree" };

                var addressHome = new Address
                    {
                        Street = "HomeStreet",
                        Persons = new List<Person> {personOne, personTwo, personThree}
                    };
                Assert.IsTrue(addressHome.Persons.Count == 3, "Soft delete test failed expectation");

                testRep.Add(addressHome);
                testRep.SaveChanges();
            }

            using (ITestRepository testRep = new TestRepository())
            {
                var personOne = testRep.Query<Person>(p => p.Name == "PersonOne").FirstOrDefault();
                var addressHome = testRep.Query<Address>(a => a.Street.Contains("HomeStreet"), a => a.Persons).FirstOrDefault();
                Assert.IsTrue(addressHome.Persons.Count == 3, "Soft delete test failed expectation");
                testRep.Delete(personOne);
                testRep.SaveChanges();
            }

            using (ITestRepository testRep = new TestRepository())
            {
                var addressHome = testRep.Query<Address>(a => a.Street.Contains("HomeStreet"), a => a.Persons).FirstOrDefault();
                if (addressHome == null) throw new Exception("Soft delete test failed, addressHome is null");
                Assert.IsTrue(addressHome.Persons.Count == 2, "Soft delete test failed expectation");
            }

        }
コード例 #2
0
        public void EntityVesrsionTestWithAutoIncrement()
        {
            using (var testRep = new TestRepository())
            {
                testRep.Database.Delete();
            }

            using (ITestRepository testRep = new TestRepository())
            {
                testRep.Add(new Address { Street = "HomeStreet" });
                testRep.SaveChanges();
            }

            using (ITestRepository testRep = new TestRepository())
            {
                var address = testRep.Query<Address>(a => a.Street == "HomeStreet").FirstOrDefault();
                Assert.IsTrue(address != null && address.VersionNo == 1);
            }

            using (ITestRepository testRep = new TestRepository())
            {
                var address = testRep.Query<Address>(a => a.Street == "HomeStreet").FirstOrDefault();
                if (address != null)
                {
                    address.Street = "HomeStreet02";
                }
                testRep.SaveChanges();

                Assert.IsTrue(address != null && address.VersionNo == 2);
            }

            using (ITestRepository testRep = new TestRepository())
            {

                Assert.IsTrue(testRep.Query<Address>(a => a.Street.Contains("Street")).Count() == 1);
                var address = testRep.Query<Address>(a => a.Street == "HomeStreet02").FirstOrDefault();
                Assert.IsTrue(address != null && address.VersionNo == 2);
            }
        }
コード例 #3
0
        public void EntityVesrsionTestWithRelatioship()
        {
            using (var testRep = new TestRepository())
            {
                testRep.Database.Delete();
            }

            using (ITestRepository testRep = new TestRepository())
            {
                testRep.Add(new Address { Street = "HomeStreet" });
                testRep.SaveChanges();
            }

            using (ITestRepository testRep = new TestRepository())
            {
                var address = testRep.Query<Address>(a => a.Street == "HomeStreet").FirstOrDefault();
            }

            using (ITestRepository testRep = new TestRepository())
            {
                var address = testRep.Query<Address>(a => a.Street == "HomeStreet").FirstOrDefault();
                if (address != null)
                {
                    address.Street = "HomeStreet02";
                }
                testRep.SaveChanges();
            }

            using (ITestRepository testRep = new TestRepository())
            {
                Assert.IsTrue(testRep.Query<Address>(a => a.Street.Contains("Street")).Count() == 1);
                var address = testRep.Query<Address>(a => a.Street == "HomeStreet02").FirstOrDefault();
                address.Persons = new List<Person> { new Person { Name = "PersonOne" }, new Person { Name = "Persontwo" }, new Person { Name = "Personthree" } };
                testRep.SaveChanges();

            }
            using (ITestRepository testRep = new TestRepository())
            {
                Assert.IsTrue(testRep.Query<Address>(a => a.Street.Contains("Street")).Count() == 1);
                var address = testRep.Query<Address>(a => a.Street == "HomeStreet02").FirstOrDefault();
                Assert.IsTrue(address != null && address.VersionNo == 2);
            }
        }
コード例 #4
0
        public void EntityDeleteTestForQuery()
        {
            using (var testRep = new TestRepository())
            {
                testRep.Database.Delete();
            }

            using (IRepository testRep = new TestRepository())
            {
                var personOne = new Person { Name = "PersonOne" };
                var personTwo = new Person { Name = "PersonTwo" };
                var personThree = new Person { Name = "PersonThree" };

                var addressHome = new Address
                {
                    Street = "HomeStreet",
                    Persons = new List<Person> { personOne, personTwo, personThree }
                };
                Assert.IsTrue(addressHome.Persons.Count == 3, "Soft delete test failed expectation");

                testRep.Add(addressHome);
                testRep.SaveChanges();
            }

            using (ITestRepository testRep = new TestRepository())
            {
                var personOne = testRep.Query<Person>(p => p.Name == "PersonOne").FirstOrDefault();
                Assert.IsNotNull(personOne, "Soft delete test failed expectation");
                testRep.Delete(personOne);
                testRep.SaveChanges();
            }

            using (ITestRepository testRep = new TestRepository())
            {
                var personOne = testRep.Query<Person>(p => p.Name == "PersonOne").FirstOrDefault();
                Assert.IsNull(personOne, "Soft delete test failed expectation");
            }
        }
コード例 #5
0
        public void EntityVesrsionRetrivalInObjectGraph()
        {
            using (var testRep = new TestRepository())
            {
                testRep.Database.Delete();
            }

            using (ITestRepository testRep = new TestRepository())
            {
                testRep.Add(new Address { Street = "HomeStreet" });
                testRep.SaveChanges();
            }

            using (ITestRepository testRep = new TestRepository())
            {
                var address = testRep.Query<Address>(a => a.Street == "HomeStreet").FirstOrDefault();
            }

            using (ITestRepository testRep = new TestRepository())
            {
                var address = testRep.Query<Address>(a => a.Street == "HomeStreet").FirstOrDefault();
                if (address != null)
                {
                    address.Street = "HomeStreet02";
                }
                testRep.SaveChanges();
            }

            using (ITestRepository testRep = new TestRepository())
            {
                Assert.IsTrue(testRep.Query<Address>(a => a.Street.Contains("Street")).Count() == 1);
                var address = testRep.Query<Address>(a => a.Street == "HomeStreet02").FirstOrDefault();
                address.Persons = new List<Person> { new Person { Name = "PersonOne" }, new Person { Name = "Persontwo" }, new Person { Name = "Personthree" } };
                testRep.SaveChanges();

            }
            using (ITestRepository testRep = new TestRepository())
            {

                var address = testRep.Query<Address>(a => a.Street.Contains("Street")).FirstOrDefault();
                address.Street = "HomeStreet03";
                testRep.SaveChanges();
            }


            using (ITestRepository testRep = new TestRepository())
            {

                var person = testRep.Query<Person>(p => p.Name.Contains("PersonOne"), p => p.Address).FirstOrDefault();
                Assert.IsTrue(person.Address.Street == "HomeStreet02");
                testRep.SaveChanges();
            }

        }