Skip to content

Commit

Permalink
Added code for NUnit 3, and split V2 and V3
Browse files Browse the repository at this point in the history
  • Loading branch information
OsirisTerje committed Jul 12, 2015
1 parent bad30a0 commit f8f5ba8
Show file tree
Hide file tree
Showing 14 changed files with 590 additions and 168 deletions.
3 changes: 3 additions & 0 deletions CreateUnitTests.NUnit/CreateUnitTests.NUnit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>..\Osiris.Extended.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand Down Expand Up @@ -57,8 +58,10 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="NUnit2FrameworkProvider.cs" />
<Compile Include="NUnitFrameworkProvider.cs" />
<Compile Include="NUnit2SolutionManager.cs" />
<Compile Include="NUnitSolutionManager.cs" />
<Compile Include="NUnitUnitTestClassManager.cs" />
<Compile Include="NUnitUnitTestProjectManager.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down
37 changes: 37 additions & 0 deletions CreateUnitTests.NUnit/NUnit2FrameworkProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using System.ComponentModel.Composition;
using Microsoft.VisualStudio.TestPlatform.TestGeneration.Data;
using Microsoft.VisualStudio.TestPlatform.TestGeneration.Model;

namespace TestGeneration.Extensions.NUnit
{
/// <summary>
/// The provider for the NUnit 2 unit test framework.
/// </summary>
[Export(typeof(IFrameworkProvider))]
public class NUnit2FrameworkProvider : FrameworkProviderBase
{
/// <summary>
/// Initializes a new instance of the <see cref="NUnit2FrameworkProvider"/> class.
/// </summary>
/// <param name="serviceProvider">The service provider to use to get the interfaces required.</param>
/// <param name="configurationSettings">The configuration settings object to be used to determine how the test method is generated.</param>
/// <param name="naming">The naming object used to decide how projects, classes and methods are named and created.</param>
/// <param name="directory">The directory object to use for directory operations.</param>
[ImportingConstructor]
public NUnit2FrameworkProvider(IServiceProvider serviceProvider, IConfigurationSettings configurationSettings, INaming naming, IDirectory directory)
: base(new NUnit2SolutionManager(serviceProvider, naming, directory), new NUnitUnitTestProjectManager(serviceProvider, naming), new NUnitUnitTestClassManager(configurationSettings, naming))
{
}

/// <summary>
/// Gets the name of the provider.
/// </summary>
public override string Name => "NUnit2";

/// <summary>
/// Gets the name of the assembly.
/// </summary>
public override string AssemblyName => "nunit.framework";
}
}
49 changes: 2 additions & 47 deletions CreateUnitTests.NUnit/NUnit2SolutionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
using Microsoft.VisualStudio.TestPlatform.TestGeneration.Data;
using Microsoft.VisualStudio.TestPlatform.TestGeneration.Logging;
using Microsoft.VisualStudio.TestPlatform.TestGeneration.Model;
using VSLangProj;
using VSLangProj80;

namespace TestGeneration.Extensions.NUnit
Expand Down Expand Up @@ -46,57 +45,13 @@ protected override void OnUnitTestProjectCreated(Project unitTestProject, CodeFu
{
if (unitTestProject == null)
{
throw new ArgumentNullException("unitTestProject");
throw new ArgumentNullException(nameof(unitTestProject));
}

TraceLogger.LogInfo("NUnitSolutionManager.OnUnitTestProjectCreated: Adding reference to NUnit 2 assemblies through nuget.");

base.OnUnitTestProjectCreated(unitTestProject, sourceMethod);
this.EnsureNuGetReference(unitTestProject, "NUnit", "2.6.4");

var vsp = unitTestProject.Object as VSProject2;
if (vsp != null)
{
var reference = vsp.References.Find(GlobalConstants.MSTestAssemblyName);
if (reference != null)
{
TraceLogger.LogInfo("NUnitSolutionManager.OnUnitTestProjectCreated: Removing reference to {0}", reference.Name);
reference.Remove();
}
}
}
}


