示例#1
0
        public bool TryCreate <TEntity>(IQuerySpecification <TEntity> specification, out IQueryPipe <TEntity> pipe)
            where TEntity : class
        {
            switch (specification)
            {
            case IIncludePathQuerySpecification <TEntity> includePathSpec:
                pipe = new IncludePathQueryPipe <TEntity>(includePathSpec.NavigationPropertyPath);
                return(true);

            case IIncludePropertyQuerySpecification <TEntity> includePropertySpec when includePropertySpec.IsRoot:
                return(TryCreateRoot(includePropertySpec, out pipe));

            case IIncludePropertyQuerySpecification <TEntity> includePropertySpec:
                return(TryCreateThen(includePropertySpec, out pipe));
            }

            pipe = null;
            return(false);
        }
        public void Apply_GivenPath_ThenNotNull()
        {
            var pipe = new IncludePathQueryPipe <Order>(nameof(Order.Customer));

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

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

            var before = queryRoot;

            Assert.NotEmpty(before);
            Assert.All(before, order => Assert.Null(order.Customer));

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

            Assert.NotEmpty(after);
            Assert.All(after, order => Assert.NotNull(order.Customer));
        }