Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
259 additions
and
193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
Test/VsVimSharedTest/Implementation/TestableEditorAdaptersFactoryService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
using Microsoft.VisualStudio; | ||
using Microsoft.VisualStudio.Editor; | ||
using Microsoft.VisualStudio.Text; | ||
using Microsoft.VisualStudio.Text.Editor; | ||
using Microsoft.VisualStudio.TextManager.Interop; | ||
using Moq; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel.Composition; | ||
using System.Text; | ||
|
||
namespace VsVimSharedTest.Implementation | ||
{ | ||
[Export(typeof(IVsEditorAdaptersFactoryService))] | ||
[Export(typeof(TestableEditorAdaptersFactoryService))] | ||
internal sealed class TestableEditorAdaptersFactoryService : IVsEditorAdaptersFactoryService | ||
{ | ||
private MockRepository _factory = new MockRepository(MockBehavior.Loose); | ||
|
||
public IVsCodeWindow CreateVsCodeWindowAdapter(Microsoft.VisualStudio.OLE.Interop.IServiceProvider serviceProvider) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public IVsTextBuffer CreateVsTextBufferAdapter(Microsoft.VisualStudio.OLE.Interop.IServiceProvider serviceProvider, Microsoft.VisualStudio.Utilities.IContentType contentType) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public IVsTextBuffer CreateVsTextBufferAdapter(Microsoft.VisualStudio.OLE.Interop.IServiceProvider serviceProvider) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public IVsTextBuffer CreateVsTextBufferAdapterForSecondaryBuffer(Microsoft.VisualStudio.OLE.Interop.IServiceProvider serviceProvider, Microsoft.VisualStudio.Text.ITextBuffer secondaryBuffer) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public IVsTextBufferCoordinator CreateVsTextBufferCoordinatorAdapter() | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public IVsTextView CreateVsTextViewAdapter(Microsoft.VisualStudio.OLE.Interop.IServiceProvider serviceProvider, ITextViewRoleSet roles) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public IVsTextView CreateVsTextViewAdapter(Microsoft.VisualStudio.OLE.Interop.IServiceProvider serviceProvider) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public IVsTextBuffer GetBufferAdapter(ITextBuffer textBuffer) | ||
{ | ||
var lines = _factory.Create<IVsTextLines>(); | ||
IVsEnumLineMarkers markers; | ||
lines | ||
.Setup(x => x.EnumMarkers(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<uint>(), out markers)) | ||
.Returns(VSConstants.E_FAIL); | ||
return lines.Object; | ||
} | ||
|
||
public Microsoft.VisualStudio.Text.ITextBuffer GetDataBuffer(IVsTextBuffer bufferAdapter) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public Microsoft.VisualStudio.Text.ITextBuffer GetDocumentBuffer(IVsTextBuffer bufferAdapter) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public IVsTextView GetViewAdapter(ITextView textView) | ||
{ | ||
return null; | ||
} | ||
|
||
public IWpfTextView GetWpfTextView(IVsTextView viewAdapter) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public IWpfTextViewHost GetWpfTextViewHost(IVsTextView viewAdapter) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public void SetDataBuffer(IVsTextBuffer bufferAdapter, Microsoft.VisualStudio.Text.ITextBuffer dataBuffer) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
Test/VsVimSharedTest/Implementation/TestableServiceProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.ComponentModel.Composition; | ||
using System.ComponentModel.Composition.Hosting; | ||
using System.Windows.Threading; | ||
using Vim.EditorHost; | ||
using Microsoft.VisualStudio; | ||
using Microsoft.VisualStudio.Editor; | ||
using Microsoft.VisualStudio.Shell; | ||
using Microsoft.VisualStudio.Shell.Interop; | ||
using Microsoft.VisualStudio.Text; | ||
using Microsoft.VisualStudio.Text.Editor; | ||
using Microsoft.VisualStudio.TextManager.Interop; | ||
using Moq; | ||
using Vim; | ||
using Vim.Extensions; | ||
using Vim.UI.Wpf; | ||
using Vim.UnitTest; | ||
using Vim.VisualStudio.UnitTest.Mock; | ||
using Xunit; | ||
using System.Threading; | ||
using EnvDTE; | ||
using Thread = System.Threading.Thread; | ||
|
||
namespace Vim.VisualStudio.UnitTest | ||
{ | ||
[Export(typeof(SVsServiceProvider))] | ||
[Export(typeof(TestableServiceProvider))] | ||
internal sealed class TestableServiceProvider : SVsServiceProvider | ||
{ | ||
/// <summary> | ||
/// This smooths out the nonsense type equality problems that come with having NoPia | ||
/// enabled on only some of the assemblies. | ||
/// </summary> | ||
private sealed class TypeEqualityComparer : IEqualityComparer<Type> | ||
{ | ||
public bool Equals(Type x, Type y) | ||
{ | ||
return | ||
x.FullName == y.FullName && | ||
x.GUID == y.GUID; | ||
} | ||
|
||
public int GetHashCode(Type obj) | ||
{ | ||
return obj != null ? obj.GUID.GetHashCode() : 0; | ||
} | ||
} | ||
|
||
private MockRepository _factory = new MockRepository(MockBehavior.Loose); | ||
private readonly Dictionary<Type, object> _serviceMap = new Dictionary<Type, object>(new TypeEqualityComparer()); | ||
|
||
public TestableServiceProvider() | ||
{ | ||
_serviceMap[typeof(SVsShell)] = _factory.Create<IVsShell>().Object; | ||
_serviceMap[typeof(SVsTextManager)] = _factory.Create<IVsTextManager>().Object; | ||
_serviceMap[typeof(SVsRunningDocumentTable)] = _factory.Create<IVsRunningDocumentTable>().Object; | ||
_serviceMap[typeof(SVsUIShell)] = MockObjectFactory.CreateVsUIShell4(MockBehavior.Strict).Object; | ||
_serviceMap[typeof(SVsShellMonitorSelection)] = _factory.Create<IVsMonitorSelection>().Object; | ||
_serviceMap[typeof(IVsExtensibility)] = _factory.Create<IVsExtensibility>().Object; | ||
var dte = MockObjectFactory.CreateDteWithCommands(); | ||
_serviceMap[typeof(_DTE)] = dte.Object; | ||
_serviceMap[typeof(SVsStatusbar)] = _factory.Create<IVsStatusbar>().Object; | ||
_serviceMap[typeof(SDTE)] = dte.Object; | ||
_serviceMap[typeof(SVsSettingsManager)] = CreateSettingsManager().Object; | ||
_serviceMap[typeof(SVsFindManager)] = _factory.Create<IVsFindManager>().Object; | ||
} | ||
|
||
private Mock<IVsSettingsManager> CreateSettingsManager() | ||
{ | ||
var settingsManager = _factory.Create<IVsSettingsManager>(); | ||
|
||
var writableSettingsStore = _factory.Create<IVsWritableSettingsStore>(); | ||
var local = writableSettingsStore.Object; | ||
settingsManager.Setup(x => x.GetWritableSettingsStore(It.IsAny<uint>(), out local)).Returns(VSConstants.S_OK); | ||
|
||
return settingsManager; | ||
} | ||
|
||
public object GetService(Type serviceType) | ||
{ | ||
return _serviceMap[serviceType]; | ||
} | ||
} | ||
} |
Oops, something went wrong.