Пример #1
0
 public virtual void SaveNew(IEntityDataBase entityDataBase, Action <string> returnAction)
 {
     try
     {
         int lastId = realm.All <T>().Count();
         entityDataBase.Id = (entityDataBase.Id == 0) ? lastId + 1 : entityDataBase.Id;
         realm.Write(() => {
             realm.Add((RealmObject)entityDataBase, true);
         });
         System.Diagnostics.Debug.WriteLine("======= ID ==> {0}", entityDataBase.Id);
         returnAction?.Invoke(string.Empty);
     }
     catch (Exception e)
     {
         returnAction?.Invoke(e.Message);
     }
 }
Пример #2
0
        /// <summary>
        /// Commons the test.
        /// </summary>
        /// <param name="saved">The saved.</param>
        /// <param name="isLocal">if set to <c>true</c> [is local].</param>
        protected void CommonTest(IEntityDataBase saved, bool isLocal)
        {
            #region Common
            //Id
            Assert.IsNotNullOrEmpty(saved.IdString);
            Assert.IsTrue(UtilsService.IsGuidValid(saved.Id));
            Assert.IsTrue(saved.IdString.Length == EntityCommonSystemUser.ValidGuidLength);

            //created
            Assert.NotNull(saved.CreatorUserId);
            Assert.IsNotNullOrEmpty(UtilsService.ValidGuidToString(saved.CreatorUserId));
            Assert.IsTrue(UtilsService.IsGuidValid(saved.CreatorUserId));
            Assert.IsTrue(UtilsService.ValidGuidToString(saved.CreatorUserId).Length == EntityCommonSystemUser.ValidGuidLength);
            Assert.NotNull(saved.DateCreated);
            Assert.GreaterOrEqual(saved.DateCreated, DateTime.Today);

            //updated
            Assert.NotNull(saved.UpdatorUserId);
            Assert.IsNotNullOrEmpty(UtilsService.ValidGuidToString(saved.UpdatorUserId));
            Assert.IsTrue(UtilsService.IsGuidValid(saved.UpdatorUserId));
            Assert.IsTrue(UtilsService.ValidGuidToString(saved.UpdatorUserId).Length == EntityCommonSystemUser.ValidGuidLength);
            Assert.NotNull(saved.DateUpdated);
            Assert.GreaterOrEqual(saved.DateUpdated, DateTime.Today);
            Assert.GreaterOrEqual(saved.DateUpdated, saved.DateCreated);

            //Sync
            if (isLocal)
            {
                Assert.IsTrue(saved.IsLocalData);
                Assert.IsFalse(saved.IsSynced);
                Assert.Less(saved.DateSynced, DateTime.Today);
            }
            else
            {
                Assert.IsFalse(saved.IsLocalData);
                Assert.IsTrue(saved.IsSynced);
                Assert.GreaterOrEqual(saved.DateSynced, DateTime.Today);
            }

            //Reason
            Assert.AreEqual(saved.NotActiveReason, saved.NotActiveReason);
            Assert.IsNull(saved.NotActiveReason);
            #endregion
        }