Exemple #1
0
        static void TestDocListHooks()
        {
            DocList <IDocLeaf> list = new DocList <IDocLeaf>();

            list.Hook += TestDocListHook;

            DocObj <string> obj0 = new DocObj <string>("Hello World");
            DocObj <string> obj1 = new DocObj <string>("Hello World");

            list.Add(obj0);
            list.Remove(obj0);
            list.Add(obj0);
            list.Add(obj1);
            list.Clear();
            list.Clear();
        }
Exemple #2
0
        static void TestHistoryBasics()
        {
            DocList <IDocLeaf> testDoc = new DocList <IDocLeaf>();

            History.Instance.Root = testDoc;
            UnitTest.Test(History.Instance.HasUndo == false);
            UnitTest.Test(History.Instance.HasRedo == false);

            DocObj <int> testInt = new DocObj <int>(0);

            testDoc.Add(testInt);
            UnitTest.Test(History.Instance.HasUndo == true);
            UnitTest.Test(History.Instance.HasRedo == false);

            testInt.Value = 1;
            UnitTest.Test(testInt.Value == 1);
            testInt.Value = 2;
            UnitTest.Test(testInt.Value == 2);
            testInt.Value = 3;
            UnitTest.Test(testInt.Value == 3);

            History.Instance.Undo();
            UnitTest.Test(testInt.Value == 0);
            UnitTest.Test(History.Instance.HasRedo == true);
            History.Instance.Redo();
            UnitTest.Test(testInt.Value == 3);
        }
Exemple #3
0
        static void TestDocListCollectionChanged()
        {
            DocList <IDocLeaf> list = new DocList <IDocLeaf>();

            list.CollectionChanged += TestDocListOnCollectionChanged;
            ((INotifyPropertyChanged)list).PropertyChanged += TestDocListOnCollectionChanged2;

            DocObj <string> obj0 = new DocObj <string>("Hello World");
            DocObj <string> obj1 = new DocObj <string>("Hello World");

            list.Add(obj0);
            list.Remove(obj0);
            list.Add(obj0);
            list.Add(obj1);
            list.Clear();
            list.Clear();
        }
Exemple #4
0
        static void TestDocListTransaction()
        {
            DocList <IDocLeaf> list = new DocList <IDocLeaf>();

            History.Instance.Root = list;

            list.Transaction.Value += 1;

            list.Add(new DocObj <string>("Hello World"));

            list.Transaction.Value -= 1;
        }
Exemple #5
0
        static void TestHistoryRollback()
        {
            DocList <DocObj <int> > testDoc = new DocList <DocObj <int> >();

            testDoc.Add(new DocObj <int>(0));
            testDoc.Add(new DocObj <int>(1));

            History.Instance.Root = testDoc;

            bool exceptionCaught = false;

            try
            {
                History.Instance.ExecuteInTransaction(
                    delegate()
                {
                    testDoc[0].Value = -1;
                    testDoc[1].Value = -2;

                    UnitTest.Test(testDoc[0].Value == -1);
                    UnitTest.Test(testDoc[1].Value == -2);

                    throw new Exception("Hello World");
                },
                    0,
                    "TestHistoryRollback");
            }
            catch (Exception ex)
            {
                exceptionCaught = true;
                UnitTest.Test(ex.Message == "Hello World");
            }

            UnitTest.Test(exceptionCaught);
            UnitTest.Test(testDoc[0].Value == 0);
            UnitTest.Test(testDoc[1].Value == 1);

            UnitTest.Test(History.Instance.HasUndo == false);
            UnitTest.Test(History.Instance.HasRedo == false);
        }
Exemple #6
0
        static void TestHistoryTransactions()
        {
            DocList <IDocLeaf> testDoc = new DocList <IDocLeaf>();

            History.Instance.Root = testDoc;
            UnitTest.Test(History.Instance.HasUndo == false);
            UnitTest.Test(History.Instance.HasRedo == false);

            History.Instance.ExecuteInTransaction(
                delegate()
            {
                DocObj <int> testInt0 = new DocObj <int>(0);
                testDoc.Add(testInt0);
                UnitTest.Test(History.Instance.HasUndo == false);
                UnitTest.Test(History.Instance.HasRedo == false);

                DocObj <int> testInt1 = new DocObj <int>(1);
                testDoc.Add(testInt1);
                UnitTest.Test(History.Instance.HasUndo == false);
                UnitTest.Test(History.Instance.HasRedo == false);
            },
                0,
                "TestHistoryTransactions");

            UnitTest.Test(testDoc.Count == 2);
            UnitTest.Test(History.Instance.HasUndo == true);
            UnitTest.Test(History.Instance.HasRedo == false);

            History.Instance.Undo();
            UnitTest.Test(testDoc.Count == 0);
            UnitTest.Test(History.Instance.HasUndo == false);
            UnitTest.Test(History.Instance.HasRedo == true);

            History.Instance.Redo();
            UnitTest.Test(testDoc.Count == 2);
            UnitTest.Test(History.Instance.HasUndo == true);
            UnitTest.Test(History.Instance.HasRedo == false);
        }
Exemple #7
0
        static void TestDocListSerialization2()
        {
            DocList <IDocLeaf> list0  = new DocList <IDocLeaf>();
            DocList <IDocLeaf> list01 = new DocList <IDocLeaf>();

            list01.Add(new DocObj <int>(0));
            list01.Add(new DocObj <int>(1));
            list0.Add(list01);

            DocList <IDocLeaf> list02 = new DocList <IDocLeaf>();

            list02.Add(new DocObj <int>(0));
            list02.Add(new DocObj <int>(1));
            list0.Add(list02);

            DocList <IDocLeaf> list1 = SerializeDeserialize(list0);

            UnitTest.Test(list1.Count == 2);
            UnitTest.Test((list1[0] as DocList <IDocLeaf>).Count == 2);
            UnitTest.Test((list1[1] as DocList <IDocLeaf>).Count == 2);

            PathUtils.CheckParentChildrenLink(list1, null);
        }
Exemple #8
0
        static void TestListUndoRedo()
        {
            DocList <DocObj <int> > testDoc = new DocList <DocObj <int> >();

            History.Instance.Root = testDoc;

            History.Instance.ExecuteInTransaction(delegate()
            {
                testDoc.Add(new DocObj <int>(1));
                UnitTest.Test(testDoc.Count == 1);
                testDoc.Add(new DocObj <int>(2));
                UnitTest.Test(testDoc.Count == 2);
                testDoc.Add(new DocObj <int>(3));
                UnitTest.Test(testDoc.Count == 3);
            }, History.Instance.NextFreeTransactionId(), "Dummy");

            UnitTest.Test(testDoc[0].Value == 1);
            UnitTest.Test(testDoc[1].Value == 2);
            UnitTest.Test(testDoc[2].Value == 3);

            History.Instance.Undo();
            UnitTest.Test(testDoc.Count == 0);

            History.Instance.Redo();
            UnitTest.Test(testDoc.Count == 3);
            UnitTest.Test(testDoc[0].Value == 1);
            UnitTest.Test(testDoc[1].Value == 2);
            UnitTest.Test(testDoc[2].Value == 3);

            testDoc.RemoveAt(0);
            UnitTest.Test(testDoc.Count == 2);
            UnitTest.Test(testDoc[0].Value == 2);
            UnitTest.Test(testDoc[1].Value == 3);

            testDoc.Clear();
            UnitTest.Test(testDoc.Count == 0);
        }