public void CreateEditorInstance()
        {
            VSThrowawayPackagePackage package = new VSThrowawayPackagePackage();

            //Create the editor factory
            EditorFactory editorFactory = new EditorFactory(package);

            // Create a basic service provider
            OleServiceProvider serviceProvider = OleServiceProvider.CreateOleServiceProviderWithBasicServices();

            serviceProvider.AddService(typeof(SLocalRegistry), (ILocalRegistry)LocalRegistryServiceMock.GetILocalRegistryInstance(), true);

            // Site the editor factory
            Assert.AreEqual(0, editorFactory.SetSite(serviceProvider), "SetSite did not return S_OK");

            IntPtr ppunkDocView;
            IntPtr ppunkDocData;
            string pbstrEditorCaption = String.Empty;
            Guid   pguidCmdUI         = Guid.Empty;
            int    pgrfCDW            = 0;

            Assert.AreEqual(VSConstants.S_OK, editorFactory.CreateEditorInstance(VSConstants.CEF_OPENFILE,
                                                                                 null, null, null, 0, IntPtr.Zero, out ppunkDocView, out ppunkDocData, out pbstrEditorCaption,
                                                                                 out pguidCmdUI, out pgrfCDW));
        }
        public void IsIVsEditorFactory()
        {
            VSThrowawayPackagePackage package       = new VSThrowawayPackagePackage();
            EditorFactory             editorFactory = new EditorFactory(package);

            Assert.IsNotNull(editorFactory as IVsEditorFactory, "The object does not implement IVsEditorFactory");
        }
Esempio n. 3
0
        public void MenuItemCallback()
        {
            // Create the package
            IVsPackage package = new VSThrowawayPackagePackage() 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);

            // Add site support to register editor factory
            BaseMock registerEditor = VSThrowawayPackage_UnitTests.EditorTests.RegisterEditorsServiceMock.GetRegisterEditorsInstance();

            serviceProvider.AddService(typeof(SVsRegisterEditors), registerEditor, false);

            // 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));
        }
Esempio n. 4
0
        public void InitializeMenuCommand()
        {
            // Create the package
            IVsPackage package = new VSThrowawayPackagePackage() as IVsPackage;

            Assert.IsNotNull(package, "The object does not implement IVsPackage");

            // Create a basic service provider
            OleServiceProvider serviceProvider = OleServiceProvider.CreateOleServiceProviderWithBasicServices();

            // Add site support to register editor factory
            BaseMock registerEditor = VSThrowawayPackage_UnitTests.EditorTests.RegisterEditorsServiceMock.GetRegisterEditorsInstance();

            serviceProvider.AddService(typeof(SVsRegisterEditors), registerEditor, false);

            // 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(VSJamSession.VSThrowawayPackage.GuidList.guidVSThrowawayPackageCmdSet, (int)VSJamSession.VSThrowawayPackage.PkgCmdIDList.startJamSession);

            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));
        }
Esempio n. 5
0
        public void ShowToolwindowNegativeTest()
        {
            IVsPackage package = new VSThrowawayPackagePackage() 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);

            // Add site support to register editor factory
            BaseMock registerEditor = VSThrowawayPackage_UnitTests.EditorTests.RegisterEditorsServiceMock.GetRegisterEditorsInstance();

            serviceProvider.AddService(typeof(SVsRegisterEditors), registerEditor, false);

            // Site the package
            Assert.AreEqual(0, package.SetSite(serviceProvider), "SetSite did not return S_OK");

            MethodInfo method = typeof(VSThrowawayPackagePackage).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 CreateInstance()
        {
            VSThrowawayPackagePackage package = new VSThrowawayPackagePackage();

            EditorFactory editorFactory = new EditorFactory(package);

            Assert.IsNotNull(editorFactory, "Failed to initialize new instance of EditorFactory.");
        }
        public void CloseTest()
        {
            VSThrowawayPackagePackage package = new VSThrowawayPackagePackage();

            EditorFactory editorFactory = new EditorFactory(package);

            Assert.AreEqual(VSConstants.S_OK, editorFactory.Close(), "Close did no return S_OK");
        }
        public void DisposeTest()
        {
            VSThrowawayPackagePackage package = new VSThrowawayPackagePackage();

            EditorFactory editorFactory = new EditorFactory(package);

            editorFactory.Dispose();
        }
        public void IsIDisposableTest()
        {
            VSThrowawayPackagePackage package = new VSThrowawayPackagePackage();

            using (EditorFactory editorFactory = new EditorFactory(package))
            {
                Assert.IsNotNull(editorFactory as IDisposable, "The object does not implement IDisposable interface");
            }
        }
Esempio n. 10
0
        public void SetSite()
        {
            VSThrowawayPackagePackage package = new VSThrowawayPackagePackage();

            //Create the editor factory
            EditorFactory editorFactory = new EditorFactory(package);

            // Create a basic service provider
            OleServiceProvider serviceProvider = OleServiceProvider.CreateOleServiceProviderWithBasicServices();

            // Site the editor factory
            Assert.AreEqual(0, editorFactory.SetSite(serviceProvider), "SetSite did not return S_OK");
        }
