예제 #1
0
        /// <summary> Finds the first difference in the two documents. </summary>
        private static void FindDifference(SerializeNode currentState, SerializeNode originalState, string path)
        {
            DidYouKnow.That(currentState.TypeId).Should()
            .Be(originalState.TypeId);

            var type = currentState.TypeId;

            path += "<" + type + ">";

            var fullPath = path + ".Data";

            DidYouKnow.That(currentState.GetDataOrDefault <string>("Body")).Should()
            .Be(originalState.GetDataOrDefault <string>("Body"));

            int max = Math.Min(currentState.Children.Count, originalState.Children.Count);

            for (int i = 0; i < max; i++)
            {
                FindDifference(currentState.Children[i], originalState.Children[i], path + ".[" + i + "]");
            }

            var theFullPath = path + ".Count";

            DidYouKnow.That(currentState.Children.Count).Should().Be(originalState.Children.Count);
        }
예제 #2
0
        public void TryMerge_WithSelf_Fails()
        {
            BlockAt <TextBlock>(0).GetCaretAtStart().AsTextCursor().InsertText("This is text");

            var self = new InsertTextCommand.InsertTextUndoableAction(BlockAt <TextBlock>(0).BeginCursor(1).ToHandle(), "One");

            DidYouKnow.That(self.TryMerge(Context, self)).Should().BeFalse();
        }
예제 #3
0
        public void TryMerge_DoesNotMergeWhenNotNextToEachother()
        {
            BlockAt <TextBlock>(0).GetCaretAtStart().AsTextCursor().InsertText("This is text");

            var first =
                new InsertTextCommand.InsertTextUndoableAction(BlockAt <TextBlock>(0).BeginCursor(1).ToHandle(), "One");
            var second =
                new InsertTextCommand.InsertTextUndoableAction(BlockAt <TextBlock>(0).BeginCursor(2).ToHandle(), "Two");

            DidYouKnow.That(first.TryMerge(Context, second)).Should().BeFalse();
        }
        public void VerifyItWorks()
        {
            var it = DoAll(
                new Func <UndoableAction>[]
            {
                FromCommand <InsertTextCommand, string>(() => BlockAt(0).BeginCursor().ToHandle(), "TheWord"),
                FromCommand <DeletePreviousCharacterCommand>(() => BlockAt(0).BeginCursor(3).AsTextCursor().ToHandle()),
            });

            DidYouKnow.That(BlockAt(0).AsText()).Should().Be("ThWord");
            it.VerifyUndo();
        }
예제 #5
0
        public void DeleteNextCharacter_WorksAtAllLocationsInTheParagraph(string text, int deleteIndex, string expected)
        {
            var it = DoAll(
                new Func <UndoableAction>[]
            {
                FromCommand <InsertTextCommand, string>(() => BlockAt(0).BeginCursor().ToHandle(), text),
                () => new DeleteNextCharacterCommand.DeleteNextCharacterAction(BlockAt(0).BeginCaret(deleteIndex).AsTextCursor()),
            });

            DidYouKnow.That(BlockAt(0).AsText()).Should().Be(expected);
            it.VerifyUndo();
        }
예제 #6
0
        public void VerifyMergeWith_ModifiesOriginalAction()
        {
            var originalAction =
                new InsertTextCommand.InsertTextUndoableAction(BlockAt(0).EndCursor().ToHandle(), "The text");

            originalAction.Do(Context);

            var mergeWithAction =
                new InsertTextCommand.InsertTextUndoableAction(BlockAt(0).EndCursor().ToHandle(), "And More");

            DidYouKnow.That(originalAction.TryMerge(Context, mergeWithAction)).Should().BeTrue();
            DidYouKnow.That(originalAction.Text).Should().Be("The textAnd More");
        }
