コード例 #1
0
        public void Should_Call_Fetch_Successfully()
        {
            using (var container = ContextScopeProvider.CreateChildContainer())
            {
                var repository = container.Resolve <IRepository>();

                var query = repository.AsQueryable <TestItemModel>().Where(q => q.Name == "Item1");
                query = new DefaultFetchingProvider().Fetch(query, q => q.Category);
                var result = query.ToList();

                Assert.IsNotNull(result);
                Assert.AreEqual(result.Count, 1);
                Assert.IsNotNull(result[0].Category);
                Assert.AreEqual(result[0].Category.Name, "ItemCategory1");
            }
        }
        public void Should_Call_Fetch_Successfully()
        {
            using (var container = ContextScopeProvider.CreateChildContainer())
            {
                var repository = container.Resolve<IRepository>();

                var query = repository.AsQueryable<TestItemModel>().Where(q => q.Name == "Item1");
                query = new DefaultFetchingProvider().Fetch(query, q => q.Category);
                var result = query.ToList();

                Assert.IsNotNull(result);
                Assert.AreEqual(result.Count, 1);
                Assert.IsNotNull(result[0].Category);
                Assert.AreEqual(result[0].Category.Name, "ItemCategory1");
            }
        }
コード例 #3
0
        public void Should_Call_ThenFetchMany_Successfully()
        {
            using (var container = ContextScopeProvider.CreateChildContainer())
            {
                var repository = container.Resolve <IRepository>();

                var query = repository.AsQueryable <TestItemModelChild>().Where(q => q.Name == "Item1 Child1");

                IFetchRequest <TestItemModelChild, TestItemModel> query1 = new DefaultFetchingProvider().Fetch(query, q => q.Item);
                query = new DefaultFetchingProvider().ThenFetchMany(query1, q => q.Children);

                var result = query.ToList();

                Assert.IsNotNull(result);
                Assert.AreEqual(result.Count, 1);
                Assert.IsNotNull(result[0].Item);
                Assert.AreEqual(result[0].Item.Name, "Item1");
                Assert.IsNotNull(result[0].Item.Children);
                Assert.AreEqual(result[0].Item.Children.Count, 2);
                Assert.IsTrue(result[0].Item.Children.Any(c => c.Name == "Item1 Child1"));
                Assert.IsTrue(result[0].Item.Children.Any(c => c.Name == "Item1 Child2"));
            }
        }
        public void Should_Call_ThenFetchMany_Successfully()
        {
            using (var container = ContextScopeProvider.CreateChildContainer())
            {
                var repository = container.Resolve<IRepository>();

                var query = repository.AsQueryable<TestItemModelChild>().Where(q => q.Name == "Item1 Child1");

                IFetchRequest<TestItemModelChild, TestItemModel> query1 = new DefaultFetchingProvider().Fetch(query, q => q.Item);
                query = new DefaultFetchingProvider().ThenFetchMany(query1, q => q.Children);

                var result = query.ToList();

                Assert.IsNotNull(result);
                Assert.AreEqual(result.Count, 1);
                Assert.IsNotNull(result[0].Item);
                Assert.AreEqual(result[0].Item.Name, "Item1");
                Assert.IsNotNull(result[0].Item.Children);
                Assert.AreEqual(result[0].Item.Children.Count, 2);
                Assert.IsTrue(result[0].Item.Children.Any(c => c.Name == "Item1 Child1"));
                Assert.IsTrue(result[0].Item.Children.Any(c => c.Name == "Item1 Child2"));
            }
        }