Beispiel #1
0
        public void NewExpressionWithArgumentsShouldBeCaptures()
        {
            Expression <Func <int, Customer> > projection = x => new Customer(x);
            var visitor = new MaterializedTypesVisitor();

            visitor.Visit(projection);
            visitor.MaterializedTypes.Should().BeEquivalentTo(new[] { typeof(Customer) });
        }
Beispiel #2
0
        public void SelectExpressionWithNoTypes()
        {
            Expression <Func <int, int> > projection = x => x;
            var visitor = new MaterializedTypesVisitor();

            visitor.Visit(projection);
            visitor.MaterializedTypes.Should().BeEmpty();
        }
Beispiel #3
0
        public void AnonymousTypeShouldBeDetected()
        {
            Expression <Func <CustomerEntity, object> > projection = x => new { x.Id };
            var visitor = new MaterializedTypesVisitor();

            visitor.Visit(projection);
            visitor.MaterializedTypes.Should().HaveCount(1)
            .And.ContainSingle(t => t.Name.StartsWith("<") && t.Name.Contains("AnonymousType"));
        }
Beispiel #4
0
        public void MultipleOccuranceOfTypeWillBeIncludedOnce()
        {
            Expression <Func <CustomerEntity, Customer> > projection = x => new Customer
            {
                DeliveryAddress = new Address(),
                WorkAddress     = new Address(),
            };
            var visitor = new MaterializedTypesVisitor();

            visitor.Visit(projection);
            visitor.MaterializedTypes.Should().BeEquivalentTo(typeof(Customer), typeof(Address));
        }
Beispiel #5
0
        public void SubselectsTypesShouldBeFound()
        {
            Expression <Func <CustomerEntity, Customer> > projection = x => new Customer
            {
                PhoneNumbers = x.PhoneNumbers.Select(pn => new Contact {
                    Number = (PhoneNumber)pn.Number, Location = pn.Location
                }).ToList(),
            };
            var visitor = new MaterializedTypesVisitor();

            visitor.Visit(projection);
            visitor.MaterializedTypes.Should().BeEquivalentTo(typeof(Contact), typeof(Customer));
        }