Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test to verify owned references in project load automatically #16784

Merged
merged 1 commit into from
Jul 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Test to verify owned references in project load automatically
Fixes #13546

Still fails on Cosmos, but due to failed left-join translation.
  • Loading branch information
ajcvickers committed Jul 27, 2019
commit 0546169b47f8e08a03c327350c32b1f94dd52dc8
30 changes: 30 additions & 0 deletions test/EFCore.Cosmos.FunctionalTests/Query/OwnedQueryCosmosTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ public OwnedQueryCosmosTest(OwnedQueryCosmosFixture fixture, ITestOutputHelper t
//TestLoggerFactory.TestOutputHelper = testOutputHelper;
}

[ConditionalFact(Skip = "Issue#12086")]
public override void Query_loads_reference_nav_automatically_in_projection()
{
}

[ConditionalFact(Skip = "Issue#15711")]
public override void Query_with_owned_entity_equality_operator()
{
Expand Down Expand Up @@ -476,6 +481,31 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con
new { Id = "He", Name = "Helium", StarId = 1 });
});
});

modelBuilder.Entity<Barton>(
b =>
{
b.OwnsOne(
e => e.Throned, b => b.HasData(
new
{
BartonId = 1,
Property = "Property"
}));
b.HasData(
new Barton
{
Id = 1, Simple = "Simple"
});

});

modelBuilder.Entity<Fink>().HasData(
new
{
Id = 1,
BartonId = 1
});
}
}
}
Expand Down
60 changes: 60 additions & 0 deletions test/EFCore.Specification.Tests/Query/OwnedQueryTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,20 @@ public virtual void Query_with_OfType_eagerly_loads_correct_owned_navigations()
}
}


[ConditionalFact]
public virtual void Query_loads_reference_nav_automatically_in_projection()
{
using (var context = CreateContext())
{
var barton = context.Set<Fink>().Select(e => e.Barton).Single();

Assert.Equal(1, barton.Id);
Assert.Equal("Simple", barton.Simple);
Assert.Equal("Property", barton.Throned.Property);
}
}

protected virtual DbContext CreateContext() => Fixture.CreateContext();

public abstract class OwnedQueryFixtureBase : SharedStoreFixtureBase<PoolableDbContext>
Expand Down Expand Up @@ -672,6 +686,31 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con
// new { Id = "He", Name = "Helium", StarId = 1 });
// });
});

modelBuilder.Entity<Barton>(
b =>
{
b.OwnsOne(
e => e.Throned, b => b.HasData(
new
{
BartonId = 1,
Property = "Property"
}));
b.HasData(
new Barton
{
Id = 1, Simple = "Simple"
});

});

modelBuilder.Entity<Fink>().HasData(
new
{
Id = 1,
BartonId = 1
});
}

public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder)
Expand Down Expand Up @@ -762,5 +801,26 @@ protected class Element

public int StarId { get; set; }
}

protected class Barton
{
public int Id { get; set; }

public Throned Throned { get; set; }

public string Simple { get; set; }
}

protected class Fink
{
public Barton Barton { get; set; }

public int Id { get; set; }
}

protected class Throned
{
public string Property { get; set; }
}
}
}