public void Apply_GivenPropertyWithObject_ThenNotNull()
        {
            var pipe = new IncludePropertyThenQueryPipe <OrderDetail, Order, Customer>(order => order.Customer, false);

            using var fixture = new NorthwindQueryInMemoryFixture <NoopModelCustomizer>();
            using var context = fixture.CreateContext();

            var queryRoot = context.Set <OrderDetail>().Include(detail => detail.Order);

            var before = queryRoot;

            Assert.NotEmpty(before);
            Assert.All(before, detail =>
            {
                Assert.NotNull(detail.Order);
                Assert.Null(detail.Order.Customer);
            });

            var after = pipe.Apply(queryRoot).ToList();

            Assert.NotEmpty(after);
            Assert.All(after, detail =>
            {
                Assert.NotNull(detail.Order);
                Assert.NotNull(detail.Order.Customer);
            });
        }
        public void Apply_GivenPropertyWithCollection_ThenNotNull()
        {
            var pipe = new IncludePropertyThenQueryPipe <Product, OrderDetail, Order>(detail => detail.Order, true);

            using var fixture = new NorthwindQueryInMemoryFixture <NoopModelCustomizer>();
            using var context = fixture.CreateContext();

            var queryRoot = context.Set <Product>().Include(product => product.OrderDetails);

            var before = queryRoot;

            Assert.NotEmpty(before);
            Assert.All(before, product =>
            {
                Assert.NotNull(product.OrderDetails);
                Assert.All(product.OrderDetails, detail =>
                {
                    Assert.Null(detail.Order);
                });
            });

            var after = pipe.Apply(queryRoot).ToList();

            Assert.NotEmpty(after);
            Assert.All(after, product =>
            {
                Assert.NotNull(product.OrderDetails);
                Assert.All(product.OrderDetails, detail =>
                {
                    Assert.NotNull(detail.Order);
                });
            });
        }
示例#3
0
            public bool TryCreate <TEntity>(IQuerySpecification <TEntity> specification, out IQueryPipe <TEntity> pipe)
                where TEntity : class
            {
                if (specification is IIncludePropertyQuerySpecification <TEntity, TInputProperty, TOutputProperty> includePropertySpec)
                {
                    pipe = new IncludePropertyThenQueryPipe <TEntity, TInputProperty, TOutputProperty>(includePropertySpec.NavigationPropertyPath, includePropertySpec.IsEnumerable);
                    return(true);
                }

                pipe = null;
                return(false);
            }