public void Can_track_navigational_property_change()
        {
            var options = new DbContextOptionsBuilder <TestTrackerContext>()
                          .UseSqlServer(TestConnectionString)
                          .Options;

            //add enitties
            var parent1 = new ParentModel();
            var child   = new ChildModel {
                Parent = parent1
            };

            using (TestTrackerContext ttc = new TestTrackerContext(options))
            {
                ttc.ChildModels.Add(child);
                ttc.SaveChanges();

                child.Id.AssertIsNotZero();   //assert child saved
                parent1.Id.AssertIsNotZero(); //assert parent1 saved

                //save parent 2
                var parent2 = new ParentModel();
                ttc.ParentModels.Add(parent2);
                ttc.SaveChanges();

                parent2.Id.AssertIsNotZero(); //assert parent2 saved

                //change parent
                child.Parent = parent2;
                ttc.SaveChanges();

                AuditLogDetail[] expectedLog = new List <AuditLogDetail>
                {
                    new AuditLogDetail
                    {
                        NewValue      = parent2.Id.ToString(),
                        OriginalValue = parent1.Id.ToString(),
                        PropertyName  = "ParentId"
                    }
                }.ToArray();

                //assert change
                child.AssertAuditForModification(ttc, child.Id, null, expectedLog);
            }
        }
        public void Can_track_navigational_property_change()
        {
            //add enitties
            var parent1 = new ParentModel();
            var child   = new ChildModel {
                Parent = parent1
            };

            Db.Children.Add(child);
            Db.SaveChanges();

            child.Id.AssertIsNotZero();   //assert child saved
            parent1.Id.AssertIsNotZero(); //assert parent1 saved

            //save parent 2
            var parent2 = new ParentModel();

            Db.ParentModels.Add(parent2);
            Db.SaveChanges();

            parent2.Id.AssertIsNotZero(); //assert parent2 saved

            //change parent
            child.Parent = parent2;
            Db.SaveChanges();

            AuditLogDetail[] expectedLog = new List <AuditLogDetail>
            {
                new AuditLogDetail
                {
                    NewValue      = parent2.Id.ToString(),
                    OriginalValue = parent1.Id.ToString(),
                    PropertyName  = "ParentId"
                }
            }.ToArray();

            //assert change
            child.AssertAuditForModification(Db, child.Id, null, expectedLog);
        }