예제 #7
0
        public void InsertAtMiddle_InsertsTextInMiddle()
        {
            var it = DoAll(new Func <UndoableAction>[]
            {
                FromCommand <InsertTextCommand, string>(() => BlockAt(0).BeginCursor().ToHandle(), "Word"), FromCommand <InsertTextCommand, string>(() => BlockAt(0).BeginCursor(2).ToHandle(), "Mid"),
            });

            DidYouKnow.That(Document.Root.ChildCount).Should().Be(1);
            DidYouKnow.That(BlockAt(0)).Should().BeAssignableTo <TextBlock>();

            DidYouKnow.That(BlockAt(0).As <TextBlock>().AsText()).Should().Be("WoMidrd");

            it.VerifyUndo();
        }
예제 #8
0
        public void MergeAt_EndOfFirstBlock_MergesIntoOne()
        {
            var it = DoAll(new Func <UndoableAction>[]
            {
                FromCommand <MergeTextBlocksCommand>(() => BlockAt(0).EndCursor().ToHandle()),
            });

            DidYouKnow.That(Document.Root.ChildCount).Should().Be(1);
            DidYouKnow.That(BlockAt(0)).Should().BeAssignableTo <TextBlock>();

            DidYouKnow.That(BlockAt(0).As <TextBlock>().AsText()).Should().Be("Paragraph 1Paragraph 2");

            it.VerifyUndo();
        }
예제 #9
0
        public void Action_Works()
        {
            var it = DoAll(new Func <UndoableAction>[]
            {
                () => new ConvertTextBlockIntoHeadingAction((TextCaret)Context.Selection.Start, 0),
            });

            var heading = Document.Root.FirstBlock.As <HeadingBlock>();

            DidYouKnow.That(heading).Should().NotBeNull();
            DidYouKnow.That(heading.HeadingLevel).Should().Be(0);
            DidYouKnow.That(heading.AsText()).Should().Be("This is the text");

            it.VerifyUndo();
        }
예제 #10
0
        public void TryMerge_WorksOnLargerStrings()
        {
            BlockAt <TextBlock>(0).GetCaretAtStart().AsTextCursor().InsertText("This is text");

            var first =
                new InsertTextCommand.InsertTextUndoableAction(BlockAt <TextBlock>(0).BeginCursor().ToHandle(),
                                                               "This is a long string");

            first.Do(Context);
            var second = new InsertTextCommand.InsertTextUndoableAction(
                BlockAt <TextBlock>(0).BeginCursor(first.Text.Length).ToHandle(),
                "This is also long");

            DidYouKnow.That(first.TryMerge(Context, second)).Should().BeTrue();
        }
예제 #11
0
        public void VerifyMergeWith_DoesNotActsOnDocument()
        {
            var originalAction =
                new InsertTextCommand.InsertTextUndoableAction(BlockAt(0).EndCursor().ToHandle(), "The text");

            originalAction.Do(Context);

            var mergeWithAction =
                new InsertTextCommand.InsertTextUndoableAction(BlockAt(0).EndCursor().ToHandle(), "And More");

            originalAction.TryMerge(Context, mergeWithAction);

            // the document should not be modified
            DidYouKnow.That(BlockAt <TextBlock>(0).AsText()).Should().Be("The text");
        }
예제 #12
0
        public void VerifyItWorks()
        {
            var it = DoAll(new Func <UndoableAction>[]
            {
                FromCommand <InsertTextCommand, string>(() => Context.Selection, "The text"),
            });

            var textBlock = Document.Root.FirstBlock as TextBlock;

            DidYouKnow.That(textBlock).Should().NotBeNull();

            DidYouKnow.That(textBlock.AsText()).Should().Be("The text");
            DidYouKnow.That(Context.Caret.Block).Should().Be(textBlock);
            DidYouKnow.That(Context.Caret.IsAtBlockEnd).Should().BeTrue();

            it.VerifyUndo();
        }
