Пример #1
0
        public void TestReplaceLastItem()
        {
            ILexEntry kick       = null;
            ILexEntry bucket     = null;
            ILexEntry can        = null;
            ILexEntry kickBucket = null;

            kick       = MakeEntryWithForm("kick");
            bucket     = MakeEntryWithForm("bucket");
            can        = MakeEntryWithForm("can");
            kickBucket = MakeEntryWithForm("kick the bucket");
            kickBucket.AddComponent(kick);
            kickBucket.AddComponent(bucket);
            var entryRef = kickBucket.EntryRefsOS[0];

            Assert.That(entryRef.ComponentLexemesRS[0], Is.EqualTo(kick));
            m_actionHandler.EndUndoTask();
            UndoableUnitOfWorkHelper.Do("doit", "undoit", Cache.ActionHandlerAccessor,
                                        () => entryRef.ComponentLexemesRS.Replace(0, 2, new[] { kick, can }));
            Assert.That(entryRef.ComponentLexemesRS[1], Is.EqualTo(can));             //test that the replace made the proper order change
            m_actionHandler.Undo();
            Assert.That(entryRef.ComponentLexemesRS[1], Is.EqualTo(bucket));          //test that the order change was reversed
        }
Пример #2
0
        public void ReplaceUndoTest()
        {
            ILexEntry kick       = null;
            ILexEntry bucket     = null;
            ILexEntry the        = null;
            ILexEntry kickBucket = null;

            kick       = MakeEntryWithForm("kick");
            bucket     = MakeEntryWithForm("bucket");
            the        = MakeEntryWithForm("the");
            kickBucket = MakeEntryWithForm("kick the bucket");
            kickBucket.AddComponent(kick);
            kickBucket.AddComponent(the);
            kickBucket.AddComponent(bucket);
            var entryRef = kickBucket.EntryRefsOS[0];

            Assert.That(entryRef.PrimaryLexemesRS[0], Is.EqualTo(kick));
            m_actionHandler.EndUndoTask();
            UndoableUnitOfWorkHelper.Do("doit", "undoit", Cache.ActionHandlerAccessor,
                                        () => entryRef.ComponentLexemesRS.Replace(0, 3, new[] { bucket, the, kick }));
            Assert.That(entryRef.ComponentLexemesRS[0], Is.EqualTo(bucket));           //test that the replace made the proper order change
            m_actionHandler.Undo();
            Assert.That(entryRef.ComponentLexemesRS[0], Is.EqualTo(kick));             //test that the order change was reversed

            UndoableUnitOfWorkHelper.Do("doit", "undoit", Cache.ActionHandlerAccessor,
                                        () => entryRef.ComponentLexemesRS.Replace(0, 3, new[] { kick, the }));
            Assert.That(entryRef.ComponentLexemesRS.Count, Is.EqualTo(2));             //test that the replace removed the last item
            Assert.That(entryRef.ComponentLexemesRS[0], Is.EqualTo(kick));             //should be unchanged

            m_actionHandler.Undo();
            Assert.That(entryRef.ComponentLexemesRS.Count, Is.EqualTo(3));             //test that the undo restored the last item
            Assert.That(entryRef.ComponentLexemesRS[2], Is.EqualTo(bucket));           //test that the order change was reversed

            m_actionHandler.Redo();
            Assert.That(entryRef.ComponentLexemesRS.Count, Is.EqualTo(2));             //test that the replace removed the last item
            Assert.That(entryRef.ComponentLexemesRS[0], Is.EqualTo(kick));             //should be unchanged

            UndoableUnitOfWorkHelper.Do("doit", "undoit", Cache.ActionHandlerAccessor,
                                        () => entryRef.ComponentLexemesRS.Replace(0, 0, new[] { bucket }));
            Assert.That(entryRef.ComponentLexemesRS.Count, Is.EqualTo(3));             //we inserted one
            Assert.That(entryRef.ComponentLexemesRS[0], Is.EqualTo(bucket));           //the inserted one
            Assert.That(entryRef.ComponentLexemesRS[1], Is.EqualTo(kick));             //old first item now in slot 1

            m_actionHandler.Undo();
            Assert.That(entryRef.ComponentLexemesRS.Count, Is.EqualTo(2));             //bucket is back out
            Assert.That(entryRef.ComponentLexemesRS[0], Is.EqualTo(kick));             //moved back to index 0

            UndoableUnitOfWorkHelper.Do("doit", "undoit", Cache.ActionHandlerAccessor,
                                        () => entryRef.ComponentLexemesRS.Replace(1, 1, new[] { bucket, the }));
            Assert.That(entryRef.ComponentLexemesRS.Count, Is.EqualTo(3));            //should now be kick bucket the
            Assert.That(entryRef.ComponentLexemesRS[0], Is.EqualTo(kick));            //unchanged
            Assert.That(entryRef.ComponentLexemesRS[1], Is.EqualTo(bucket));          //inserted
            Assert.That(entryRef.ComponentLexemesRS[2], Is.EqualTo(the));             //moved

            UndoableUnitOfWorkHelper.Do("doit", "undoit", Cache.ActionHandlerAccessor,
                                        () => entryRef.ComponentLexemesRS.Replace(1, 1, new[] { bucket, the, bucket }));
            Assert.That(entryRef.ComponentLexemesRS.Count, Is.EqualTo(5));            //should now be kick bucket the bucket the
            Assert.That(entryRef.ComponentLexemesRS[0], Is.EqualTo(kick));            //unchanged
            Assert.That(entryRef.ComponentLexemesRS[1], Is.EqualTo(bucket));          //replaced with itself
            Assert.That(entryRef.ComponentLexemesRS[2], Is.EqualTo(the));             //inserted
            Assert.That(entryRef.ComponentLexemesRS[3], Is.EqualTo(bucket));          //inserted
            Assert.That(entryRef.ComponentLexemesRS[4], Is.EqualTo(the));             //moved

            m_actionHandler.Undo();
            Assert.That(entryRef.ComponentLexemesRS.Count, Is.EqualTo(3));             //should now be back to kick bucket the
            Assert.That(entryRef.ComponentLexemesRS[0], Is.EqualTo(kick));
            Assert.That(entryRef.ComponentLexemesRS[1], Is.EqualTo(bucket));
            Assert.That(entryRef.ComponentLexemesRS[2], Is.EqualTo(the));
        }