public class NUnitSolutionManager : SolutionManagerBase
{
/// <summary>
/// Initializes a new instance of the <see cref="NUnitSolutionManager"/> class.
/// </summary>
/// <param name="serviceProvider">The service provider to use to get the interfaces required.</param>
/// <param name="naming">The naming object used to decide how projects, classes and methods are named and created.</param>
/// <param name="directory">The directory object to use for directory operations.</param>
public NUnitSolutionManager(IServiceProvider serviceProvider, INaming naming, IDirectory directory)
: base(serviceProvider, naming, directory)
{
}

/// <summary>
/// Performs any preparatory tasks that have to be done after a new unit test project has been created.
/// </summary>
/// <param name="unitTestProject">The <see cref="Project"/> of the unit test project that has just been created.</param>
/// <param name="sourceMethod">The <see cref="CodeFunction2"/> of the source method that is to be unit tested.</param>
protected override void OnUnitTestProjectCreated(Project unitTestProject, CodeFunction2 sourceMethod)
{
if (unitTestProject == null)
{
throw new ArgumentNullException("unitTestProject");
}

TraceLogger.LogInfo("NUnitSolutionManager.OnUnitTestProjectCreated: Adding reference to NUnit assemblies through nuget.");

base.OnUnitTestProjectCreated(unitTestProject, sourceMethod);
this.EnsureNuGetReference(unitTestProject, "NUnit", "3.0.0-beta-2");
EnsureNuGetReference(unitTestProject, "NUnit", "2.6.4");

var vsp = unitTestProject.Object as VSProject2;
if (vsp != null)
Expand Down
30 changes: 0 additions & 30 deletions CreateUnitTests.NUnit/NUnitFrameworkProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,6 @@

namespace TestGeneration.Extensions.NUnit
{
/// <summary>
/// The provider for the NUnit 2 unit test framework.
/// </summary>
[Export(typeof(IFrameworkProvider))]
public class NUnit2FrameworkProvider : FrameworkProviderBase
{
/// <summary>
/// Initializes a new instance of the <see cref="NUnit2FrameworkProvider"/> class.
/// </summary>
/// <param name="serviceProvider">The service provider to use to get the interfaces required.</param>
/// <param name="configurationSettings">The configuration settings object to be used to determine how the test method is generated.</param>
/// <param name="naming">The naming object used to decide how projects, classes and methods are named and created.</param>
/// <param name="directory">The directory object to use for directory operations.</param>
[ImportingConstructor]
public NUnit2FrameworkProvider(IServiceProvider serviceProvider, IConfigurationSettings configurationSettings, INaming naming, IDirectory directory)
: base(new NUnit2SolutionManager(serviceProvider, naming, directory), new NUnitUnitTestProjectManager(serviceProvider, naming), new NUnitUnitTestClassManager(configurationSettings, naming))
{
}

/// <summary>
/// Gets the name of the provider.
/// </summary>
public override string Name => "NUnit2";

/// <summary>
/// Gets the name of the assembly.
/// </summary>
public override string AssemblyName => "nunit.framework";
}

/// <summary>
/// The provider for the NUnit 2 unit test framework.
/// </summary>
Expand Down
51 changes: 51 additions & 0 deletions CreateUnitTests.NUnit/NUnitSolutionManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System;
using EnvDTE;
using EnvDTE80;
using Microsoft.VisualStudio.TestPlatform.TestGeneration;
using Microsoft.VisualStudio.TestPlatform.TestGeneration.Data;
using Microsoft.VisualStudio.TestPlatform.TestGeneration.Logging;
using Microsoft.VisualStudio.TestPlatform.TestGeneration.Model;
using VSLangProj80;

namespace TestGeneration.Extensions.NUnit
{
public class NUnitSolutionManager : SolutionManagerBase
{
/// <summary>
/// Initializes a new instance of the <see cref="NUnitSolutionManager"/> class.
/// </summary>
/// <param name="serviceProvider">The service provider to use to get the interfaces required.</param>
/// <param name="naming">The naming object used to decide how projects, classes and methods are named and created.</param>
/// <param name="directory">The directory object to use for directory operations.</param>
public NUnitSolutionManager(IServiceProvider serviceProvider, INaming naming, IDirectory directory)
: base(serviceProvider, naming, directory)
{
}

/// <summary>
/// Performs any preparatory tasks that have to be done after a new unit test project has been created.
/// </summary>
/// <param name="unitTestProject">The <see cref="Project"/> of the unit test project that has just been created.</param>
/// <param name="sourceMethod">The <see cref="CodeFunction2"/> of the source method that is to be unit tested.</param>
protected override void OnUnitTestProjectCreated(Project unitTestProject, CodeFunction2 sourceMethod)
{
if (unitTestProject == null)
{
throw new ArgumentNullException(nameof(unitTestProject));
}

TraceLogger.LogInfo("NUnitSolutionManager.OnUnitTestProjectCreated: Adding reference to NUnit assemblies through nuget.");

base.OnUnitTestProjectCreated(unitTestProject, sourceMethod);
this.EnsureNuGetReference(unitTestProject, "NUnit", "3.0.0-beta-2");

var vsp = unitTestProject.Object as VSProject2;
var reference = vsp?.References.Find(GlobalConstants.MSTestAssemblyName);
if (reference != null)
{
TraceLogger.LogInfo("NUnitSolutionManager.OnUnitTestProjectCreated: Removing reference to {0}", reference.Name);
reference.Remove();
}
}
}
}
7 changes: 4 additions & 3 deletions IntelliTest.NUnit/IntelliTest.NUnit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<ProjectGuid>{9B87DC9E-151C-4F94-959F-657BBF72645F}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>NUnit</RootNamespace>
<AssemblyName>NUnit</AssemblyName>
<RootNamespace>TestGeneration.Extensions.IntelliTest.NUnit</RootNamespace>
<AssemblyName>TestGeneration.Extensions.IntelliTest.NUnit</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
Expand All @@ -20,6 +20,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>..\Osiris.Extended.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand Down Expand Up @@ -54,7 +55,7 @@
<ItemGroup>
<Compile Include="NUnitAssertMethodFilter.cs" />
<Compile Include="NUnitTestFramework.cs" />
<Compile Include="NunitTestFrameworkMetadata.cs" />
<Compile Include="NUnitTestFrameworkMetadata.cs" />
<Compile Include="NUnitTestFrameworkPackage.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
Expand Down
11 changes: 6 additions & 5 deletions IntelliTest.NUnit/NUnitAssertMethodFilter.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
namespace Samples.Extensions.NUnit
{
using Microsoft.ExtendedReflection.Asserts;
using Microsoft.ExtendedReflection.Metadata;
using Microsoft.ExtendedReflection.Utilities.Safe.Diagnostics;
using Microsoft.ExtendedReflection.Asserts;
using Microsoft.ExtendedReflection.Metadata;
using Microsoft.ExtendedReflection.Utilities.Safe.Diagnostics;


namespace TestGeneration.Extensions.IntelliTest.NUnit
{
/// <summary>
/// The n unit assert method filer.
/// </summary>
Expand Down
Loading

0 comments on commit f8f5ba8

Please sign in to comment.