This commit is contained in:
vitaliiy@outlook.com 2014-03-12 20:32:09 -07:00
parent 8b61ca41fa
commit 17883e16e1
41 changed files with 3173 additions and 0 deletions

Binary file not shown.

View file

@ -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));
}
}
}

View file

@ -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
}
}

View file

@ -0,0 +1,58 @@
/***************************************************************************
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 Microsoft.VsSDK.UnitTestLibrary;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.VSSDK.Tools.VsIdeTesting;
using VitaliiGanzha.VSPackageInstall;
namespace VSPackageInstall_UnitTests.MyToolWindowTest
{
/// <summary>
///This is a test class for MyToolWindowTest and is intended
///to contain all MyToolWindowTest Unit Tests
///</summary>
[TestClass()]
public class MyToolWindowTest
{
/// <summary>
///MyToolWindow Constructor test
///</summary>
[TestMethod()]
public void MyToolWindowConstructorTest()
{
MyToolWindow target = new MyToolWindow();
Assert.IsNotNull(target, "Failed to create an instance of MyToolWindow");
MethodInfo method = target.GetType().GetMethod("get_Content", BindingFlags.Public | BindingFlags.Instance);
Assert.IsNotNull(method.Invoke(target, null), "MyControl object was not instantiated");
}
/// <summary>
///Verify the Content property is valid.
///</summary>
[TestMethod()]
public void WindowPropertyTest()
{
MyToolWindow target = new MyToolWindow();
Assert.IsNotNull(target.Content, "Content property was null");
}
}
}

View file

@ -0,0 +1,77 @@
/***************************************************************************
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 Microsoft.VsSDK.UnitTestLibrary;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.VSSDK.Tools.VsIdeTesting;
using VitaliiGanzha.VSPackageInstall;
namespace VSPackageInstall_UnitTests.MyToolWindowTest
{
[TestClass()]
public class ShowToolWindowTest
{
[TestMethod()]
public void ValidateToolWindowShown()
{
IVsPackage package = new VSPackageInstallPackage() 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(VSPackageInstallPackage).GetMethod("ShowToolWindow", BindingFlags.NonPublic | BindingFlags.Instance);
object result = method.Invoke(package, new object[] { null, null });
}
[TestMethod()]
[ExpectedException(typeof(InvalidOperationException), "Did not throw expected exception when windowframe object was null")]
public void ShowToolwindowNegativeTest()
{
IVsPackage package = new VSPackageInstallPackage() 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(VSPackageInstallPackage).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;
}
}
}
}

View file

@ -0,0 +1,84 @@
/***************************************************************************
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.MyToolWindowTest
{
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 implement CreateToolWindow
/// </summary>
/// <returns>uishell mock</returns>
internal static BaseMock GetUiShellInstanceCreateToolWin()
{
BaseMock uiShell = GetUiShellInstance();
string name = string.Format("{0}.{1}", typeof(IVsUIShell).FullName, "CreateToolWindow");
uiShell.AddMethodCallback(name, new EventHandler<CallbackArgs>(CreateToolWindowCallBack));
return uiShell;
}
/// <summary>
/// Get an IVsUiShell that implement CreateToolWindow (negative test)
/// </summary>
/// <returns>uishell mock</returns>
internal static BaseMock GetUiShellInstanceCreateToolWinReturnsNull()
{
BaseMock uiShell = GetUiShellInstance();
string name = string.Format("{0}.{1}", typeof(IVsUIShell).FullName, "CreateToolWindow");
uiShell.AddMethodCallback(name, new EventHandler<CallbackArgs>(CreateToolWindowNegativeTestCallBack));
return uiShell;
}
#endregion
#region Callbacks
private static void CreateToolWindowCallBack(object caller, CallbackArgs arguments)
{
arguments.ReturnValue = VSConstants.S_OK;
// Create the output mock object for the frame
IVsWindowFrame frame = WindowFrameMock.GetBaseFrame();
arguments.SetParameter(9, frame);
}
private static void CreateToolWindowNegativeTestCallBack(object caller, CallbackArgs arguments)
{
arguments.ReturnValue = VSConstants.S_OK;
//set the windowframe object to null
arguments.SetParameter(9, null);
}
#endregion
}
}

View file

@ -0,0 +1,39 @@
/***************************************************************************
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.Generic;
using System.Text;
using Microsoft.VsSDK.UnitTestLibrary;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Shell.Interop;
namespace VSPackageInstall_UnitTests.MyToolWindowTest
{
class WindowFrameMock
{
const string propertiesName = "properties";
private static GenericMockFactory frameFactory = null;
/// <summary>
/// Return a IVsWindowFrame without any special implementation
/// </summary>
/// <returns></returns>
internal static IVsWindowFrame GetBaseFrame()
{
if (frameFactory == null)
frameFactory = new GenericMockFactory("WindowFrame", new Type[] { typeof(IVsWindowFrame), typeof(IVsWindowFrame2) });
IVsWindowFrame frame = (IVsWindowFrame)frameFactory.GetInstance();
return frame;
}
}
}

View file

@ -0,0 +1,56 @@
/***************************************************************************
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 Microsoft.VsSDK.UnitTestLibrary;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using VitaliiGanzha.VSPackageInstall;
namespace VSPackageInstall_UnitTests
{
[TestClass()]
public class PackageTest
{
[TestMethod()]
public void CreateInstance()
{
VSPackageInstallPackage package = new VSPackageInstallPackage();
}
[TestMethod()]
public void IsIVsPackage()
{
VSPackageInstallPackage package = new VSPackageInstallPackage();
Assert.IsNotNull(package as IVsPackage, "The object does not implement IVsPackage");
}
[TestMethod()]
public void SetSite()
{
// 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");
// Unsite the package
Assert.AreEqual(0, package.SetSite(null), "SetSite(null) did not return S_OK");
}
}
}

View file

@ -0,0 +1,84 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="12.0">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{E620FC0C-6208-4216-9899-47DF43578E4C}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>VSPackageInstall_UnitTests</RootNamespace>
<AssemblyName>VSPackageInstall_UnitTests</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath Condition="'$(OutputPath)'==''">bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath Condition="'$(OutputPath)'==''">bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>Key.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.OLE.Interop" />
<Reference Include="Microsoft.VisualStudio.Shell.Interop" />
<Reference Include="Microsoft.VisualStudio.Shell.Interop.8.0" />
<Reference Include="Microsoft.VisualStudio.Shell.Interop.9.0" />
<Reference Include="Microsoft.VisualStudio.Shell.Interop.10.0" />
<Reference Include="Microsoft.VisualStudio.Shell.Interop.11.0">
<EmbedInteropTypes>true</EmbedInteropTypes>
</Reference>
<Reference Include="Microsoft.VisualStudio.Shell.12.0" />
<Reference Include="Microsoft.VisualStudio.Shell.Immutable.10.0" />
<Reference Include="Microsoft.VisualStudio.Shell.Immutable.11.0" />
<!---->
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework" />
<Reference Include="Microsoft.VSSDK.UnitTestLibrary" />
<Reference Include="Microsoft.VSSDK.TestHostFramework" />
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Design" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="PackageTest.cs" />
<!---->
<Compile Include="MenuItemTests\MenuItemCallback.cs" />
<Compile Include="MenuItemTests\UIShellServiceMock.cs" />
<!---->
<!---->
<Compile Include="MyToolWindowTest\MyToolWindow.cs" />
<Compile Include="MyToolWindowTest\ShowToolWindow.cs" />
<Compile Include="MyToolWindowTest\WindowFrameMock.cs" />
<Compile Include="MyToolWindowTest\UIShellServiceMock.cs" />
<!---->
<!---->
</ItemGroup>
<ItemGroup>
<None Include="Key.snk" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\VSPackageInstall.csproj">
<Project>{20191D13-7CC1-4F9B-9CB8-42F22ACE4CA6}</Project>
<Name>VSPackageInstall</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>