Skip to content

Commit

Permalink
Added code for NUnit 3
Browse files Browse the repository at this point in the history
  • Loading branch information
OsirisTerje committed Jul 11, 2015
1 parent a4a95a0 commit bad30a0
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 12 deletions.
2 changes: 1 addition & 1 deletion CreateUnitTests.NUnit/CreateUnitTests.NUnit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="NUnitFrameworkProvider.cs" />
<Compile Include="NUnitSolutionManager.cs" />
<Compile Include="NUnit2SolutionManager.cs" />
<Compile Include="NUnitUnitTestClassManager.cs" />
<Compile Include="NUnitUnitTestProjectManager.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,50 @@ namespace TestGeneration.Extensions.NUnit
/// <summary>
/// A solution manager for NUnit unit tests.
/// </summary>
public class NUnit2SolutionManager : 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 NUnit2SolutionManager(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 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>
Expand Down Expand Up @@ -52,12 +96,12 @@ protected override void OnUnitTestProjectCreated(Project unitTestProject, CodeFu
TraceLogger.LogInfo("NUnitSolutionManager.OnUnitTestProjectCreated: Adding reference to NUnit assemblies through nuget.");

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

VSProject2 vsp = unitTestProject.Object as VSProject2;
var vsp = unitTestProject.Object as VSProject2;
if (vsp != null)
{
Reference reference = vsp.References.Find(GlobalConstants.MSTestAssemblyName);
var reference = vsp.References.Find(GlobalConstants.MSTestAssemblyName);
if (reference != null)
{
TraceLogger.LogInfo("NUnitSolutionManager.OnUnitTestProjectCreated: Removing reference to {0}", reference.Name);
Expand Down
34 changes: 32 additions & 2 deletions CreateUnitTests.NUnit/NUnitFrameworkProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,43 @@
namespace TestGeneration.Extensions.NUnit
{
/// <summary>
/// The provider for the NUnit unit test framework.
/// 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>
[Export(typeof(IFrameworkProvider))]
public class NUnitFrameworkProvider : FrameworkProviderBase
{
/// <summary>
/// Initializes a new instance of the <see cref="NUnitFrameworkProvider"/> class.
/// 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>
Expand Down
9 changes: 3 additions & 6 deletions IntelliTest.NUnit/NUnitTestFramework.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public NUnitTestFramework(IPexComponent host)
/// identify of the test framework
/// </summary>
/// <value></value>
public override string Name => "NUnit";
public override string Name => "NUnit2";

/// <summary>
/// Gets the assembly name of the framework main's assembly. This name is used
Expand All @@ -68,7 +68,7 @@ public override ICountable<ShortReferenceAssemblyName> References
{
get
{
return Indexable.One(new ShortReferenceAssemblyName(ShortAssemblyName.FromName("Nunit"), "2.6.4", AssemblyReferenceType.NugetReference));
return Indexable.One(new ShortReferenceAssemblyName(ShortAssemblyName.FromName("NUnit"), "2.6.4", AssemblyReferenceType.NugetReference));
}
}

Expand Down Expand Up @@ -208,10 +208,7 @@ public override bool TryGetAssemblySetupTeardownMethods(
/// <value>
/// <c>true</c> if [fixture set up tear down instance]; otherwise, <c>false</c>.
/// </value>
public override bool FixtureSetupTeardownInstance
{
get { return true; }
}
public override bool FixtureSetupTeardownInstance => true;

/// <summary>
/// The _fixture attribute.
Expand Down

0 comments on commit bad30a0

Please sign in to comment.