Esempio n. 11
0
        public void DisposeDisposableMembersTest()
        {
            VSThrowawayPackagePackage package = new VSThrowawayPackagePackage();

            EditorFactory      editorFactory   = new EditorFactory(package);
            OleServiceProvider serviceProvider = OleServiceProvider.CreateOleServiceProviderWithBasicServices();

            editorFactory.SetSite(serviceProvider);
            object service = editorFactory.GetService(typeof(IProfferService));

            Assert.IsNotNull(service);
            editorFactory.Dispose(); //service provider contains no services after this call
            service = editorFactory.GetService(typeof(IProfferService));
            Assert.IsNull(service, "serviceprovider has not beed disposed as expected");
        }
Esempio n. 12
0
        public void CheckLogicalView()
        {
            VSThrowawayPackagePackage package = new VSThrowawayPackagePackage();

            //Create the editor factory
            EditorFactory editorFactory = new EditorFactory(package);

            // Create a basic service provider
            OleServiceProvider serviceProvider = OleServiceProvider.CreateOleServiceProviderWithBasicServices();

            serviceProvider.AddService(typeof(SLocalRegistry), (ILocalRegistry)LocalRegistryServiceMock.GetILocalRegistryInstance(), true);

            // Site the editor factory
            Assert.AreEqual(0, editorFactory.SetSite(serviceProvider), "SetSite did not return S_OK");

            IntPtr ppunkDocView;
            IntPtr ppunkDocData;
            string pbstrEditorCaption = String.Empty;
            Guid   pguidCmdUI         = Guid.Empty;
            int    pgrfCDW            = 0;

            Assert.AreEqual(VSConstants.S_OK, editorFactory.CreateEditorInstance(VSConstants.CEF_OPENFILE,
                                                                                 null, null, null, 0, IntPtr.Zero, out ppunkDocView, out ppunkDocData, out pbstrEditorCaption,
                                                                                 out pguidCmdUI, out pgrfCDW)); //check for successfull creation of editor instance

            string bstrPhysicalView   = string.Empty;
            Guid   refGuidLogicalView = VSConstants.LOGVIEWID_Debugging;

            Assert.AreEqual(VSConstants.E_NOTIMPL, editorFactory.MapLogicalView(ref refGuidLogicalView, out bstrPhysicalView));

            refGuidLogicalView = VSConstants.LOGVIEWID_Code;
            Assert.AreEqual(VSConstants.E_NOTIMPL, editorFactory.MapLogicalView(ref refGuidLogicalView, out bstrPhysicalView));

            refGuidLogicalView = VSConstants.LOGVIEWID_TextView;
            Assert.AreEqual(VSConstants.S_OK, editorFactory.MapLogicalView(ref refGuidLogicalView, out bstrPhysicalView));

            refGuidLogicalView = VSConstants.LOGVIEWID_UserChooseView;
            Assert.AreEqual(VSConstants.E_NOTIMPL, editorFactory.MapLogicalView(ref refGuidLogicalView, out bstrPhysicalView));

            refGuidLogicalView = VSConstants.LOGVIEWID_Primary;
            Assert.AreEqual(VSConstants.S_OK, editorFactory.MapLogicalView(ref refGuidLogicalView, out bstrPhysicalView));
        }
Esempio n. 13
0
        public void SetSite()
        {
            // Create the package
            IVsPackage package = new VSThrowawayPackagePackage() as IVsPackage;

            Assert.IsNotNull(package, "The object does not implement IVsPackage");

            // Create a basic service provider
            OleServiceProvider serviceProvider = OleServiceProvider.CreateOleServiceProviderWithBasicServices();

            // Add site support to register editor factory
            BaseMock registerEditor = VSThrowawayPackage_UnitTests.EditorTests.RegisterEditorsServiceMock.GetRegisterEditorsInstance();

            serviceProvider.AddService(typeof(SVsRegisterEditors), registerEditor, false);

            // 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");
        }
Esempio n. 14
0
        public void ValidateToolWindowShown()
        {
            IVsPackage package = new VSThrowawayPackagePackage() 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);

            // Add site support to register editor factory
            BaseMock registerEditor = VSThrowawayPackage_UnitTests.EditorTests.RegisterEditorsServiceMock.GetRegisterEditorsInstance();

            serviceProvider.AddService(typeof(SVsRegisterEditors), registerEditor, false);

            // Site the package
            Assert.AreEqual(0, package.SetSite(serviceProvider), "SetSite did not return S_OK");

            MethodInfo method = typeof(VSThrowawayPackagePackage).GetMethod("ShowToolWindow", BindingFlags.NonPublic | BindingFlags.Instance);

            object result = method.Invoke(package, new object[] { null, null });
        }
Esempio n. 15
0
        public void IsIVsPackage()
        {
            VSThrowawayPackagePackage package = new VSThrowawayPackagePackage();

            Assert.IsNotNull(package as IVsPackage, "The object does not implement IVsPackage");
        }
Esempio n. 16
0
 public void CreateInstance()
 {
     VSThrowawayPackagePackage package = new VSThrowawayPackagePackage();
 }