public void ShowToolwindowNegativeTest() { IVsPackage package = new SynopsisVSPkgPackage() as IVsPackage; // Create a basic service provider OleServiceProvider serviceProvider = OleServiceProvider.CreateOleServiceProviderWithBasicServices(); //Add uishell service that knows how to create a toolwindow BaseMock uiShellService = UIShellServiceMock.GetUiShellInstanceCreateToolWinReturnsNull(); serviceProvider.AddService(typeof(SVsUIShell), uiShellService, false); // Site the package Assert.AreEqual(0, package.SetSite(serviceProvider), "SetSite did not return S_OK"); MethodInfo method = typeof(SynopsisVSPkgPackage).GetMethod("ShowToolWindow", BindingFlags.NonPublic | BindingFlags.Instance); //Invoke thows TargetInvocationException, but we want it's inner Exception thrown by ShowToolWindow, InvalidOperationException. try { object result = method.Invoke(package, new object[] { null, null }); } catch (Exception e) { throw e.InnerException; } }
public override void OnToolWindowCreated() { if(_package == null) { _package = base.Package as SynopsisVSPkgPackage; } var WindowEvents = _package.IDE.Events.get_WindowEvents(null); WindowEvents.WindowActivated += WindowEvents_WindowActivated; base.OnToolWindowCreated(); _package = base.Package as SynopsisVSPkgPackage; _contentControl.FileText = GetTextForActiveDocument(_package); }
public void SetSite() { // Create the package IVsPackage package = new SynopsisVSPkgPackage() as IVsPackage; Assert.IsNotNull(package, "The object does not implement IVsPackage"); // Create a basic service provider OleServiceProvider serviceProvider = OleServiceProvider.CreateOleServiceProviderWithBasicServices(); // Site the package Assert.AreEqual(0, package.SetSite(serviceProvider), "SetSite did not return S_OK"); // Unsite the package Assert.AreEqual(0, package.SetSite(null), "SetSite(null) did not return S_OK"); }
private string GetTextForActiveDocument(SynopsisVSPkgPackage package) { var document = _package.IDE.ActiveDocument; if (document != null) { var textDocument = (TextDocument)document.Object("TextDocument"); var fullText = textDocument.StartPoint.CreateEditPoint().GetText(textDocument.EndPoint); return fullText; } else { return String.Empty; } }
public void ValidateToolWindowShown() { IVsPackage package = new SynopsisVSPkgPackage() as IVsPackage; // Create a basic service provider OleServiceProvider serviceProvider = OleServiceProvider.CreateOleServiceProviderWithBasicServices(); //Add uishell service that knows how to create a toolwindow BaseMock uiShellService = UIShellServiceMock.GetUiShellInstanceCreateToolWin(); serviceProvider.AddService(typeof(SVsUIShell), uiShellService, false); // Site the package Assert.AreEqual(0, package.SetSite(serviceProvider), "SetSite did not return S_OK"); MethodInfo method = typeof(SynopsisVSPkgPackage).GetMethod("ShowToolWindow", BindingFlags.NonPublic | BindingFlags.Instance); object result = method.Invoke(package, new object[] { null, null }); }
public void InitializeMenuCommand() { // Create the package IVsPackage package = new SynopsisVSPkgPackage() as IVsPackage; Assert.IsNotNull(package, "The object does not implement IVsPackage"); // Create a basic service provider OleServiceProvider serviceProvider = OleServiceProvider.CreateOleServiceProviderWithBasicServices(); // Site the package Assert.AreEqual(0, package.SetSite(serviceProvider), "SetSite did not return S_OK"); //Verify that the menu command can be found CommandID menuCommandID = new CommandID(Synopsis.SynopsisVSPkg.GuidList.guidSynopsisVSPkgCmdSet, (int)Synopsis.SynopsisVSPkg.PkgCmdIDList.cmdidViewSynopsis); System.Reflection.MethodInfo info = typeof(Package).GetMethod("GetService", BindingFlags.Instance | BindingFlags.NonPublic); Assert.IsNotNull(info); OleMenuCommandService mcs = info.Invoke(package, new object[] { (typeof(IMenuCommandService)) }) as OleMenuCommandService; Assert.IsNotNull(mcs.FindCommand(menuCommandID)); }
/// <summary> /// Standard constructor for the tool window. /// </summary> public MemberByAccessModifierViewWindow() : base(null) { // Set the window title reading it from the resources. this.Caption = Resources.ToolWindowTitle; // Set the image that will appear on the tab of the window frame // when docked with an other window // The resource ID correspond to the one defined in the resx file // while the Index is the offset in the bitmap strip. Each image in // the strip being 16x16. this.BitmapResourceID = 301; this.BitmapIndex = 1; // This is the user control hosted by the tool window; Note that, even if this class implements IDisposable, // we are not calling Dispose on this object. This is because ToolWindowPane calls Dispose on // the object returned by the Content property. _package = base.Package as SynopsisVSPkgPackage; _contentControl = new MemberByAccessModifierView(); base.Content = _contentControl; }
public void MenuItemCallback() { // Create the package IVsPackage package = new SynopsisVSPkgPackage() as IVsPackage; Assert.IsNotNull(package, "The object does not implement IVsPackage"); // Create a basic service provider OleServiceProvider serviceProvider = OleServiceProvider.CreateOleServiceProviderWithBasicServices(); // Create a UIShell service mock and proffer the service so that it can called from the MenuItemCallback method BaseMock uishellMock = UIShellServiceMock.GetUiShellInstance(); serviceProvider.AddService(typeof(SVsUIShell), uishellMock, true); // Site the package Assert.AreEqual(0, package.SetSite(serviceProvider), "SetSite did not return S_OK"); //Invoke private method on package class and observe that the method does not throw System.Reflection.MethodInfo info = package.GetType().GetMethod("MenuItemCallback", BindingFlags.Instance | BindingFlags.NonPublic); Assert.IsNotNull(info, "Failed to get the private method MenuItemCallback throug refplection"); info.Invoke(package, new object[] { null, null }); //Clean up services serviceProvider.RemoveService(typeof(SVsUIShell)); }
public void IsIVsPackage() { SynopsisVSPkgPackage package = new SynopsisVSPkgPackage(); Assert.IsNotNull(package as IVsPackage, "The object does not implement IVsPackage"); }
public void CreateInstance() { SynopsisVSPkgPackage package = new SynopsisVSPkgPackage(); }
private void WindowEvents_WindowActivated(EnvDTE.Window GotFocus, EnvDTE.Window LostFocus) { _package = base.Package as SynopsisVSPkgPackage; _contentControl.FileText = GetTextForActiveDocument(_package); }