This repository was archived by the owner on Dec 19, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 221
/
Copy pathBraceSmartIndenterTestBase.cs
78 lines (65 loc) · 3 KB
/
BraceSmartIndenterTestBase.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.VisualStudio.Test;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Text.Operations;
using Moq;
using Xunit;
namespace Microsoft.VisualStudio.Editor.Razor
{
public class BraceSmartIndenterTestBase : ForegroundDispatcherTestBase
{
protected static VisualStudioDocumentTracker CreateDocumentTracker(Func<ITextBuffer> bufferAccessor, ITextView focusedTextView)
{
var tracker = new Mock<VisualStudioDocumentTracker>();
tracker.Setup(t => t.TextBuffer)
.Returns(bufferAccessor);
tracker.Setup(t => t.GetFocusedTextView())
.Returns(focusedTextView);
return tracker.Object;
}
protected static ITextView CreateFocusedTextView(Func<ITextBuffer> textBufferAccessor = null, ITextCaret caret = null)
{
var focusedTextView = new Mock<ITextView>();
focusedTextView.Setup(textView => textView.HasAggregateFocus)
.Returns(true);
if (textBufferAccessor != null)
{
focusedTextView.Setup(textView => textView.TextBuffer)
.Returns(textBufferAccessor);
}
if (caret != null)
{
focusedTextView.Setup(textView => textView.Caret)
.Returns(caret);
}
return focusedTextView.Object;
}
protected static ITextCaret CreateCaretFrom(int position, ITextSnapshot snapshot)
{
var bufferPosition = new VirtualSnapshotPoint(snapshot, position);
var caret = new Mock<ITextCaret>();
caret.Setup(c => c.Position)
.Returns(new CaretPosition(bufferPosition, new Mock<IMappingPoint>().Object, PositionAffinity.Predecessor));
caret.Setup(c => c.MoveTo(It.IsAny<SnapshotPoint>()));
return caret.Object;
}
protected static IEditorOperationsFactoryService CreateOperationsFactoryService()
{
var editorOperations = new Mock<IEditorOperations>();
editorOperations.Setup(operations => operations.MoveToEndOfLine(false));
var editorOperationsFactory = new Mock<IEditorOperationsFactoryService>();
editorOperationsFactory.Setup(factory => factory.GetEditorOperations(It.IsAny<ITextView>()))
.Returns(editorOperations.Object);
return editorOperationsFactory.Object;
}
protected static TestTextBuffer CreateTextBuffer(ITextSnapshot initialSnapshot, VisualStudioDocumentTracker documentTracker)
{
var textBuffer = new TestTextBuffer(initialSnapshot);
textBuffer.Properties.AddProperty(typeof(VisualStudioDocumentTracker), documentTracker);
return textBuffer;
}
}
}