Commit
This commit is contained in:
		
							parent
							
								
									8b61ca41fa
								
							
						
					
					
						commit
						17883e16e1
					
				
					 41 changed files with 3173 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -0,0 +1,80 @@
 | 
			
		|||
/***************************************************************************
 | 
			
		||||
 | 
			
		||||
Copyright (c) Microsoft Corporation. All rights reserved.
 | 
			
		||||
This code is licensed under the Visual Studio SDK license terms.
 | 
			
		||||
THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
 | 
			
		||||
ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
 | 
			
		||||
IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
 | 
			
		||||
PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
 | 
			
		||||
 | 
			
		||||
***************************************************************************/
 | 
			
		||||
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using System.Reflection;
 | 
			
		||||
using System.ComponentModel.Design;
 | 
			
		||||
using Microsoft.VsSDK.UnitTestLibrary;
 | 
			
		||||
using Microsoft.VisualStudio.Shell.Interop;
 | 
			
		||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
 | 
			
		||||
using Microsoft.VisualStudio.Shell;
 | 
			
		||||
using VitaliiGanzha.VSPackageInstall;
 | 
			
		||||
 | 
			
		||||
namespace VSPackageInstall_UnitTests.MenuItemTests
 | 
			
		||||
{
 | 
			
		||||
    [TestClass()]
 | 
			
		||||
    public class MenuItemTest
 | 
			
		||||
    {
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Verify that a new menu command object gets added to the OleMenuCommandService. 
 | 
			
		||||
        /// This action takes place In the Initialize method of the Package object
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        [TestMethod]
 | 
			
		||||
        public void InitializeMenuCommand()
 | 
			
		||||
        {
 | 
			
		||||
            // Create the package
 | 
			
		||||
            IVsPackage package = new VSPackageInstallPackage() 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(VitaliiGanzha.VSPackageInstall.GuidList.guidVSPackageInstallCmdSet, (int)VitaliiGanzha.VSPackageInstall.PkgCmdIDList.cmdidVsDing);
 | 
			
		||||
            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));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [TestMethod]
 | 
			
		||||
        public void MenuItemCallback()
 | 
			
		||||
        {
 | 
			
		||||
            // Create the package
 | 
			
		||||
            IVsPackage package = new VSPackageInstallPackage() 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));
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,76 @@
 | 
			
		|||
/***************************************************************************
 | 
			
		||||
 | 
			
		||||
Copyright (c) Microsoft Corporation. All rights reserved.
 | 
			
		||||
This code is licensed under the Visual Studio SDK license terms.
 | 
			
		||||
THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
 | 
			
		||||
ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
 | 
			
		||||
IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
 | 
			
		||||
PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
 | 
			
		||||
 | 
			
		||||
***************************************************************************/
 | 
			
		||||
 | 
			
		||||
using System;
 | 
			
		||||
using Microsoft.VisualStudio;
 | 
			
		||||
using Microsoft.VisualStudio.Shell.Interop;
 | 
			
		||||
using Microsoft.VsSDK.UnitTestLibrary;
 | 
			
		||||
 | 
			
		||||
namespace VSPackageInstall_UnitTests
 | 
			
		||||
{
 | 
			
		||||
    static class UIShellServiceMock
 | 
			
		||||
    {
 | 
			
		||||
        private static GenericMockFactory uiShellFactory;
 | 
			
		||||
 | 
			
		||||
        #region UiShell Getters
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Returns an IVsUiShell that does not implement any methods
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <returns></returns>
 | 
			
		||||
        internal static BaseMock GetUiShellInstance()
 | 
			
		||||
        {
 | 
			
		||||
            if (uiShellFactory == null)
 | 
			
		||||
            {
 | 
			
		||||
                uiShellFactory = new GenericMockFactory("UiShell", new Type[] { typeof(IVsUIShell), typeof(IVsUIShellOpenDocument) });
 | 
			
		||||
            }
 | 
			
		||||
            BaseMock uiShell = uiShellFactory.GetInstance();
 | 
			
		||||
            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;
 | 
			
		||||
        }
 | 
			
		||||
        #endregion
 | 
			
		||||
 | 
			
		||||
        #region Callbacks
 | 
			
		||||
        private static void SetWaitCursorCallBack(object caller, CallbackArgs arguments)
 | 
			
		||||
        {
 | 
			
		||||
            arguments.ReturnValue = VSConstants.S_OK;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private static void SaveDocDataToFileCallBack(object caller, CallbackArgs arguments)
 | 
			
		||||
        {
 | 
			
		||||
            arguments.ReturnValue = VSConstants.S_OK;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private static void ShowMessageBoxCallBack(object caller, CallbackArgs arguments)
 | 
			
		||||
        {
 | 
			
		||||
            arguments.ReturnValue = VSConstants.S_OK;
 | 
			
		||||
            arguments.SetParameter(10, (int)System.Windows.Forms.DialogResult.Yes);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        #endregion
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue