From 69d75f180fa4d44e93a8be62545894f953831210 Mon Sep 17 00:00:00 2001 From: Victor Irzak Date: Wed, 24 Mar 2021 18:39:15 -0400 Subject: [PATCH] Add failing test which fails to SetValues of owned property --- .../ChangeTracking/PropertyEntryTest.cs | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/test/EFCore.Tests/ChangeTracking/PropertyEntryTest.cs b/test/EFCore.Tests/ChangeTracking/PropertyEntryTest.cs index 38637c02908..5e60cb0d03c 100644 --- a/test/EFCore.Tests/ChangeTracking/PropertyEntryTest.cs +++ b/test/EFCore.Tests/ChangeTracking/PropertyEntryTest.cs @@ -138,6 +138,55 @@ protected internal override void OnModelCreating(ModelBuilder modelBuilder) } } + [ConditionalFact] + public void SetValues_to_owned_property() + { + Guid id; + using (var context = new OwnedDbContext()) + { + id = context.Add(new Owner { OwnerInt = 1, Owned = new() { OwnedInt = 1 } }).Entity.Id; + context.SaveChanges(); + } + + var disconnectedEntity = new Owner { Id = id, OwnerInt = 2, Owned = new() { OwnedInt = 2 } }; + + + using (var context = new OwnedDbContext()) + { + var trackedEntity = context.Find(id); + var entry = context.Entry(trackedEntity); + entry.CurrentValues.SetValues(disconnectedEntity); + + Assert.Equal(2, trackedEntity.OwnerInt); + Assert.Equal(2, trackedEntity.Owned.OwnedInt); + + context.SaveChanges(); + } + } + + public class Owner + { + public Guid Id { get; set; } + public int OwnerInt { get; set; } + public Owned Owned { get; set; } = null!; + } + + + [Owned] + public class Owned + { + public int OwnedInt { get; set; } + } + + protected class OwnedDbContext : DbContext + { + protected internal override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + => optionsBuilder.UseInMemoryDatabase(GetType().FullName); + + public DbSet Owners { get; set; } = null!; + } + + [ConditionalFact] public void Setting_IsModified_is_not_reset_by_OriginalValues() {