public void Cannot_set_or_get_original_value_when_not_tracked_generic() { var entity = new FullyNotifyingWotty { Id = 1, ConcurrentPrimate = "Monkey" }; var entry = InMemoryTestHelpers.Instance.CreateInternalEntry( BuildModel(), EntityState.Unchanged, entity); var propertyEntry = new PropertyEntry <FullyNotifyingWotty, string>(entry, "Primate"); Assert.Equal( CoreStrings.OriginalValueNotTracked("Primate", "FullyNotifyingWotty"), Assert.Throws <InvalidOperationException>(() => propertyEntry.OriginalValue).Message); Assert.Equal( CoreStrings.OriginalValueNotTracked("Primate", "FullyNotifyingWotty"), Assert.Throws <InvalidOperationException>(() => propertyEntry.OriginalValue = "Chimp").Message); }
private void Can_reject_changes_when_clearing_modified_flag_helper <TWotty>() where TWotty : IWotty, new() { using (var context = new PrimateContext()) { var entity = new TWotty { Id = 1, Primate = "Monkey", Marmate = "Bovril", RequiredPrimate = "Tarsier" }; var entry = context.Entry(entity).GetInfrastructure(); entry.SetEntityState(EntityState.Unchanged); var primateEntry = new PropertyEntry(entry, "Primate") { OriginalValue = "Chimp", IsModified = true }; var marmateEntry = new PropertyEntry(entry, "Marmate") { OriginalValue = "Marmite", IsModified = true }; var requiredEntry = new PropertyEntry(entry, "RequiredPrimate") { OriginalValue = "Bushbaby", IsModified = true }; Assert.Equal(EntityState.Modified, entry.EntityState); Assert.Equal("Monkey", entity.Primate); Assert.Equal("Bovril", entity.Marmate); Assert.Equal("Tarsier", entity.RequiredPrimate); context.ChangeTracker.DetectChanges(); Assert.Equal(EntityState.Modified, entry.EntityState); Assert.Equal("Monkey", entity.Primate); Assert.Equal("Bovril", entity.Marmate); Assert.Equal("Tarsier", entity.RequiredPrimate); primateEntry.IsModified = false; Assert.Equal(EntityState.Modified, entry.EntityState); Assert.Equal("Chimp", entity.Primate); Assert.Equal("Bovril", entity.Marmate); Assert.Equal("Tarsier", entity.RequiredPrimate); context.ChangeTracker.DetectChanges(); Assert.Equal(EntityState.Modified, entry.EntityState); Assert.Equal("Chimp", entity.Primate); Assert.Equal("Bovril", entity.Marmate); Assert.Equal("Tarsier", entity.RequiredPrimate); marmateEntry.IsModified = false; Assert.Equal(EntityState.Modified, entry.EntityState); Assert.Equal("Chimp", entity.Primate); Assert.Equal("Marmite", entity.Marmate); Assert.Equal("Tarsier", entity.RequiredPrimate); context.ChangeTracker.DetectChanges(); Assert.Equal(EntityState.Modified, entry.EntityState); Assert.Equal("Chimp", entity.Primate); Assert.Equal("Marmite", entity.Marmate); Assert.Equal("Tarsier", entity.RequiredPrimate); requiredEntry.IsModified = false; Assert.Equal(EntityState.Unchanged, entry.EntityState); Assert.Equal("Chimp", entity.Primate); Assert.Equal("Marmite", entity.Marmate); Assert.Equal("Bushbaby", entity.RequiredPrimate); context.ChangeTracker.DetectChanges(); Assert.Equal(EntityState.Unchanged, entry.EntityState); Assert.Equal("Chimp", entity.Primate); Assert.Equal("Marmite", entity.Marmate); Assert.Equal("Bushbaby", entity.RequiredPrimate); } }