Пример #1
0
        public void TestOutputNoPane() {
            // Create an instance of the package and initialize it so that the GetService
            // will succeed, but the GetPane will fail.

            // As first create a service provider.
            using(OleServiceProvider serviceProvider = OleServiceProvider.CreateOleServiceProviderWithBasicServices()) {
                // Now create the mock object for the output window.
                if(null == mockOutputWindowFactory) {
                    mockOutputWindowFactory = new GenericMockFactory("MockOutputWindow", new Type[] { typeof(IVsOutputWindow) });
                }
                BaseMock mockBase = mockOutputWindowFactory.GetInstance() as BaseMock;
                mockBase.AddMethodReturnValues(string.Format("{0}.{1}", typeof(IVsOutputWindow).FullName, "GetPane"),
                                               new object[] { -1, Guid.Empty, null });
                // Add the output window to the services provided by the service provider.
                serviceProvider.AddService(typeof(SVsOutputWindow), mockBase, false);

                // Create an instance of the package and initialize it calling SetSite.
                SrcMLServicePackage package = new SrcMLServicePackage();
                int result = ((IVsPackage)package).SetSite(serviceProvider);
                Assert.IsTrue(Microsoft.VisualStudio.ErrorHandler.Succeeded(result), "SetSite failed.");

                // Now we can create an instance of the service
                SetUpSrcMLServiceExtensionDirectory();
                SrcMLGlobalService service = new SrcMLGlobalService(package, extensionDirectory);
                
                service.GlobalServiceFunction();
                                
                ((IVsPackage)package).SetSite(null);
                ((IVsPackage)package).Close();
            }
        }
 public void SetSiteSimple() {
     SrcMLServicePackage packageObject = new SrcMLServicePackage();
     IVsPackage package = (IVsPackage)packageObject;
     using(OleServiceProvider provider = OleServiceProvider.CreateOleServiceProviderWithBasicServices()) {
         int result = package.SetSite(provider);
         Assert.IsTrue(Microsoft.VisualStudio.ErrorHandler.Succeeded(result), "SetSite failed.");
     }
     package.SetSite(null);
     package.Close();
 }
 public void SetSite() {
     // Create the package
     IVsPackage package = new SrcMLServicePackage() 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 GetLocalServiceSimple() {
     SrcMLServicePackage packageObject = new SrcMLServicePackage();
     IVsPackage package = (IVsPackage)packageObject;
     using(OleServiceProvider provider = OleServiceProvider.CreateOleServiceProviderWithBasicServices()) {
         int result = package.SetSite(provider);
         Assert.IsTrue(Microsoft.VisualStudio.ErrorHandler.Succeeded(result), "SetSite failed.");
         IServiceProvider serviceProvider = package as IServiceProvider;
         object o = serviceProvider.GetService(typeof(SSrcMLLocalService));
         Assert.IsNotNull(o, "GetService returned null for the local service.");
         ISrcMLLocalService service = o as ISrcMLLocalService;
         Assert.IsNotNull(service, "The service SMyLocalService does not implements IMyLocalService.");
         service.LocalServiceFunction();
     }
     package.SetSite(null);
     package.Close();
 }
        public static void ClassInitialize(TestContext testContext) {
            // Create SrcMLServicePackage
            SrcMLServicePackage packageObject = new SrcMLServicePackage();
            package = (IVsPackage)packageObject;
            Assert.IsNotNull(package, "Get a null SrcMLServicePackage instance.");
            IServiceProvider serviceProvider = package as IServiceProvider;
            // Get SrcML Service
            object o = serviceProvider.GetService(typeof(SSrcMLGlobalService));
            Assert.IsNotNull(o, "GetService returned null for the global service.");
            srcMLService = o as ISrcMLGlobalService;
            Assert.IsNotNull(srcMLService, "The service SSrcMLGlobalService does not implements ISrcMLGlobalService.");

            // Register SrcML Service events
            srcMLService.SourceFileChanged += SourceFileChanged;
            srcMLService.IsReadyChanged += IsReadyChanged;
            srcMLService.MonitoringStopped += MonitoringStopped;
        }
Пример #6
0
        public void InitializeMenuCommand() {
            // Create the package
            IVsPackage package = new SrcMLServicePackage() 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(GuidList.guidSrcMLServiceCmdSet, (int)PkgCmdIDList.SrcML);
            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));
        }
Пример #7
0
        public void MenuItemCallback() {
            // Create the package
            IVsPackage package = new SrcMLServicePackage() 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() {
     SrcMLServicePackage package = new SrcMLServicePackage();
     Assert.IsNotNull(package as IVsPackage, "The object does not implement IVsPackage");
 }
 // TODO: remove?
 public void CreateInstance() {
     SrcMLServicePackage package = new SrcMLServicePackage();
 }
Пример #10
0
        public void TestOutput() {
            callbackExecuted = false;
            // As first create a service provider.
            using(OleServiceProvider serviceProvider = OleServiceProvider.CreateOleServiceProviderWithBasicServices()) {
                // Create a mock object for the output window pane.
                GenericMockFactory mockWindowPaneFactory = new GenericMockFactory("MockOutputWindowPane", new Type[] { typeof(IVsOutputWindowPane) });
                BaseMock mockWindowPane = mockWindowPaneFactory.GetInstance();
                mockWindowPane.AddMethodCallback(string.Format("{0}.{1}", typeof(IVsOutputWindowPane).FullName, "OutputString"),
                                                 new EventHandler<CallbackArgs>(OutputWindowPaneCallback));

                // Now create the mock object for the output window.
                if(null == mockOutputWindowFactory) {
                    mockOutputWindowFactory = new GenericMockFactory("MockOutputWindow1", new Type[] { typeof(IVsOutputWindow) });
                }
                BaseMock mockOutputWindow = mockOutputWindowFactory.GetInstance();
                mockOutputWindow.AddMethodReturnValues(
                        string.Format("{0}.{1}", typeof(IVsOutputWindow).FullName, "GetPane"),
                        new object[] { 0, Guid.Empty, (IVsOutputWindowPane)mockWindowPane });

                // Add the output window to the services provided by the service provider.
                serviceProvider.AddService(typeof(SVsOutputWindow), mockOutputWindow, false);

                // Create an instance of the package and initialize it calling SetSite.
                SrcMLServicePackage package = new SrcMLServicePackage();
                int result = ((IVsPackage)package).SetSite(serviceProvider);
                Assert.IsTrue(Microsoft.VisualStudio.ErrorHandler.Succeeded(result), "SetSite failed.");

                // Now we can create an instance of the service
                SrcMLGlobalService service = new SrcMLGlobalService(package, extensionDirectory);

                service.GlobalServiceFunction();
                
                Assert.IsTrue(callbackExecuted, "OutputText not called.");
                ((IVsPackage)package).SetSite(null);
                ((IVsPackage)package).Close();
            }
        }