Skip to content

Commit

Permalink
Test for #18339
Browse files Browse the repository at this point in the history
Fixes #18339
  • Loading branch information
AndriySvyryd committed Sep 1, 2020
1 parent bff57f9 commit cda8c55
Showing 1 changed file with 34 additions and 1 deletion.
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

0 comments on commit cda8c55

Please sign in to comment.