コード例 #1
0
        public void StatusUtility_IsModified_WithMultiLevelHirachy_ShouldGetStatus()
        {
            var rootEntity  = new RootEntity();
            var leafEntityA = new LeafEntity();

            rootEntity.LeafEntities.Add(leafEntityA);
            var leafEntityB = new LeafEntity();

            rootEntity.LeafEntities.Add(leafEntityB);
            var leafEntityNotNull = new LeafEntity();

            rootEntity.LeafEntityNotNull = leafEntityNotNull;
            rootEntity.LeafEntityNull    = null;

            bool unModifiedRoot = StatusManager.IsModified(rootEntity);

            rootEntity.Status = EntityStatus.Modified;
            bool modifiedRoot = StatusManager.IsModified(rootEntity);

            rootEntity.Status  = EntityStatus.Unmodified;
            leafEntityA.Status = EntityStatus.New;
            bool modifiedLeafCollection = StatusManager.IsModified(rootEntity);

            leafEntityA.Status       = EntityStatus.Unmodified;
            leafEntityNotNull.Status = EntityStatus.Deleted;
            bool modifiedLeafSubEntity = StatusManager.IsModified(rootEntity);

            Assert.IsFalse(unModifiedRoot);
            Assert.IsTrue(modifiedRoot);
            Assert.IsTrue(modifiedLeafCollection);
            Assert.IsTrue(modifiedLeafSubEntity);
        }
コード例 #2
0
 private void AssertTwoLeafEntitiesTypeAEquals(LeafEntity entityA, LeafEntity entityB)
 {
     Assert.AreEqual(entityA.IdCol, entityB.IdCol);
     Assert.AreEqual(entityA.IndexNo, entityB.IndexNo);
     Assert.AreEqual(entityA.SomeText, entityB.SomeText);
     if (entityA is LeafEntitySubA && entityB is LeafEntitySubA)
     {
         Assert.AreEqual(((LeafEntitySubA)entityA).SomeTextA, ((LeafEntitySubA)entityB).SomeTextA);
     }
     if (entityA is LeafEntitySubB && entityB is LeafEntitySubB)
     {
         Assert.AreEqual(((LeafEntitySubB)entityA).SomeTextB, ((LeafEntitySubB)entityB).SomeTextB);
     }
 }
コード例 #3
0
        private void AssertTwoRootEntitiesEquals(RootEntity entityA, RootEntity entityB)
        {
            Assert.AreEqual(entityA.IdCol, entityB.IdCol);

            Assert.AreEqual(entityA.CharNotNull, entityB.CharNotNull);
            Assert.AreEqual(entityA.CharNull, entityB.CharNull);
            Assert.AreEqual(entityA.DateNotNull, entityB.DateNotNull);
            Assert.AreEqual(entityA.DateNull, entityB.DateNull);
            Assert.AreEqual(entityA.DoubleNotNull, entityB.DoubleNotNull);
            Assert.AreEqual(entityA.DoubleNull, entityB.DoubleNull);
            Assert.AreEqual(entityA.FloatNotNull, entityB.FloatNotNull);
            Assert.AreEqual(entityA.FloatNull, entityB.FloatNull);
            Assert.AreEqual(entityA.IntNotNull, entityB.IntNotNull);
            Assert.AreEqual(entityA.IntNull, entityB.IntNull);
            Assert.AreEqual(entityA.LongNotNull, entityB.LongNotNull);
            Assert.AreEqual(entityA.LongNull, entityB.LongNull);
            Assert.AreEqual(entityA.TimestampNotNull, entityB.TimestampNotNull);
            Assert.AreEqual(entityA.TimestampNull, entityB.TimestampNull);
            Assert.AreEqual(entityA.VarcharNotNull, entityB.VarcharNotNull);
            Assert.AreEqual(entityA.VarcharNull, entityB.VarcharNull);
            Assert.AreEqual(entityA.LeafEntities.Count, entityB.LeafEntities.Count);

            IEnumerator <LeafEntity> iteratorA = entityA.LeafEntities.GetEnumerator();

            while (iteratorA.MoveNext())
            {
                LeafEntity leafEntityA = iteratorA.Current;
                bool       bFound      = false;
                foreach (LeafEntity leafEntityB in entityB.LeafEntities)
                {
                    if (leafEntityB.IdCol == leafEntityA.IdCol &&
                        leafEntityB.IndexNo == leafEntityA.IndexNo)
                    {
                        bFound = true;
                        AssertTwoLeafEntitiesTypeAEquals(leafEntityA, leafEntityB);
                    }
                }
                if (!bFound)
                {
                    Assert.Fail("Could not found matching leaf entity");
                }
            }
        }
コード例 #4
0
        public void StatusUtility_SetStatus_WithMultiLevelHirachy_ShouldSetStatus()
        {
            var rootEntity  = new RootEntity();
            var leafEntityA = new LeafEntity();

            rootEntity.LeafEntities.Add(leafEntityA);
            var leafEntityB = new LeafEntity();

            rootEntity.LeafEntities.Add(leafEntityB);
            var leafEntityNotNull = new LeafEntity();

            rootEntity.LeafEntityNotNull = leafEntityNotNull;
            rootEntity.LeafEntityNull    = null;

            StatusManager.SetStatus(rootEntity, EntityStatus.Modified);

            Assert.AreEqual(rootEntity.Status, EntityStatus.Modified);
            Assert.AreEqual(leafEntityA.Status, EntityStatus.Modified);
            Assert.AreEqual(leafEntityB.Status, EntityStatus.Modified);
            Assert.AreEqual(leafEntityNotNull.Status, EntityStatus.Modified);
        }
コード例 #5
0
        public void StatusUtility_GetImmidiateChildrenAndClear_WithMultiLevelHirachy_ShouldGetChildren()
        {
            var rootEntity  = new RootEntity();
            var leafEntityA = new LeafEntity();

            rootEntity.LeafEntities.Add(leafEntityA);
            var leafEntityB = new LeafEntity();

            rootEntity.LeafEntities.Add(leafEntityB);
            var leafEntityNotNull = new LeafEntity();

            rootEntity.LeafEntityNotNull = leafEntityNotNull;
            rootEntity.LeafEntityNull    = null;

            ICollection <IClientEntity> childern = StatusManager.GetImmidiateChildrenAndClear(rootEntity);

            Assert.IsTrue(childern.Contains(leafEntityA));
            Assert.IsTrue(childern.Contains(leafEntityB));
            Assert.IsTrue(childern.Contains(leafEntityNotNull));
            Assert.IsTrue(rootEntity.LeafEntities.Count == 0);
            Assert.IsNull(rootEntity.LeafEntityNotNull);
        }