public void End_Text_Not_The_Same()
        {
            TwoWayDiff diffAlgorithm = new TwoWayDiff();

            DiffResult result = diffAlgorithm.PerformDiff("Common Text\nLeft Text", "Common Text\nRight Text");

            Assert.That(result.MergedSuccessfully, Is.False, "Merge should not have been successful");
            Assert.That(result.ConflictBlocks.Count, Is.EqualTo(1), "Wrong number of Blocks in conflict");

            Assert.That(result.BlockCount, Is.EqualTo(2), "Wrong number of blocks.");

            Block left = result.ConflictBlocks[0].Left;
            Block right = result.ConflictBlocks[0].Right;
            Block merged = result.ConflictBlocks[0].Merged;

            CommonTests.CheckBlocksAreNotNull(left, right, merged);
            Assert.That(result.ConflictBlocks[0].Base, Is.Null, "Base is not null");

            CommonTests.AssertConflictBlockHasThisText(left, right, merged, "Left Text", "Right Text");

            ReadOnlyCollection<ObjectList<Block>> blocks = result.GetBlocks();
            left = blocks[0].Left;
            right = blocks[0].Right;
            merged = blocks[0].Merged;

            CommonTests.CheckBlocksAreNotNull(left, right, merged);
            Assert.That(blocks[0].Base, Is.Null, "Base is not null");

            CommonTests.AssertAllHaveSameSingleLineOfText(left, right, merged, "Common Text");
        }
        public void Change_Line_Of_Text()
        {
            TwoWayDiff diffAlgorithm = new TwoWayDiff();
            DiffResult result = diffAlgorithm.PerformDiff("Common Text\nLeft Text\nCommon Text2", "Common Text\nRight Text\nCommon Text2");

            result.ChangeLine(1, "Line Text");

            Assert.That(result.Merged.Lines[1], Is.EqualTo("Line Text"));
        }
        private void Select_One_Version_Of_Conflict(ObjectVersion versionToUse, string mergedText)
        {
            TwoWayDiff diffAlgorithm = new TwoWayDiff();
            DiffResult result = diffAlgorithm.PerformDiff("Common Text\nLeft Text\nCommon Text2", "Common Text\nRight Text\nCommon Text2");

            Assert.That(result.MergedSuccessfully, Is.False, "Merge should not have been successful");
            Assert.That(result.ConflictBlocks.Count, Is.EqualTo(1), "Wrong number of Blocks in conflict");
            Assert.That(result.BlockCount, Is.EqualTo(3), "Wrong number of blocks.");

            // Use the Left text for the conflict.
            result.SelectVersionOfConflict(1, versionToUse);

            ReadOnlyCollection<ObjectList<Block>> blocks = result.GetBlocks();

            Block left = blocks[0].Left;
            Block right = blocks[0].Right;
            Block merged = blocks[0].Merged;

            CommonTests.CheckBlocksAreNotNull(left, right, merged);
            Assert.That(blocks[0].Base, Is.Null, "Base is not null");

            CommonTests.AssertAllHaveSameSingleLineOfText(left, right, merged, "Common Text");

            left = blocks[1].Left;
            right = blocks[1].Right;
            merged = blocks[1].Merged;

            CommonTests.AssertAllHaveOneLineOfText(left, right, merged);

            CommonTests.AssertSingleLineOfTextIneachVersionIsEqualTo(left, right, merged, "Left Text", "Right Text", mergedText);

            left = blocks[2].Left;
            right = blocks[2].Right;
            merged = blocks[2].Merged;

            CommonTests.CheckBlocksAreNotNull(left, right, merged);
            Assert.That(blocks[0].Base, Is.Null, "Base is not null");

            CommonTests.AssertAllHaveSameSingleLineOfText(left, right, merged, "Common Text2");

            Assert.That(result.MergedSuccessfully, Is.True, "MergedSucessfully was not set to true after all conflicts handled.");
        }
        public void Remove_Line_Of_Text_Weve_Just_Added()
        {
            TwoWayDiff diffAlgorithm = new TwoWayDiff();
            DiffResult result = diffAlgorithm.PerformDiff("Common Text\nLeft Text\nCommon Text2", "Common Text\nRight Text\nCommon Text2");

            Assert.That(result.MergedSuccessfully, Is.False);

            result.SelectVersionOfConflict(1, ObjectVersion.Left);

            Assert.That(result.MergedSuccessfully, Is.True);

            result.InsertLine(1, 0, "New Text");

            Assert.That(result.Merged.Lines.Count, Is.EqualTo(5));
            Assert.That(result.Merged.Lines[1], Is.EqualTo("New Text"));
            Assert.That(result.MergedSuccessfully, Is.False);

            // Change the line back
            result.RemoveLine(1, 0);

            Assert.That(result.Merged.Lines[1], Is.EqualTo("Left Text"));
            Assert.That(result.MergedSuccessfully, Is.True);
        }
        public void Remove_Line_Of_Existing_Text()
        {
            TwoWayDiff diffAlgorithm = new TwoWayDiff();
            DiffResult result = diffAlgorithm.PerformDiff("Common Text\nLeft Text\nCommon Text2", "Common Text\nRight Text\nCommon Text2");

            Assert.That(result.MergedSuccessfully, Is.False);
            Assert.That(result.ConflictBlocks.Count, Is.EqualTo(1));

            result.RemoveLine(2, 0);

            Assert.That(result.Merged.Lines.Count, Is.EqualTo(2));
            Assert.That(result.ConflictBlocks.Count, Is.EqualTo(2));
            Assert.That(result.MergedSuccessfully, Is.False);
        }
        public void Error_Thrown_When_Selecting_Merged_Version_Of_Conflict()
        {
            TwoWayDiff diffAlgorithm = new TwoWayDiff();
            DiffResult result = diffAlgorithm.PerformDiff("Common Text\nLeft Text\nCommon Text2", "Common Text\nRight Text\nCommon Text2");

            Assert.That(result.MergedSuccessfully, Is.False, "Merge should not have been successful");
            Assert.That(result.ConflictBlocks.Count, Is.EqualTo(1), "Wrong number of Blocks in conflict");
            Assert.That(result.BlockCount, Is.EqualTo(3), "Wrong number of blocks.");

            result.SelectVersionOfConflict(1, ObjectVersion.Merged);
        }
        public void Change_Line_Of_Text_To_Left()
        {
            TwoWayDiff diffAlgorithm = new TwoWayDiff();
            DiffResult result = diffAlgorithm.PerformDiff("Common Text\nLeft Text\nCommon Text2", "Common Text\nRight Text\nCommon Text2");

            result.InsertLine(1, 0, "Left Text");

            Assert.That(result.Merged.Lines[1], Is.EqualTo("Left Text"));
            Assert.That(result.MergedSuccessfully, Is.True);
        }