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 for #18339 #22363

Merged
merged 1 commit into from
Sep 2, 2020
Merged
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
35 changes: 34 additions & 1 deletion test/EFCore.Cosmos.FunctionalTests/EmbeddedDocumentsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using Microsoft.EntityFrameworkCore.Cosmos.Internal;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.TestModels.TransportationModel;
using Microsoft.EntityFrameworkCore.TestUtilities;
using Microsoft.EntityFrameworkCore.ValueGeneration;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json.Linq;
using Xunit;
Expand Down Expand Up @@ -265,6 +267,30 @@ async Task AssertState(EmbeddedTransportationContext context)
}
}

[ConditionalFact]
public virtual async Task Properties_on_owned_types_can_be_client_generated()
{
var options = Fixture.CreateOptions(seed: false);

using (var context = new EmbeddedTransportationContext(options))
{
var address = new Address
{
Street = "First",
City = "City",
AddressTitle = new AddressTitle()
};

context.Add(new Person { Id = 1, Addresses = new List<Address> { address} });
Assert.Equal("DefaultTitle", address.AddressTitle.Title);

await context.SaveChangesAsync();

var people = await context.Set<Person>().ToListAsync();
Assert.Same(address, people[0].Addresses.Single());
}
}

[ConditionalFact]
public virtual async Task Can_use_non_int_keys_for_embedded_entities()
{
Expand Down Expand Up @@ -569,12 +595,19 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
v => v.Addresses, b =>
{
b.ToJsonProperty("Stored Addresses");
b.OwnsOne(a => a.AddressTitle);
b.OwnsOne(a => a.AddressTitle).Property(a => a.Title).HasValueGenerator<TitleGenerator>().IsRequired();
b.OwnsMany(a => a.Notes);
}));
}
}

private class TitleGenerator : ValueGenerator<string>
{
public override bool GeneratesTemporaryValues => false;

public override string Next(EntityEntry entry) => "DefaultTitle";
}

private abstract class PersonBase
{
public int Id { get; set; }
Expand Down