Skip to content

Commit

Permalink
Add test for runtime model generation with proxies
Browse files Browse the repository at this point in the history
Part of #24902
  • Loading branch information
ajcvickers committed Aug 8, 2022
1 parent e68de74 commit b82a393
Showing 1 changed file with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,47 @@ public class LazyPropertyEntity
public LazyConstructorEntity LazyConstructorEntity { get; set; }
}

[ConditionalFact]
public void Lazy_loading_proxies()
=> Test(
new LazyLoadingProxiesContext(),
new CompiledModelCodeGenerationOptions(),
assertModel: model =>
{
Assert.Equal(
typeof(ILazyLoader), model.FindEntityType(typeof(LazyProxiesEntity1))!.GetServiceProperties().Single().ClrType);
Assert.Equal(
typeof(ILazyLoader), model.FindEntityType(typeof(LazyProxiesEntity1))!.GetServiceProperties().Single().ClrType);
});

public class LazyLoadingProxiesContext : ContextBase
{
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);

modelBuilder.Entity<LazyProxiesEntity1>();
}

protected override void OnConfiguring(DbContextOptionsBuilder options)
=> base.OnConfiguring(options.UseLazyLoadingProxies());
}

public class LazyProxiesEntity1
{
public int Id { get; set; }

public virtual LazyProxiesEntity2 ReferenceNavigation { get; set; }
}

public class LazyProxiesEntity2
{
public ILazyLoader Loader { get; set; }

public int Id { get; set; }
public virtual ICollection<LazyProxiesEntity1> CollectionNavigation { get; set; }
}

[ConditionalFact]
public void Throws_for_query_filter()
=> Test(
Expand Down Expand Up @@ -4776,6 +4817,7 @@ protected void Test(
BuildReference.ByName("Microsoft.EntityFrameworkCore.Abstractions"),
BuildReference.ByName("Microsoft.EntityFrameworkCore.Cosmos"),
BuildReference.ByName("Microsoft.EntityFrameworkCore.InMemory"),
BuildReference.ByName("Microsoft.EntityFrameworkCore.Proxies"),
BuildReference.ByName("Microsoft.EntityFrameworkCore.Relational"),
BuildReference.ByName("Microsoft.EntityFrameworkCore.Sqlite"),
BuildReference.ByName("Microsoft.EntityFrameworkCore.Sqlite.NetTopologySuite"),
Expand Down

0 comments on commit b82a393

Please sign in to comment.