Ejemplo n.º 1
0
        public void LazyLoad_Set_To_False()
        {
            dbContext.Configuration.LazyLoadingEnabled = false;
            var repository = new MyEfRepository(dbContext);

            repository.LazyLoadValue.ShouldBeFalse();
        }
Ejemplo n.º 2
0
        public void LazyLoad_Set_To_False()
        {
            var dbPath = EfDataDirectoryFactory.Build();

            Database.DefaultConnectionFactory = new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0");

            var dbContext = new TestObjectEntities("Data Source=" + dbPath);

            dbContext.Configuration.LazyLoadingEnabled = false;

            var repos = new MyEfRepository(dbContext);

            repos.LazyLoadValue.ShouldBeFalse();
        }
Ejemplo n.º 3
0
        public void GetAll_Without_Includes_LazyLoads_Email()
        {
            dbContext.Configuration.LazyLoadingEnabled = true;
            dbContext.Database.Log = sql =>
            {
                if (sql.Contains("SELECT"))
                {
                    queries.Add(sql);
                }
            };
            var repository = new MyEfRepository(dbContext);

            var contact = repository.GetAll().First();

            contact.Name.ShouldEqual("Test User 1");
            queries.Count().ShouldEqual(1);
            contact.EmailAddresses.First().Email.ShouldEqual("*****@*****.**");
            queries.Count().ShouldEqual(2);
        }
Ejemplo n.º 4
0
        public void GetAll_With_Text_Include_And_Pagination_LazyLoads_Email()
        {
            dbContext.Configuration.LazyLoadingEnabled = true;
            dbContext.Database.Log = sql =>
            {
                if (sql.Contains("SELECT"))
                {
                    queries.Add(sql);
                }
            };
            var repository = new MyEfRepository(dbContext);

            var pagination = new PagingOptions <Contact>(1, 4, "ContactId");

            var contact = repository.GetAll(pagination, "EmailAddresses").First();

            contact.Name.ShouldEqual("Test User 1");
            queries.Count().ShouldEqual(2); // first query is count for total records
            contact.EmailAddresses.First().Email.ShouldEqual("*****@*****.**");
            queries.Count().ShouldEqual(2);
        }
Ejemplo n.º 5
0
        public void FindAll_With_Include_And_Predicate_In_Specs_LazyLoads_Email()
        {
            dbContext.Configuration.LazyLoadingEnabled = true;
            dbContext.Database.Log = sql =>
            {
                if (sql.Contains("SELECT"))
                {
                    queries.Add(sql);
                }
            };
            var repository = new MyEfRepository(dbContext);

            var findAllBySpec = new Specification <Contact>(obj => obj.ContactId == "1")
                                .And(obj => obj.EmailAddresses.Any(m => m.Email == "*****@*****.**"));

            var specification = new Specification <Contact>(obj => obj.Name == "Test User 1");

            findAllBySpec.FetchStrategy = new GenericFetchStrategy <Contact>();
            findAllBySpec.FetchStrategy
            .Include(obj => obj.EmailAddresses);

            // NOTE: This line will erase my FetchStrategy from above
            if (null != specification)
            {
                findAllBySpec = findAllBySpec.And(specification);
            }

            var contact = repository.FindAll(findAllBySpec).First();

            contact.Name.ShouldEqual("Test User 1");
            queries.Count().ShouldEqual(1); // first query is count for total records
            contact.EmailAddresses.First().Email.ShouldEqual("*****@*****.**");
            queries.Count().ShouldEqual(1);

            repository.FindAll(findAllBySpec).Count().ShouldEqual(1);
        }
Ejemplo n.º 6
0
        public void GetAll_With_Includes_In_Strategy_LazyLoads_Email()
        {
            dbContext.Configuration.LazyLoadingEnabled = true;
            dbContext.Database.Log = sql =>
            {
                if (sql.Contains("SELECT"))
                {
                    queries.Add(sql);
                }
            };
            var repository = new MyEfRepository(dbContext);


            var strategy = new GenericFetchStrategy <Contact>();

            strategy.Include(x => x.EmailAddresses);

            var contact = repository.GetAll(strategy).First();

            contact.Name.ShouldBe("Test User 1");
            queries.Count().ShouldBe(1);
            contact.EmailAddresses.First().Email.ShouldBe("*****@*****.**");
            queries.Count().ShouldBe(1);
        }