예제 #13
0
        public void Break_BreaksIntoTwo(string whole, int splitIndex, string left, string right)
        {
            var it = DoAll(new Func <UndoableAction>[]
            {
                FromCommand <InsertTextCommand, string>(() => BlockAt(0).EndCursor().ToHandle(), whole),
                FromCommand <BreakTextBlockCommand>(() => BlockAt(0).BeginCursor(splitIndex).ToHandle()),
            });

            DidYouKnow.That(Document.Root.ChildCount).Should().Be(2);
            DidYouKnow.That(BlockAt(0)).Should().BeAssignableTo <TextBlock>();
            DidYouKnow.That(BlockAt(1)).Should().BeAssignableTo <TextBlock>();

            DidYouKnow.That(BlockAt(0).As <TextBlock>().AsText()).Should().Be(left);
            DidYouKnow.That(BlockAt(1).As <TextBlock>().AsText()).Should().Be(right);

            it.VerifyUndo();
        }
예제 #14
0
        public void ExecutingOnHeading_SimplyChangesLevel()
        {
            DoAll(new Func <UndoableAction>[]
            {
                () => new ConvertTextBlockIntoHeadingAction((TextCaret)Context.Selection.Start, 0),
            });

            var heading = Document.Root.FirstBlock.As <HeadingBlock>();

            DoAll(new Func <UndoableAction>[]
            {
                () => new ConvertTextBlockIntoHeadingAction((TextCaret)Context.Selection.Start, 3),
            });

            DidYouKnow.That(heading).Should().BeSameAs(Document.Root.FirstBlock);
            DidYouKnow.That(heading.HeadingLevel).Should().Be(3);
        }
예제 #15
0
        /// <summary> Check that the two documents are equal. </summary>
        private static void CheckEqual(DocumentOwner originalState, DocumentOwner currentState)
        {
            var originalJson = JsonConvert.SerializeObject(originalState.SerializeAsNode(), Formatting.Indented);
            var newJson      = JsonConvert.SerializeObject(currentState.SerializeAsNode(), Formatting.Indented);

            if (originalState.Equals(currentState))
            {
                DidYouKnow.That(newJson).Should().Be(originalJson);
                return;
            }

            Console.WriteLine("===== Original State: =====");
            Console.WriteLine(originalJson);
            Console.WriteLine("===== Current State: =====");
            Console.WriteLine(newJson);

            FindDifference(currentState.SerializeAsNode(), originalState.SerializeAsNode(), "");
        }
예제 #16
0
        public void TryMerge_WithBackspace_DoesNotWorkWhenInsertionIsEmpty()
        {
            var fakeInsertion =
                new InsertTextCommand.InsertTextUndoableAction(BlockAt <TextBlock>(0).BeginCursor().ToHandle(),
                                                               "1234");

            fakeInsertion.Do(Context);
            Context.UndoStack.Clear();

            var insertion =
                new InsertTextCommand.InsertTextUndoableAction(BlockAt <TextBlock>(0).BeginCursor().ToHandle(), "");

            insertion.Do(Context);
            var second =
                new DeletePreviousCharacterCommand.DeletePreviousCharacterAction(
                    BlockAt <TextBlock>(0).BeginCaret(4).AsTextCursor());

            DidYouKnow.That(insertion.TryMerge(Context, second)).Should().BeFalse();
        }
예제 #17
0
        public void TryMerge_WithBackspaceAction_Works()
        {
            BlockAt <TextBlock>(0).GetCaretAtStart().AsTextCursor().InsertText("This is text");

            var insertion =
                new InsertTextCommand.InsertTextUndoableAction(BlockAt <TextBlock>(0).BeginCursor().ToHandle(),
                                                               "Inserted String");

            insertion.Do(Context);
            var second =
                new DeletePreviousCharacterCommand.DeletePreviousCharacterAction(
                    BlockAt <TextBlock>(0).BeginCaret(insertion.Text.Length).AsTextCursor());

            DidYouKnow.That(insertion.TryMerge(Context, second)).
            Should().BeTrue();

            DidYouKnow.That(insertion.Text).Should()
            .Be("Inserted Strin");
        }