public void BeginEdit_merge_changes_one_to_many_navigation_property()
        {
            MockEntity entity = new MockEntity();

            entity.BeginEdit();

            MockEntity relationalEntity = new MockEntity();

            relationalEntity.BeginEdit();

            relationalEntity.RelationalEntity1 = new MockEntity();
            relationalEntity.RelationalEntity1.StringProperty = "Address Line 1";
            entity.RelationalEntity1     = relationalEntity;
            relationalEntity.IntProperty = 1;

            Assert.AreEqual(4, entity.PropertyChanges().Count());
            Assert.IsTrue(entity.PropertyChanges().Any(c => c.DbEntityPropertyPath(entity).Equals(".RelationalEntity1")));
            Assert.IsTrue(entity.PropertyChanges().Any(c => c.DbEntityPropertyPath(entity).Equals(".RelationalEntity1.RelationalEntity1")));
            Assert.IsTrue(entity.PropertyChanges().Any(c => c.DbEntityPropertyPath(entity).Equals(".RelationalEntity1.RelationalEntity1.StringProperty")));
            Assert.IsTrue(entity.PropertyChanges().Any(c => c.DbEntityPropertyPath(entity).Equals(".RelationalEntity1.IntProperty")));
            Should.Throw <ArgumentNullException>(() => relationalEntity.DbEntityChanges());
            Assert.IsTrue(entity.IsTracked);
            Assert.IsTrue(entity.IsEditing);
            Assert.IsTrue(relationalEntity.IsTracked);
            Assert.IsFalse(relationalEntity.IsEditing);
        }
        public void BeginEdit_entity_tracked_by_parent_entity_do_not_initiate_tracker()
        {
            MockEntity entity           = new MockEntity();
            MockEntity relationalEntity = new MockEntity();

            entity.RelationalEntity1 = relationalEntity;
            entity.BeginEdit();
            relationalEntity.BeginEdit();

            relationalEntity.IntProperty = 1;

            Assert.AreEqual(1, entity.DbEntityChanges().Count());
            Assert.IsTrue(relationalEntity.IsTracked);
            Should.Throw <ArgumentException>(() => { relationalEntity.DbEntityChanges(); });
        }
        public void Push_update_primary_keys_without_tracking()
        {
            Mock <IDataAccessLayer> mockDal = new Mock <IDataAccessLayer>();
            IDictionary <string, Tuple <string, object>[]> keys = new Dictionary <string, Tuple <string, object>[]>()
            {
                { ".", new Tuple <string, object>[] { new Tuple <string, object>("id", int.MaxValue) } }
            };

            mockDal.Setup(m => m.UpdateEntity(typeof(MockEntity), It.IsAny <string>(), It.IsAny <IEnumerable <string> >(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult(keys));
            MockEntity entity = new MockEntity();

            entity.BeginEdit();
            entity.PushAsync(mockDal.Object, 0, 0).GetAwaiter().GetResult();

            Assert.AreEqual(0, entity.DbEntityChanges().Count());
            Assert.AreEqual(entity.id, keys.First().Value.First().Item2);
            Assert.AreEqual(EntityState.Persisted, entity.State);
        }
        public async Task Push_entity_pushed_changes_reset()
        {
            IDictionary <string, Tuple <string, object>[]> primaryKeys = new Dictionary <string, Tuple <string, object>[]>()
            {
                { ".", new Tuple <string, object>[] { new Tuple <string, object>("id", 1) } }
            };
            Mock <IDataAccessLayer> mockDal = new Mock <IDataAccessLayer>();

            mockDal.Setup(m => m.UpdateEntity(It.IsAny <Type>(), It.IsAny <string>(), It.IsAny <IEnumerable <string> >(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult(primaryKeys));
            MockEntity entity = new MockEntity();

            entity.BeginEdit();
            entity.IntProperty = 1;
            string changesAsJson = entity.ChangesAsJson();

            await entity.PushAsync(mockDal.Object, 0, 1);

            mockDal.Verify(m => m.UpdateEntity(It.IsAny <Type>(), It.Is <string>(s => s.Equals(changesAsJson)), It.IsAny <IEnumerable <string> >(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>()), Times.Once());
            Assert.AreEqual(0, entity.DbEntityChanges().Count());
        }