public void MemberWithConverterType_IsColumnMember()
        {
            var config = new ConversionConfiguration();

            config.AddConvertor(new ValueConverter <Id <SingleProperty>, int>(model => model.Value, provider => (Id <SingleProperty>)provider));
            var searcher = new GraphSearcher(config);
            var graph    = searcher.SearchGraph(typeof(SingleProperty));

            graph.Nodes.Should().ContainSingle()
            .Which.ColumnMembers.Should().ContainSingle(x => x.Name == nameof(SingleProperty.Id) && ((PropertyInfo)x).PropertyType == typeof(Id <SingleProperty>));
        }
예제 #2
0
        public void PrimitiveTypeAsRoot_WillBeEmptyGraph()
        {
            var primitiveType = typeof(int);
            var config        = new ConversionConfiguration
            {
                IsAllowedForColumn = x => x == primitiveType,
            };
            var searcher = new GraphSearcher(config);
            var graph    = searcher.SearchGraph(primitiveType);

            graph.Nodes.Should().BeEmpty();
        }
예제 #3
0
        public void CyclicGraphs_DontCauseEndlessRecursion()
        {
            var primitiveType = typeof(int);
            var config        = new ConversionConfiguration
            {
                IsAllowedForColumn          = x => false,
                ShouldMediateTargetProperty = x => true,
            };
            var searcher = new GraphSearcher(config);
            var graph    = searcher.SearchGraph(typeof(CycleLink1));

            graph.Nodes.Select(_ => _.Type).Should().Contain(new[] { typeof(CycleLink1), typeof(CycleLink2) });
        }
예제 #4
0
        public void SelectWithMultiplePropertyChain_IsProperlyMaterialized()
        {
            using (var connection = new SQLiteConnection("data source=:memory:"))
            {
                connection.Open();
                using (var ctx = new OrderContext(connection))
                {
                    var order = new Order
                    {
                        Items = new List <OrderItem>
                        {
                            new OrderItem
                            {
                                Product = new Product {
                                    Name = "Diapers", Cost = 10.0m
                                },
                                Quantity = 5,
                            },
                            new OrderItem
                            {
                                Product = new Product {
                                    Name = "Baby formula", Cost = 50m
                                },
                                Quantity = 3,
                            },
                        },
                    };
                    ctx.Orders.Add(order);
                    ctx.SaveChanges();

                    var config = new ConversionConfiguration()
                    {
                        IsAllowedForColumn = x => x.IsValueType || x == typeof(string),
                    };
                    var searcher       = new GraphSearcher(config);
                    var graph          = searcher.SearchGraph(typeof(B));
                    var mediatorMapper = new MediatorTypeBuilder().CreateMediatorTypes(graph);
                    var result         = ctx.OrderItems.ProjectToList(
                        x => new B
                    {
                        ProductCost = x.Product.Cost,
                    },
                        mediatorMapper);
                    result.Select(x => x.ProductCost).Should().BeEquivalentTo(10m, 50m);
                }
            }
        }
예제 #5
0
        public void PropertiesMaterializedFromDbColumnAreAlwaysAllowed()
        {
            var originType    = typeof(Outer);
            var primitiveType = new Outer().Primitive.GetType();
            var config        = new ConversionConfiguration
            {
                IsAllowedForColumn          = x => x == primitiveType,
                ShouldMediateTargetProperty = x => false,
            };
            var searcher = new GraphSearcher(config);
            var graph    = searcher.SearchGraph(originType);

            graph.Nodes.Should().ContainSingle()
            .Which.Type.Should().Be(originType);
            graph.Nodes.Single().ColumnMembers
            .Should().Equal(typeof(Outer).GetProperty(nameof(Outer.Primitive)));
        }
예제 #6
0
        private void AssertTargetToMediator <TParameter, TResult>(
            Expression <Func <TParameter, TResult> > projection,
            string resultTargetToMediator)
        {
            var config = new ConversionConfiguration()
            {
                IsAllowedForColumn = x => x.IsValueType || x == typeof(string),
            };
            var searcher = new GraphSearcher(config);
            var graph    = searcher.SearchGraph(typeof(TResult));

            var mediatorMapper = new MediatorTypeBuilder().CreateMediatorTypes(graph);

            var targetToMediatorVisitor = new TargetToMediatorVisitor(mediatorMapper);
            var result = targetToMediatorVisitor.Visit(projection);

            result.ToString("C#").Should().Be(resultTargetToMediator.Trim());
        }
예제 #7
0
        public void GraphHasMultipleLevels_AllAreFound()
        {
            var originType = typeof(Outer);
            var config     = new ConversionConfiguration
            {
                IsAllowedForColumn          = x => x.IsPrimitive,
                ShouldMediateTargetProperty = x => true,
            };
            var searcher = new GraphSearcher(config);
            var graph    = searcher.SearchGraph(originType);

            graph.Nodes.Select(x => x.Type).Should().BeEquivalentTo(typeof(Outer), typeof(Inner), typeof(Innermost));
            var outerNode     = graph.Nodes.Single(x => x.Type == typeof(Outer));
            var innerNode     = graph.Nodes.Single(x => x.Type == typeof(Inner));
            var innermostNode = graph.Nodes.Single(x => x.Type == typeof(Innermost));

            graph.Edges.Should().BeEquivalentTo(
                new Edge(outerNode, innerNode, typeof(Outer).GetProperty(nameof(Outer.Inner))),
                new Edge(innerNode, innermostNode, typeof(Inner).GetProperty(nameof(Inner.Innermost))));
        }