SourceTextContainerExtensionsTests.cs 1.5 KB
Newer Older
B
beep boop 已提交
1 2 3
// Copyright (c) Microsoft.  All Rights Reserved.  Licensed under the Apache License, Version 2.0.  See License.txt in the project root for license information.

using Microsoft.CodeAnalysis.Text;
4 5 6 7 8 9 10
using Moq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;
11
using Roslyn.Test.Utilities;
12 13 14 15 16

namespace Microsoft.CodeAnalysis.Editor.UnitTests.Extensions
{
    public class SourceTextContainerExtensionsTests
    {
17
        [Fact]
18 19 20
        public void GetBufferTextFromNonTextContainerThrows()
        {
            var containerMock = new Mock<SourceTextContainer>();
21
            Assert.Throws<ArgumentException>(() => Microsoft.CodeAnalysis.Text.Extensions.GetTextBuffer(containerMock.Object));
22 23
        }

24
        [Fact]
25
        public void GetBufferTextFromTextContainerDoesNotThrow()
26
        {
C
CyrusNajmabadi 已提交
27 28
            var textImageMock = new Mock<VisualStudio.Text.ITextImage>();
            var textSnapshotMock = new Mock<VisualStudio.Text.ITextSnapshot2>();
29
            var bufferMock = new Mock<VisualStudio.Text.ITextBuffer>();
C
CyrusNajmabadi 已提交
30 31

            textSnapshotMock.Setup(s => s.TextImage).Returns(textImageMock.Object);
32 33 34
            bufferMock.SetupGet(x => x.CurrentSnapshot).Returns(textSnapshotMock.Object);
            bufferMock.SetupGet(x => x.Properties).Returns(new VisualStudio.Utilities.PropertyCollection());

C
CyrusNajmabadi 已提交
35
            var textContainer = Text.Extensions.TextBufferContainer.From(bufferMock.Object);
36

C
CyrusNajmabadi 已提交
37
            Text.Extensions.GetTextBuffer(textContainer);
38 39
        }
    }
C
CyrusNajmabadi 已提交
40
}