public void BeforePushActions()
        {
            bool       isActionInvoked = false;
            MockEntity entity          = new MockEntity();

            entity.BeforePushActions.Add((e) => isActionInvoked = true);
            entity.BeginEdit();
            IDictionary <string, Tuple <string, object>[]> result = new Dictionary <string, Tuple <string, object>[]>();
            Mock <IDataAccessLayer> mockDal = new Mock <IDataAccessLayer>();

            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(result));

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

            Assert.IsTrue(isActionInvoked);
        }
        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_include_duration()
        {
            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();
            int editDuration = 100;

            Thread.Sleep(editDuration);

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

            mockDal.Verify(m => m.UpdateEntity(It.IsAny <Type>(), It.IsAny <string>(), It.IsAny <IEnumerable <string> >(), It.IsAny <int>(), It.Is <int>(i => i > 0), It.IsAny <int>()), Times.Once());
        }
        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());
        }