public void ShowToolwindowNegativeTest() { IVsPackage package = new TestifyPackage() 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(TestifyPackage).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 void MenuItemCallback() { // Create the package IVsPackage package = new TestifyPackage() 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 SetSite() { // Create the package IVsPackage package = new TestifyPackage() 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"); }
public void ValidateToolWindowShown() { IVsPackage package = new TestifyPackage() 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(TestifyPackage).GetMethod("ShowToolWindow", BindingFlags.NonPublic | BindingFlags.Instance); object result = method.Invoke(package, new object[] { null, null }); }
public void InitializeMenuCommand() { // Create the package IVsPackage package = new TestifyPackage() 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(Leem.Testify.GuidList.guidTestifyCmdSet, (int)Leem.Testify.PkgCmdIDList.cmdidSolutionTests); 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)); }
public void IsIVsPackage() { TestifyPackage package = new TestifyPackage(); Assert.IsNotNull(package as IVsPackage, "The object does not implement IVsPackage"); }
public void CreateInstance() { TestifyPackage package = new TestifyPackage(); }
void ItemDoubleClicked(object sender, RoutedEventArgs e) { _queries = TestifyQueries.Instance; string filePath = string.Empty; int line = 0; int column = 0; string type = ((HeaderedItemsControl)(e.Source)).Header.ToString(); string name = string.Empty; EnvDTE.Window openDocumentWindow; var clickedMethodName = string.Empty; var dte = TestifyPackage.GetGlobalService(typeof(DTE)) as DTE2; //IList<CodeElement> classes; //IList<CodeElement> methods; if (dte.ActiveDocument != null) { //CodeModelService.GetCodeBlocks(dte.ActiveDocument.ProjectItem.FileCodeModel, out classes, out methods); if (type == "Leem.Testify.SummaryView.ViewModel.MethodViewModel") { clickedMethodName = ((MethodViewModel)(((System.Windows.Controls.HeaderedItemsControl)(e.Source)).Header)).FullName; // var method = _queries.GetMethod(clickedMethodName); filePath = ((MethodViewModel)(((System.Windows.Controls.HeaderedItemsControl)(e.Source)).Header)).FileName; line = ((MethodViewModel)(((System.Windows.Controls.HeaderedItemsControl)(e.Source)).Header)).Line; column = ((MethodViewModel)(((System.Windows.Controls.HeaderedItemsControl)(e.Source)).Header)).Column; } } if (!string.IsNullOrEmpty(filePath) && filePath != string.Empty && !dte.ItemOperations.IsFileOpen(filePath)) { openDocumentWindow = dte.ItemOperations.OpenFile(filePath); if (openDocumentWindow != null) { openDocumentWindow.Activate(); } else { for (var i = 1; i == dte.Documents.Count; i++) { if (dte.Documents.Item(i).Name == name) { openDocumentWindow = dte.Documents.Item(i).ProjectItem.Document.ActiveWindow; } } } } else { for (var i = 1; i <= dte.Windows.Count; i++) { var window = dte.Windows.Item(i); if (window.Document != null && window.Document.FullName.Equals(filePath, StringComparison.OrdinalIgnoreCase)) { openDocumentWindow = window; openDocumentWindow.Activate(); var selection = window.Document.DTE.ActiveDocument.Selection as TextSelection; selection.StartOfDocument(); selection.MoveToLineAndOffset(line, column, true); selection.SelectLine(); continue; } } } }