// 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 bufferAccessor, ITextView focusedTextView) { var tracker = new Mock(); tracker.Setup(t => t.TextBuffer) .Returns(bufferAccessor); tracker.Setup(t => t.GetFocusedTextView()) .Returns(focusedTextView); return tracker.Object; } protected static ITextView CreateFocusedTextView(Func textBufferAccessor = null, ITextCaret caret = null) { var focusedTextView = new Mock(); 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(); caret.Setup(c => c.Position) .Returns(new CaretPosition(bufferPosition, new Mock().Object, PositionAffinity.Predecessor)); caret.Setup(c => c.MoveTo(It.IsAny())); return caret.Object; } protected static IEditorOperationsFactoryService CreateOperationsFactoryService() { var editorOperations = new Mock(); editorOperations.Setup(operations => operations.MoveToEndOfLine(false)); var editorOperationsFactory = new Mock(); editorOperationsFactory.Setup(factory => factory.GetEditorOperations(It.IsAny())) .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; } } }