Commit
This commit is contained in:
parent
8b61ca41fa
commit
17883e16e1
41 changed files with 3173 additions and 0 deletions
|
@ -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");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue