/// <summary> /// Get an IVsTrackProjectDocuments2 that implement AdviseTrackProjectDocumentsEvents and UnadviseTrackProjectDocumentsEvents. /// </summary> /// <returns></returns> internal static BaseMock GetTrackProjectDocuments() { BaseMock tpd = GetBaseTrackProjectDocuments(); string name = string.Format("{0}.{1}", typeof(IVsTrackProjectDocuments2).FullName, "AdviseTrackProjectDocumentsEvents"); tpd.AddMethodCallback(name, new EventHandler <CallbackArgs>(AdviseTrackProjectDocumentsEventsCallBack)); name = string.Format("{0}.{1}", typeof(IVsTrackProjectDocuments2).FullName, "UnadviseTrackProjectDocumentsEvents"); tpd.AddMethodCallback(name, new EventHandler <CallbackArgs>(UnadviseTrackProjectDocumentsEventsCallBack)); return(tpd); }
/// <summary> /// Returns a SVsSolutionBuildManager that implements IVsSolutionBuildManager2 and IVsSolutionBuildManager3 /// </summary> /// <returns></returns> internal static BaseMock GetSolutionBuildManagerInstance0() { BaseMock buildManager = GetSolutionBuildManagerInstance(); string name = string.Format("{0}.{1}", typeof(IVsSolutionBuildManager2).FullName, "AdviseUpdateSolutionEvents"); buildManager.AddMethodCallback(name, new EventHandler <CallbackArgs>(AdviseUpdateSolutionEventsCallBack)); name = string.Format("{0}.{1}", typeof(IVsSolutionBuildManager3).FullName, "AdviseUpdateSolutionEvents3"); buildManager.AddMethodCallback(name, new EventHandler <CallbackArgs>(AdviseUpdateSolutionEvents3CallBack)); return(buildManager); }
/// <summary> /// Get an IVsUiShell that implement CreateToolWindow and GetToolWindowEnum. /// The enumeration contains 2 windows. /// </summary> /// <returns></returns> internal static BaseMock GetWindowEnumerator2() { BaseMock uiShell = GetUiShellInstance(); string name = string.Format("{0}.{1}", typeof(IVsUIShell).FullName, "CreateToolWindow"); uiShell.AddMethodCallback(name, new EventHandler <CallbackArgs>(CreateToolWindowCallBack)); name = string.Format("{0}.{1}", typeof(IVsUIShell).FullName, "GetToolWindowEnum"); uiShell.AddMethodCallback(name, new EventHandler <CallbackArgs>(GetToolWindowEnumCallBack2)); return(uiShell); }
/// <summary> /// Get an IVsUiShell that implements SetWaitCursor, SaveDocDataToFile, ShowMessageBox /// </summary> /// <returns>uishell mock</returns> internal static BaseMock GetUiShellInstance0() { BaseMock uiShell = GetUiShellInstance(); string name = $"{typeof(IVsUIShell).FullName}.{"SetWaitCursor"}"; uiShell.AddMethodCallback(name, SetWaitCursorCallBack); name = $"{typeof(IVsUIShell).FullName}.{"SaveDocDataToFile"}"; uiShell.AddMethodCallback(name, SaveDocDataToFileCallBack); name = $"{typeof(IVsUIShell).FullName}.{"ShowMessageBox"}"; uiShell.AddMethodCallback(name, ShowMessageBoxCallBack); return(uiShell); }
/// <summary> /// Get an IVsUiShell that implements SetWaitCursor, SaveDocDataToFile, ShowMessageBox /// </summary> /// <returns>uishell mock</returns> internal static BaseMock GetUiShellInstance0() { BaseMock uiShell = GetUiShellInstance(); string name = string.Format("{0}.{1}", typeof(IVsUIShell).FullName, "SetWaitCursor"); uiShell.AddMethodCallback(name, new EventHandler <CallbackArgs>(SetWaitCursorCallBack)); name = string.Format("{0}.{1}", typeof(IVsUIShell).FullName, "SaveDocDataToFile"); uiShell.AddMethodCallback(name, new EventHandler <CallbackArgs>(SaveDocDataToFileCallBack)); name = string.Format("{0}.{1}", typeof(IVsUIShell).FullName, "ShowMessageBox"); uiShell.AddMethodCallback(name, new EventHandler <CallbackArgs>(ShowMessageBoxCallBack)); return(uiShell); }
/// <summary> /// Return an IVsWindowFrame implements GetProperty /// The peopertiesList will be used too look up PropertyIDs to find values for /// requested properties /// </summary> /// <param name="propertiesList">The dictionary contains PropertyID/Value pairs</param> /// <returns></returns> internal static IVsWindowFrame GetFrameWithProperties(Dictionary <int, object> propertiesList) { BaseMock frame = (BaseMock)FrameFactory.GetInstance(); frame[propertiesName] = propertiesList; // Add support for GetProperty string name = string.Format("{0}.{1}", typeof(IVsWindowFrame).FullName, "GetProperty"); frame.AddMethodCallback(name, new EventHandler <CallbackArgs>(GetPropertiesCallBack)); // Add support for GetGuidProperty name = string.Format("{0}.{1}", typeof(IVsWindowFrame).FullName, "GetGuidProperty"); frame.AddMethodCallback(name, new EventHandler <CallbackArgs>(GetPropertiesCallBack)); return((IVsWindowFrame)frame); }
public void TestFlushFromASCII() { BaseMock mockBuffer = MockFactories.CreateBufferWithMarker(); mockBuffer.AddMethodReturnValues(string.Format("{0}.{1}", typeof(IVsTextLines).FullName, "GetLastLineIndex"), new object[] { 0, 11, 42 }); mockBuffer["Text"] = ""; mockBuffer.AddMethodCallback(string.Format("{0}.{1}", typeof(IVsTextLines).FullName, "ReplaceLines"), new EventHandler <CallbackArgs>(ReplaceLinesCallback)); using (Stream stream = CreateTextBufferStream((IVsTextLines)mockBuffer)) { string test = "� Test �"; using (StreamWriter writer = new StreamWriter(stream, System.Text.Encoding.ASCII)) { writer.Write(test); writer.Flush(); // There is no ASCII translation for �, so the standard replacement is used. Assert.IsTrue((string)mockBuffer["Text"] == "? Test ?"); } } int lockCount = mockBuffer.FunctionCalls(string.Format("{0}.{1}", typeof(IVsTextLines).FullName, "LockBuffer")); int unlockCount = mockBuffer.FunctionCalls(string.Format("{0}.{1}", typeof(IVsTextLines).FullName, "UnlockBuffer")); Assert.IsTrue(lockCount == unlockCount); }
public void ConsoleTextOfLineNoMarker() { string testString = "Test"; using (OleServiceProvider provider = new OleServiceProvider()) { BaseMock textLinesMock = MockFactories.TextBufferFactory.GetInstance(); textLinesMock.AddMethodCallback( string.Format("{0}.{1}", typeof(IVsTextLines).FullName, "GetLineText"), new EventHandler <CallbackArgs>(GetLineTextCallbackForConsoleTextOfLine)); textLinesMock["LineText"] = testString; textLinesMock["ExpectedLine"] = 1; textLinesMock["ExpectedStart"] = 0; textLinesMock["ExpectedEnd"] = 10; // Create a new local registry class. LocalRegistryMock mockRegistry = new LocalRegistryMock(); // Add the text buffer to the list of the classes that local registry can create. mockRegistry.AddClass(typeof(VsTextBufferClass), textLinesMock); // Add the local registry to the service provider. provider.AddService(typeof(SLocalRegistry), mockRegistry, false); // Create the console. using (ToolWindowPane windowPane = CommandWindowHelper.CreateConsoleWindow(provider) as ToolWindowPane) { IConsoleText consoleText = windowPane as IConsoleText; Assert.IsNull(consoleText.TextOfLine(1, -1, true)); Assert.IsNull(consoleText.TextOfLine(1, -1, false)); string text = consoleText.TextOfLine(1, 10, false); Assert.IsTrue(testString == text); } } }
public void OneTriggerNoText() { using (OleServiceProvider provider = new OleServiceProvider()) { ResetScopeState(); // Create a mock engine provider. BaseMock mockEngineProvider = MockFactories.EngineProviderFactory.GetInstance(); // Create a mock engine. BaseMock mockEngine = MockFactories.EngineFactory.GetInstance(); // Set this engine as the one returned from the GetSharedEngine of the engine provider. mockEngineProvider.AddMethodReturnValues( string.Format("{0}.{1}", typeof(IPythonEngineProvider), "GetSharedEngine"), new object[] { (IEngine)mockEngine }); // Add the engine provider to the list of the services. provider.AddService(typeof(IPythonEngineProvider), mockEngineProvider, false); // Create the scanner for this test. BaseMock scannerMock = MockFactories.ScannerFactory.GetInstance(); scannerMock["Iteration"] = 0; TokenInfo token = new TokenInfo(); token.StartIndex = 0; token.EndIndex = 1; token.Trigger = TokenTriggers.MemberSelect; scannerMock["Tokens"] = new TokenInfo[] { token }; scannerMock.AddMethodCallback( string.Format("{0}.{1}", typeof(IScanner).FullName, "ScanTokenAndProvideInfoAboutIt"), new EventHandler <CallbackArgs>(StandardScannerCallback)); Declarations declarations = ExecuteGetDeclarations(".", scannerMock as IScanner, provider); Assert.IsTrue(0 == mockEngine.TotalCallsAllFunctions()); } }
public void CommandBufferAddWithThrowingExecute() { // Create the mock engine. BaseMock mockEngine = MockFactories.EngineFactory.GetInstance(); // Set the callback function for the ExecuteToConsole method of the engine to the throwing one. mockEngine.AddMethodCallback( string.Format("{0}.{1}", typeof(IEngine).FullName, "ExecuteToConsole"), new EventHandler <CallbackArgs>(ThrowingExecuteCallback)); // Make sure that the execute is called. mockEngine.AddMethodReturnValues(parseFunctionName, new object[] { true }); CommandBuffer buffer = new CommandBuffer(mockEngine as IEngine); bool exceptionThrown = false; try { buffer.Add("Test Line"); } catch (ExecuteException) { exceptionThrown = true; } Assert.IsTrue(exceptionThrown); Assert.IsTrue(string.IsNullOrEmpty(buffer.Text)); }
/// <summary> /// Gets an IVsQueryEditQuerySave2 mock object which implements QuerySaveFile and QueryEditFiles methods /// </summary> /// <returns></returns> internal static BaseMock GetQueryEditQuerySaveInstance() { if (null == qeqsFactory) { qeqsFactory = new GenericMockFactory("QueryEditQuerySave", new Type[] { typeof(IVsQueryEditQuerySave2) }); } BaseMock qeqs = qeqsFactory.GetInstance(); string name = string.Format("{0}.{1}", typeof(IVsQueryEditQuerySave2).FullName, "QuerySaveFile"); qeqs.AddMethodCallback(name, new EventHandler <CallbackArgs>(QuerySaveFileCallBack)); name = string.Format("{0}.{1}", typeof(IVsQueryEditQuerySave2).FullName, "QueryEditFiles"); qeqs.AddMethodCallback(name, new EventHandler <CallbackArgs>(QueryEditFilesCallBack)); return(qeqs); }
/// <summary> /// Get an IVsShell that implement GetProperty /// </summary> /// <returns></returns> internal static BaseMock GetShellForUI() { BaseMock Shell = GetShellInstance(); string name = string.Format("{0}.{1}", typeof(IVsShell).FullName, "GetProperty"); Shell.AddMethodCallback(name, new EventHandler <CallbackArgs>(GetPropertyCallBack2)); return(Shell); }
public static IVsOutputWindowPane OutputPaneWithStringFunctions() { BaseMock mock = OutputWindowPaneFactory.GetInstance(); mock["StringBuilder"] = new System.Text.StringBuilder(); mock.AddMethodCallback( string.Format("{0}.{1}", typeof(IVsOutputWindowPane).FullName, "OutputString"), new EventHandler <CallbackArgs>(OutputStringCallback)); mock.AddMethodCallback( string.Format("{0}.{1}", typeof(IVsOutputWindowPane).FullName, "OutputStringThreadSafe"), new EventHandler <CallbackArgs>(OutputStringCallback)); mock.AddMethodCallback( string.Format("{0}.{1}", typeof(IVsOutputWindowPane).FullName, "Clear"), new EventHandler <CallbackArgs>(ClearOutputCallback)); return(mock as IVsOutputWindowPane); }
public static BaseMock CreateBufferWithMarker() { BaseMock bufferMock = TextBufferFactory.GetInstance(); BaseMock markerMock = TextLineMarkerFactory.GetInstance(); markerMock.AddMethodCallback( string.Format("{0}.{1}", typeof(IVsTextLineMarker).FullName, "ResetSpan"), new EventHandler <CallbackArgs>(StandardMarkerResetSpanCallback)); markerMock.AddMethodCallback( string.Format("{0}.{1}", typeof(IVsTextLineMarker).FullName, "GetCurrentSpan"), new EventHandler <CallbackArgs>(StandardMarkerGetCurrentSpanCallback)); bufferMock["LineMarker"] = markerMock; bufferMock.AddMethodCallback( string.Format("{0}.{1}", typeof(IVsTextLines).FullName, "CreateLineMarker"), new EventHandler <CallbackArgs>(CreateMarkerCallback)); return(bufferMock); }
/// <summary> /// Get an IVsUiShell that implement ShowMessageBox and returns Cancel from pressing the buttons /// </summary> /// <returns></returns> internal static BaseMock GetShowMessageBoxCancel() { BaseMock uiShell = GetUiShellInstance(); string name = string.Format("{0}.{1}", typeof(IVsUIShell).FullName, "ShowMessageBox"); uiShell.AddMethodCallback(name, new EventHandler <CallbackArgs>(ShowMessageBoxCancel)); return(uiShell); }
/// <summary> /// Get a property bag that implements Write method /// </summary> /// <returns></returns> internal static BaseMock GetWritePropertyBag() { BaseMock pb = GetPBInstance(); string name = string.Format("{0}.{1}", typeof(IPropertyBag).FullName, "Write"); pb.AddMethodCallback(name, new EventHandler <CallbackArgs>(WriteCallback)); return(pb); }
/// <summary> /// Returns a monitor selection object that implement GetCurrentSelection and GetSelectionInfo/GetSelectedItems /// </summary> /// <returns></returns> internal static BaseMock GetMonSel() { BaseMock pb = GetBaseMonSelInstance(); // Add the callback methods string name = string.Format("{0}.{1}", typeof(IVsMonitorSelection).FullName, "GetCurrentSelection"); pb.AddMethodCallback(name, new EventHandler <CallbackArgs>(GetCurrentSelectionCallback)); name = string.Format("{0}.{1}", typeof(IVsMultiItemSelect).FullName, "GetSelectionInfo"); pb.AddMethodCallback(name, new EventHandler <CallbackArgs>(GetSelectionInfoCallback)); name = string.Format("{0}.{1}", typeof(IVsMultiItemSelect).FullName, "GetSelectedItems"); pb.AddMethodCallback(name, new EventHandler <CallbackArgs>(GetSelectedItemsCallback)); // Initialize selection data to empty selection pb["Selection"] = null; return(pb); }
/// <summary> /// Get an IVsUiShell that implement CreateToolWindow (negative test) /// </summary> /// <returns>uishell mock</returns> internal static BaseMock GetUiShellInstanceCreateToolWinReturnsNull() { BaseMock uiShell = GetUiShellInstance(); string name = $"{typeof(IVsUIShell).FullName}.{"CreateToolWindow"}"; uiShell.AddMethodCallback(name, CreateToolWindowNegativeTestCallBack); return(uiShell); }
internal static BaseMock GetILocalRegistryInstance() { GenericMockFactory factory = new GenericMockFactory("ILocalRegistry", new Type[] { typeof(ILocalRegistry) }); BaseMock mockObj = factory.GetInstance(); string name = string.Format("{0}.{1}", typeof(ILocalRegistry).FullName, "CreateInstance"); mockObj.AddMethodCallback(name, new EventHandler <CallbackArgs>(CreateInstanceCallBack)); return(mockObj); }
/// <summary> /// Get an IVsUiShell that implement CreateToolWindow (negative test) /// </summary> /// <returns>uishell mock</returns> internal static BaseMock GetUiShellInstanceCreateToolWinReturnsNull() { BaseMock uiShell = GetUiShellInstance(); string name = string.Format("{0}.{1}", typeof(IVsUIShell).FullName, "CreateToolWindow"); uiShell.AddMethodCallback(name, new EventHandler <CallbackArgs>(CreateToolWindowNegativeTestCallBack)); return(uiShell); }
/// <summary> /// Get an IVsUiShell that implement CreateToolWindow /// </summary> /// <returns>uishell mock</returns> internal static BaseMock GetUiShellInstanceCreateToolWin() { BaseMock uiShell = GetUiShellInstance(); string name = string.Format("{0}.{1}", typeof(IVsUIShell).FullName, "CreateToolWindow"); uiShell.AddMethodCallback(name, CreateToolWindowCallBack); return(uiShell); }
public static BaseMock GetInstance() { BaseMock mock = factory.GetInstance(); string name = string.Format("{0}.{1}", typeof(IVsShell).FullName, "GetProperty"); mock.AddMethodCallback(name, new EventHandler <CallbackArgs>(GetPropertyCallBack)); return(mock); }
private static BaseMock CreateDefaultEngine() { // Create the mock. BaseMock mockEngine = MockFactories.EngineFactory.GetInstance(); // Set the callback function for the ExecuteToConsole method of the engine. mockEngine.AddMethodCallback( string.Format("{0}.{1}", typeof(IEngine).FullName, "ExecuteToConsole"), new EventHandler <CallbackArgs>(ExecuteToConsoleCallback)); return(mockEngine); }
/// <summary> /// Get an ITrackSelection mock object which implements the OnSelectChange method /// </summary> /// <returns></returns> internal static BaseMock GetTrackSelectionInstance() { if (trackSelFactory == null) { trackSelFactory = new GenericMockFactory("MockTrackSelection", new Type[] { typeof(ITrackSelection) }); } BaseMock trackSel = trackSelFactory.GetInstance(); string name = string.Format("{0}.{1}", typeof(ITrackSelection).FullName, "OnSelectChange"); trackSel.AddMethodCallback(name, new EventHandler <CallbackArgs>(OnSelectChangeCallBack)); return(trackSel); }
internal static BaseMock GetInstance() { //Create a base mock GenericMockFactory factory = new GenericMockFactory("ILocalRegistry3", new Type[] { typeof(ILocalRegistry3) }); BaseMock mockObj = factory.GetInstance(); //Add method call back for GetLocalRegistryRoot string methodName = string.Format("{0}.{1}", typeof(ILocalRegistry3).FullName, "GetLocalRegistryRoot"); mockObj.AddMethodCallback(methodName, new EventHandler <CallbackArgs>(GetLocalRegistryRootCallBack)); return(mockObj); }
public static BaseMock CreateMSBuildEventSource() { BaseMock mockSource = MSBuildEventSourceFactory.GetInstance(); mockSource.AddMethodCallback( string.Format("{0}.{1}", typeof(IEventSource).FullName, "add_MessageRaised"), new EventHandler <CallbackArgs>(EventSourceAddMessageRaised)); mockSource.AddMethodCallback( string.Format("{0}.{1}", typeof(IEventSource).FullName, "add_BuildFinished"), new EventHandler <CallbackArgs>(EventSourceAddBuildFinished)); mockSource.AddMethodCallback( string.Format("{0}.{1}", typeof(IEventSource).FullName, "add_BuildStarted"), new EventHandler <CallbackArgs>(EventSourceAddBuildStarted)); mockSource.AddMethodCallback( string.Format("{0}.{1}", typeof(IEventSource).FullName, "add_TaskStarted"), new EventHandler <CallbackArgs>(EventSourceAddTaskStarted)); mockSource.AddMethodCallback( string.Format("{0}.{1}", typeof(IEventSource).FullName, "add_TaskFinished"), new EventHandler <CallbackArgs>(EventSourceAddTaskFinished)); return(mockSource); }
public static BaseMock GetInstance() { BaseMock mock = factory.GetInstance(); string name = string.Format("{0}.{1}", typeof(IVsWindowFrame).FullName, "SetProperty"); mock.AddMethodReturnValues(name, new object[] { VSConstants.S_OK }); name = string.Format("{0}.{1}", typeof(ILocalRegistry3).FullName, "GetLocalRegistryRoot"); mock.AddMethodCallback(name, new EventHandler <CallbackArgs>(GetLocalRegistryRoot)); return(mock); }
public void TextViewCreation() { using (OleServiceProvider provider = new OleServiceProvider()) { // Create a mock text buffer for the console. BaseMock textLinesMock = MockFactories.TextBufferFactory.GetInstance(); LocalRegistryMock mockLocalRegistry = new LocalRegistryMock(); mockLocalRegistry.AddClass(typeof(VsTextBufferClass), textLinesMock); // Define the mock object for the text view. BaseMock textViewMock = MockFactories.TextViewFactory.GetInstance(); textViewMock.AddMethodCallback(string.Format("{0}.{1}", typeof(IObjectWithSite).FullName, "SetSite"), new EventHandler <CallbackArgs>(TextViewSetSiteCallback)); textViewMock.AddMethodCallback(string.Format("{0}.{1}", typeof(IVsTextView).FullName, "Initialize"), new EventHandler <CallbackArgs>(TextViewInitializeCallback)); mockLocalRegistry.AddClass(typeof(VsTextViewClass), textViewMock); // Add the local registry to the list of services. provider.AddService(typeof(SLocalRegistry), mockLocalRegistry, false); // Create the tool window. using (IDisposable disposableObject = CommandWindowHelper.CreateConsoleWindow(provider) as IDisposable) { IVsWindowPane windowPane = disposableObject as IVsWindowPane; Assert.IsNotNull(windowPane); // Call the CreatePaneWindow method that will force the creation of the text view. IntPtr newHwnd; Assert.IsTrue(Microsoft.VisualStudio.ErrorHandler.Succeeded( windowPane.CreatePaneWindow(IntPtr.Zero, 0, 0, 0, 0, out newHwnd))); // Verify that the text view was used as expected. Assert.IsTrue(1 == textViewMock.FunctionCalls(string.Format("{0}.{1}", typeof(IObjectWithSite), "SetSite"))); Assert.IsTrue(1 == textViewMock.FunctionCalls(string.Format("{0}.{1}", typeof(IVsTextView), "Initialize"))); } } }
/// <summary> /// Gets the IVsRunningDocumentTable mock object which implements FindAndLockIncrement, /// NotifyDocumentChanged and UnlockDocument /// </summary> /// <returns></returns> internal static BaseMock GetRunningDocTableInstance() { if (null == runningDocFactory) { runningDocFactory = new GenericMockFactory("RunningDocumentTable", new Type[] { typeof(IVsRunningDocumentTable) }); } BaseMock runningDoc = runningDocFactory.GetInstance(); string name = string.Format("{0}.{1}", typeof(IVsRunningDocumentTable).FullName, "FindAndLockDocument"); runningDoc.AddMethodCallback(name, new EventHandler <CallbackArgs>(FindAndLockDocumentCallBack)); name = string.Format("{0}.{1}", typeof(IVsRunningDocumentTable).FullName, "NotifyDocumentChanged"); runningDoc.AddMethodReturnValues(name, new object[] { VSConstants.S_OK }); name = string.Format("{0}.{1}", typeof(IVsRunningDocumentTable).FullName, "UnlockDocument"); runningDoc.AddMethodReturnValues(name, new object[] { VSConstants.S_OK }); return(runningDoc); }
private static void GetToolWindowEnumCallBack0(object caller, CallbackArgs arguments) { arguments.ReturnValue = VSConstants.S_OK; // Create the output mock object if (enumWindowsFactory0 == null) { enumWindowsFactory0 = new GenericMockFactory("EnumWindows", new Type[] { typeof(IEnumWindowFrames) }); } BaseMock enumWindows = enumWindowsFactory0.GetInstance(); // Add support for Next string name = string.Format("{0}.{1}", typeof(IEnumWindowFrames).FullName, "Next"); enumWindows.AddMethodCallback(name, new EventHandler <CallbackArgs>(NextCallBack0)); arguments.SetParameter(0, enumWindows); }