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) }); }
public void SelectExpressionWithNoTypes() { Expression <Func <int, int> > projection = x => x; var visitor = new MaterializedTypesVisitor(); visitor.Visit(projection); visitor.MaterializedTypes.Should().BeEmpty(); }
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")); }
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)); }
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)); }