From f8f5ba8c608b35364b6fbea44cef03907f7743f8 Mon Sep 17 00:00:00 2001 From: Terje Sandstrom Date: Sun, 12 Jul 2015 16:24:56 +0200 Subject: [PATCH] Added code for NUnit 3, and split V2 and V3 --- .../CreateUnitTests.NUnit.csproj | 3 + .../NUnit2FrameworkProvider.cs | 37 ++ .../NUnit2SolutionManager.cs | 49 +- .../NUnitFrameworkProvider.cs | 30 -- CreateUnitTests.NUnit/NUnitSolutionManager.cs | 51 ++ IntelliTest.NUnit/IntelliTest.NUnit.csproj | 7 +- IntelliTest.NUnit/NUnitAssertMethodFilter.cs | 11 +- IntelliTest.NUnit/NUnitTestFramework.cs | 497 +++++++++++++++--- .../NUnitTestFrameworkPackage.cs | 31 +- .../NunitTestFrameworkMetadata.cs | 2 +- Osiris.Extended.ruleset | 5 +- .../TestGeneration.Extensions.NUnit.csproj | 4 + TestGeneration.Extensions.NUnit/license.txt | 22 + .../source.extension.vsixmanifest | 9 +- 14 files changed, 590 insertions(+), 168 deletions(-) create mode 100644 CreateUnitTests.NUnit/NUnit2FrameworkProvider.cs create mode 100644 CreateUnitTests.NUnit/NUnitSolutionManager.cs create mode 100644 TestGeneration.Extensions.NUnit/license.txt diff --git a/CreateUnitTests.NUnit/CreateUnitTests.NUnit.csproj b/CreateUnitTests.NUnit/CreateUnitTests.NUnit.csproj index 3d7d837..e2e2c38 100644 --- a/CreateUnitTests.NUnit/CreateUnitTests.NUnit.csproj +++ b/CreateUnitTests.NUnit/CreateUnitTests.NUnit.csproj @@ -20,6 +20,7 @@ DEBUG;TRACE prompt 4 + ..\Osiris.Extended.ruleset pdbonly @@ -57,8 +58,10 @@ + + diff --git a/CreateUnitTests.NUnit/NUnit2FrameworkProvider.cs b/CreateUnitTests.NUnit/NUnit2FrameworkProvider.cs new file mode 100644 index 0000000..5f73c7f --- /dev/null +++ b/CreateUnitTests.NUnit/NUnit2FrameworkProvider.cs @@ -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 +{ + /// + /// The provider for the NUnit 2 unit test framework. + /// + [Export(typeof(IFrameworkProvider))] + public class NUnit2FrameworkProvider : FrameworkProviderBase + { + /// + /// Initializes a new instance of the class. + /// + /// The service provider to use to get the interfaces required. + /// The configuration settings object to be used to determine how the test method is generated. + /// The naming object used to decide how projects, classes and methods are named and created. + /// The directory object to use for directory operations. + [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)) + { + } + + /// + /// Gets the name of the provider. + /// + public override string Name => "NUnit2"; + + /// + /// Gets the name of the assembly. + /// + public override string AssemblyName => "nunit.framework"; + } +} \ No newline at end of file diff --git a/CreateUnitTests.NUnit/NUnit2SolutionManager.cs b/CreateUnitTests.NUnit/NUnit2SolutionManager.cs index c585d4c..b0f147a 100644 --- a/CreateUnitTests.NUnit/NUnit2SolutionManager.cs +++ b/CreateUnitTests.NUnit/NUnit2SolutionManager.cs @@ -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 @@ -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 - { - /// - /// Initializes a new instance of the class. - /// - /// The service provider to use to get the interfaces required. - /// The naming object used to decide how projects, classes and methods are named and created. - /// The directory object to use for directory operations. - public NUnitSolutionManager(IServiceProvider serviceProvider, INaming naming, IDirectory directory) - : base(serviceProvider, naming, directory) - { - } - - /// - /// Performs any preparatory tasks that have to be done after a new unit test project has been created. - /// - /// The of the unit test project that has just been created. - /// The of the source method that is to be unit tested. - 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) diff --git a/CreateUnitTests.NUnit/NUnitFrameworkProvider.cs b/CreateUnitTests.NUnit/NUnitFrameworkProvider.cs index 9d00124..05d94a2 100644 --- a/CreateUnitTests.NUnit/NUnitFrameworkProvider.cs +++ b/CreateUnitTests.NUnit/NUnitFrameworkProvider.cs @@ -16,36 +16,6 @@ namespace TestGeneration.Extensions.NUnit { - /// - /// The provider for the NUnit 2 unit test framework. - /// - [Export(typeof(IFrameworkProvider))] - public class NUnit2FrameworkProvider : FrameworkProviderBase - { - /// - /// Initializes a new instance of the class. - /// - /// The service provider to use to get the interfaces required. - /// The configuration settings object to be used to determine how the test method is generated. - /// The naming object used to decide how projects, classes and methods are named and created. - /// The directory object to use for directory operations. - [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)) - { - } - - /// - /// Gets the name of the provider. - /// - public override string Name => "NUnit2"; - - /// - /// Gets the name of the assembly. - /// - public override string AssemblyName => "nunit.framework"; - } - /// /// The provider for the NUnit 2 unit test framework. /// diff --git a/CreateUnitTests.NUnit/NUnitSolutionManager.cs b/CreateUnitTests.NUnit/NUnitSolutionManager.cs new file mode 100644 index 0000000..194c378 --- /dev/null +++ b/CreateUnitTests.NUnit/NUnitSolutionManager.cs @@ -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 + { + /// + /// Initializes a new instance of the class. + /// + /// The service provider to use to get the interfaces required. + /// The naming object used to decide how projects, classes and methods are named and created. + /// The directory object to use for directory operations. + public NUnitSolutionManager(IServiceProvider serviceProvider, INaming naming, IDirectory directory) + : base(serviceProvider, naming, directory) + { + } + + /// + /// Performs any preparatory tasks that have to be done after a new unit test project has been created. + /// + /// The of the unit test project that has just been created. + /// The of the source method that is to be unit tested. + 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(); + } + } + } +} \ No newline at end of file diff --git a/IntelliTest.NUnit/IntelliTest.NUnit.csproj b/IntelliTest.NUnit/IntelliTest.NUnit.csproj index 43b5fc6..5b1ed59 100644 --- a/IntelliTest.NUnit/IntelliTest.NUnit.csproj +++ b/IntelliTest.NUnit/IntelliTest.NUnit.csproj @@ -7,8 +7,8 @@ {9B87DC9E-151C-4F94-959F-657BBF72645F} Library Properties - NUnit - NUnit + TestGeneration.Extensions.IntelliTest.NUnit + TestGeneration.Extensions.IntelliTest.NUnit v4.5.2 512 @@ -20,6 +20,7 @@ DEBUG;TRACE prompt 4 + ..\Osiris.Extended.ruleset pdbonly @@ -54,7 +55,7 @@ - + diff --git a/IntelliTest.NUnit/NUnitAssertMethodFilter.cs b/IntelliTest.NUnit/NUnitAssertMethodFilter.cs index c40a0c1..1d954ec 100644 --- a/IntelliTest.NUnit/NUnitAssertMethodFilter.cs +++ b/IntelliTest.NUnit/NUnitAssertMethodFilter.cs @@ -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 +{ /// /// The n unit assert method filer. /// diff --git a/IntelliTest.NUnit/NUnitTestFramework.cs b/IntelliTest.NUnit/NUnitTestFramework.cs index 7977731..ce4cb6a 100644 --- a/IntelliTest.NUnit/NUnitTestFramework.cs +++ b/IntelliTest.NUnit/NUnitTestFramework.cs @@ -6,7 +6,8 @@ // NUnit test framework // // -------------------------------------------------------------------------------------------------------------------- -namespace Samples.Extensions.NUnit + +namespace TestGeneration.Extensions.IntelliTest.NUnit { using System; using System.Collections.Generic; @@ -25,17 +26,17 @@ namespace Samples.Extensions.NUnit using Microsoft.Pex.Engine.TestFrameworks; /// - /// NUnit test framework + /// NUnit 2 test framework /// [Serializable] - sealed class NUnitTestFramework : AttributeBasedTestFrameworkBase + sealed class NUnit2TestFramework : AttributeBasedTestFrameworkBase { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// /// - public NUnitTestFramework(IPexComponent host) + public NUnit2TestFramework(IPexComponent host) : base(host) { } @@ -56,49 +57,401 @@ public NUnitTestFramework(IPexComponent host) /// Gets the root namespace. /// /// The root namespace. - public override string RootNamespace + public override string RootNamespace => NUnitTestFrameworkMetadata.RootNamespace; + + /// + /// The test framework references. + /// + public override ICountable References => Indexable.One(new ShortReferenceAssemblyName(ShortAssemblyName.FromName("NUnit"), "2.6.4", AssemblyReferenceType.NugetReference)); + + /// + /// The _directory. + /// + private string directory = null; + + /// + /// Hint on the location of the test framework assembly + /// + /// + /// The directory. + /// + /// + /// The . + /// + public override bool TryGetDirectory(out string pdirectory) { - get { return NUnitTestFrameworkMetadata.RootNamespace; } + if (directory == null) + { + var programFiles = new DirectoryInfo(Environment.ExpandEnvironmentVariables("%ProgramFiles%")); + var info = programFiles.GetDirectories("NUnit-Net-*", SearchOption.TopDirectoryOnly); + directory = info.Length == 0 ? string.Empty : Path.Combine(info[0].FullName, "bin"); + } + + pdirectory = directory; + return !SafeString.IsNullOrEmpty(directory); } /// - /// The test framework references. + /// Gets a value indicating whether + /// partial test classes + /// + /// + public override bool SupportsPartialClasses => true; + + /// + /// The supports project bitness. + /// + /// + /// The bitness. + /// + /// + /// The . + /// + public override bool SupportsProjectBitness(Bitness bitness) + { + SafeDebug.Assume(bitness != Bitness.Unsupported, "bitness != Bitness.Unsupported"); + return true; + } + + /// + /// The _expected exception attribute. + /// + [NonSerialized] + TypeName expectedExceptionAttribute; + + /// + /// Gets the ExpectedException attribute. + /// + /// The expected exception attribute. + public override TypeName ExpectedExceptionAttribute => expectedExceptionAttribute ?? + (expectedExceptionAttribute = NUnitTestFrameworkMetadata.AttributeName("ExpectedException")); + + /// + /// Tries the read expected exception. + /// + /// + /// The method. + /// + /// + /// Type of the exception. + /// + /// + /// The . + /// + public override bool TryReadExpectedException(ICustomAttributeProviderEx target, out TypeEx exceptionType) + { + var attribute = AttributeHelper.GetAttribute(target, ExpectedExceptionAttribute); + if (attribute != null) + { + var attributeType = attribute.GetType(); + + // read exception type using reflection. + var field = attributeType.GetField("expectedException", BindingFlags.NonPublic | BindingFlags.Instance); + if (field != null) + { + var t = field.GetValue(attribute) as Type; + bool isClass; + if (t != null && ReflectionHelper.TryGetIsClass(t, out isClass) && isClass + && !ReflectionHelper.ContainsGenericParameters(t)) + { + exceptionType = MetadataFromReflection.GetType(t); + return true; + } + } + } + + exceptionType = null; + return false; + } + + /// + /// Tries to get the assembly set up tear down attribute. /// - public override ICountable References + /// + /// The assembly. + /// + /// + /// The set up. + /// + /// + /// The tear down. + /// + /// + /// The . + /// + public override bool TryGetAssemblySetupTeardownMethods(AssemblyEx assembly, out Method setUp, out Method tearDown) + { + setUp = null; + tearDown = null; + return false; + } + + /// + /// Gets a value indicating whether[fixture set up tear down are instance methods. + /// + /// + /// true if [fixture set up tear down instance]; otherwise, false. + /// + public override bool FixtureSetupTeardownInstance => true; + + /// + /// The _fixture attribute. + /// + [NonSerialized] + TypeName fixtureAttribute; + + /// + /// Gets the name of the fixture attribute + /// + /// The fixture attribute. + public override TypeName FixtureAttribute => fixtureAttribute ?? + (fixtureAttribute = NUnitTestFrameworkMetadata.AttributeName("TestFixture")); + + /// + /// The _fixture set up attribute. + /// + [NonSerialized] + TypeName fixtureSetUpAttribute; + + /// + /// Gets the name of the fixture setup attribute + /// + /// The fixture set up attribute. + public override TypeName FixtureSetupAttribute => fixtureSetUpAttribute ?? + (fixtureSetUpAttribute = NUnitTestFrameworkMetadata.AttributeName("TestFixtureSetUp")); + + /// + /// The _fixture tear down attribute. + /// + [NonSerialized] + TypeName fixtureTearDownAttribute; + + /// + /// Gets the name of the fixture teardown attribute + /// + /// The fixture tear down attribute. + public override TypeName FixtureTeardownAttribute => fixtureTearDownAttribute ?? + (fixtureTearDownAttribute = NUnitTestFrameworkMetadata.AttributeName("TestFixtureTearDown")); + + /// + /// The _set up attribute. + /// + [NonSerialized] + TypeName setUpAttribute; + + /// + /// Gets the name of the test setup attribute. + /// + /// The set up attribute. + public override TypeName SetupAttribute => setUpAttribute ?? + (setUpAttribute = NUnitTestFrameworkMetadata.AttributeName("SetUp")); + + /// + /// The _test attribute. + /// + [NonSerialized] + TypeName testAttribute; + + /// + /// Gets the name of the test attribute. + /// + /// The set up attribute. + public override TypeName TestAttribute => testAttribute ?? (testAttribute = NUnitTestFrameworkMetadata.AttributeName("Test")); + + /// + /// The _tear down attribute. + /// + [NonSerialized] + TypeName tearDownAttribute; + + /// + /// Gets the name of the test teardown attribute. + /// + /// The tear down attribute. + public override TypeName TeardownAttribute => tearDownAttribute ?? + (tearDownAttribute = NUnitTestFrameworkMetadata.AttributeName("TearDown")); + + /// + /// The _ignore attribute. + /// + [NonSerialized] + TypeName ignoreAttribute; + + /// + /// Gets the ignore attribute. + /// + /// The ignore attribute. + public override TypeName IgnoreAttribute => ignoreAttribute ?? + (ignoreAttribute = NUnitTestFrameworkMetadata.AttributeName("Ignore")); + + /// + /// Whether the ignore attribute constructor takes a message as its first argument. + /// + /// + protected override bool HasIgnoreAttributeMessage => true; + + /// + /// Gets the ignore message property. + /// + /// The ignore message property. + protected override string IgnoreMessageProperty => "Reason"; + + /// + /// Gets the expected exception property name. + /// + /// The expected exception property. + protected override string ExpectedExceptionProperty => "ExceptionType"; + + /// + /// Gets a list of attribute that should be duplicated from the + /// pex test to the parameterized test + /// + /// + /// The . + /// + protected override IEnumerable GetSatelliteAttributeTypes() + { + return Indexable.Array(CategoryAttribute, + NUnitTestFrameworkMetadata.AttributeName("Description"), + NUnitTestFrameworkMetadata.AttributeName("Explicit"), + NUnitTestFrameworkMetadata.AttributeName("Platform"), + NUnitTestFrameworkMetadata.AttributeName("Property") + ); + } + + /// + /// The _category attribute. + /// + [NonSerialized] + TypeName categoryAttribute; + + /// + /// Gets the category attribute. + /// + private TypeName CategoryAttribute => categoryAttribute ?? + (categoryAttribute = NUnitTestFrameworkMetadata.AttributeName("Category")); + + /// + /// Tries the get categories. + /// + /// + /// The element. + /// + /// + /// The names. + /// + /// + /// The . + /// + protected override bool TryGetCategories( ICustomAttributeProviderEx element, out IEnumerable names) + { + SafeDebug.AssumeNotNull(element, "element"); + + // TODO + names = null; + return false; + } + + /// + /// The _assertion exception type. + /// + [NonSerialized] + TypeName assertionExceptionType; + + /// + /// Gets the type of the assertion exception. + /// + /// The type of the assertion exception. + public override TypeName AssertionExceptionType { get { - return Indexable.One(new ShortReferenceAssemblyName(ShortAssemblyName.FromName("NUnit"), "2.6.4", AssemblyReferenceType.NugetReference)); + System.Diagnostics.Debugger.Launch(); + return assertionExceptionType ?? (assertionExceptionType = TypeDefinitionName.FromName( + NUnitTestFrameworkMetadata.AssemblyName, + -1, + false, + NUnitTestFrameworkMetadata.RootNamespace, + "AssertionException").SelfInstantiation); } } + /// + /// Gets a value indicating whether supports static test methods. + /// + public override bool SupportsStaticTestMethods => false; + + /// + /// Gets the assert method filters. + /// + public override IIndexable AssertMethodFilters => Indexable.One(NUnitAssertMethodFilter.Instance); + } + + + + /// + /// NUnit 2 test framework + /// + [Serializable] + sealed class NUnitTestFramework : AttributeBasedTestFrameworkBase + { + /// + /// Initializes a new instance of the class. + /// + /// + /// + public NUnitTestFramework(IPexComponent host) + : base(host) + { } + + /// + /// identify of the test framework + /// + /// + public override string Name => "NUnit"; + + /// + /// Gets the assembly name of the framework main's assembly. This name is used + /// to automatically discover test frameworks, based the assembly references + /// + /// + public override ShortAssemblyName AssemblyName => NUnitTestFrameworkMetadata.AssemblyName; + + /// + /// Gets the root namespace. + /// + /// The root namespace. + public override string RootNamespace => NUnitTestFrameworkMetadata.RootNamespace; + + /// + /// The test framework references. + /// + public override ICountable References => Indexable.One(new ShortReferenceAssemblyName(ShortAssemblyName.FromName("NUnit"), "3.0.0-beta-2", AssemblyReferenceType.NugetReference)); + /// /// The _directory. /// - private string _directory = null; + private string directory = null; /// /// Hint on the location of the test framework assembly /// - /// + /// /// The directory. /// /// /// The . /// - public override bool TryGetDirectory(out string directory) + public override bool TryGetDirectory(out string pdirectory) { - if (this._directory == null) + if (directory == null) { - DirectoryInfo programFiles = new DirectoryInfo(Environment.ExpandEnvironmentVariables("%ProgramFiles%")); - DirectoryInfo[] info = programFiles.GetDirectories("NUnit-Net-*", SearchOption.TopDirectoryOnly); - if (info == null || info.Length == 0) - this._directory = string.Empty; - else - this._directory = Path.Combine(info[0].FullName, "bin"); + var programFiles = new DirectoryInfo(Environment.ExpandEnvironmentVariables("%ProgramFiles%")); + var info = programFiles.GetDirectories("NUnit-Net-*", SearchOption.TopDirectoryOnly); + directory = info.Length == 0 ? string.Empty : Path.Combine(info[0].FullName, "bin"); } - directory = this._directory; + pdirectory = directory; return !SafeString.IsNullOrEmpty(directory); } @@ -128,14 +481,14 @@ public override bool SupportsProjectBitness(Bitness bitness) /// The _expected exception attribute. /// [NonSerialized] - TypeName _expectedExceptionAttribute; + TypeName expectedExceptionAttribute; /// /// Gets the ExpectedException attribute. /// /// The expected exception attribute. - public override TypeName ExpectedExceptionAttribute => this._expectedExceptionAttribute ?? - (this._expectedExceptionAttribute = NUnitTestFrameworkMetadata.AttributeName("ExpectedException")); + public override TypeName ExpectedExceptionAttribute => expectedExceptionAttribute ?? + (expectedExceptionAttribute = NUnitTestFrameworkMetadata.AttributeName("ExpectedException")); /// /// Tries the read expected exception. @@ -149,20 +502,18 @@ public override bool SupportsProjectBitness(Bitness bitness) /// /// The . /// - public override bool TryReadExpectedException( - ICustomAttributeProviderEx target, - out TypeEx exceptionType) + public override bool TryReadExpectedException(ICustomAttributeProviderEx target, out TypeEx exceptionType) { - object attribute = AttributeHelper.GetAttribute(target, this.ExpectedExceptionAttribute); + var attribute = AttributeHelper.GetAttribute(target, ExpectedExceptionAttribute); if (attribute != null) { - Type attributeType = attribute.GetType(); + var attributeType = attribute.GetType(); // read exception type using reflection. var field = attributeType.GetField("expectedException", BindingFlags.NonPublic | BindingFlags.Instance); if (field != null) { - Type t = field.GetValue(attribute) as Type; + var t = field.GetValue(attribute) as Type; bool isClass; if (t != null && ReflectionHelper.TryGetIsClass(t, out isClass) && isClass && !ReflectionHelper.ContainsGenericParameters(t)) @@ -192,10 +543,7 @@ public override bool TryReadExpectedException( /// /// The . /// - public override bool TryGetAssemblySetupTeardownMethods( - AssemblyEx assembly, - out Method setUp, - out Method tearDown) + public override bool TryGetAssemblySetupTeardownMethods(AssemblyEx assembly, out Method setUp, out Method tearDown) { setUp = null; tearDown = null; @@ -214,91 +562,97 @@ public override bool TryGetAssemblySetupTeardownMethods( /// The _fixture attribute. /// [NonSerialized] - TypeName _fixtureAttribute; + TypeName fixtureAttribute; /// /// Gets the name of the fixture attribute /// /// The fixture attribute. - public override TypeName FixtureAttribute => this._fixtureAttribute ?? - (this._fixtureAttribute = NUnitTestFrameworkMetadata.AttributeName("TestFixture")); + public override TypeName FixtureAttribute => fixtureAttribute ?? + (fixtureAttribute = NUnitTestFrameworkMetadata.AttributeName("TestFixture")); /// /// The _fixture set up attribute. /// [NonSerialized] - TypeName _fixtureSetUpAttribute; + TypeName fixtureSetUpAttribute; /// /// Gets the name of the fixture setup attribute /// /// The fixture set up attribute. - public override TypeName FixtureSetupAttribute => this._fixtureSetUpAttribute ?? - (this._fixtureSetUpAttribute = NUnitTestFrameworkMetadata.AttributeName("TestFixtureSetUp")); + public override TypeName FixtureSetupAttribute => fixtureSetUpAttribute ?? + (fixtureSetUpAttribute = NUnitTestFrameworkMetadata.AttributeName("OneTimeSetUp")); /// /// The _fixture tear down attribute. /// [NonSerialized] - TypeName _fixtureTearDownAttribute; + TypeName fixtureTearDownAttribute; /// /// Gets the name of the fixture teardown attribute /// /// The fixture tear down attribute. - public override TypeName FixtureTeardownAttribute => this._fixtureTearDownAttribute ?? - (this._fixtureTearDownAttribute = NUnitTestFrameworkMetadata.AttributeName("TestFixtureTearDown")); + public override TypeName FixtureTeardownAttribute => fixtureTearDownAttribute ?? + (fixtureTearDownAttribute = NUnitTestFrameworkMetadata.AttributeName("OneTimeTearDown")); /// /// The _set up attribute. /// [NonSerialized] - TypeName _setUpAttribute; + TypeName setUpAttribute; /// /// Gets the name of the test setup attribute. /// /// The set up attribute. - public override TypeName SetupAttribute => this._setUpAttribute ?? - (this._setUpAttribute = NUnitTestFrameworkMetadata.AttributeName("SetUp")); + public override TypeName SetupAttribute => setUpAttribute ?? + (setUpAttribute = NUnitTestFrameworkMetadata.AttributeName("SetUp")); /// /// The _test attribute. /// [NonSerialized] - TypeName _testAttribute; + TypeName testAttribute; /// /// Gets the name of the test attribute. /// /// The set up attribute. - public override TypeName TestAttribute => this._testAttribute ?? (this._testAttribute = NUnitTestFrameworkMetadata.AttributeName("Test")); + public override TypeName TestAttribute => testAttribute ?? (testAttribute = NUnitTestFrameworkMetadata.AttributeName("Test")); /// /// The _tear down attribute. /// [NonSerialized] - TypeName _tearDownAttribute; + TypeName tearDownAttribute; /// /// Gets the name of the test teardown attribute. /// /// The tear down attribute. - public override TypeName TeardownAttribute => this._tearDownAttribute ?? - (this._tearDownAttribute = NUnitTestFrameworkMetadata.AttributeName("TearDown")); + public override TypeName TeardownAttribute + { + get + { + return tearDownAttribute ?? + (tearDownAttribute = NUnitTestFrameworkMetadata.AttributeName("TearDown")); + } + } /// /// The _ignore attribute. /// [NonSerialized] - TypeName _ignoreAttribute; + TypeName ignoreAttribute; /// /// Gets the ignore attribute. /// /// The ignore attribute. - public override TypeName IgnoreAttribute => this._ignoreAttribute ?? - (this._ignoreAttribute = NUnitTestFrameworkMetadata.AttributeName("Ignore")); + public override TypeName IgnoreAttribute => ignoreAttribute ?? + (ignoreAttribute = NUnitTestFrameworkMetadata.AttributeName("Ignore")); /// /// Whether the ignore attribute constructor takes a message as its first argument. @@ -327,11 +681,10 @@ public override bool TryGetAssemblySetupTeardownMethods( /// protected override IEnumerable GetSatelliteAttributeTypes() { - return Indexable.Array( - this.CategoryAttribute, - NUnitTestFrameworkMetadata.AttributeName("Description"), - NUnitTestFrameworkMetadata.AttributeName("Explicit"), - NUnitTestFrameworkMetadata.AttributeName("Platform"), + return Indexable.Array(CategoryAttribute, + NUnitTestFrameworkMetadata.AttributeName("Description"), + NUnitTestFrameworkMetadata.AttributeName("Explicit"), + NUnitTestFrameworkMetadata.AttributeName("Platform"), NUnitTestFrameworkMetadata.AttributeName("Property") ); } @@ -340,13 +693,13 @@ protected override IEnumerable GetSatelliteAttributeTypes() /// The _category attribute. /// [NonSerialized] - TypeName _categoryAttribute; + TypeName categoryAttribute; /// /// Gets the category attribute. /// - private TypeName CategoryAttribute => this._categoryAttribute ?? - (this._categoryAttribute = NUnitTestFrameworkMetadata.AttributeName("Category")); + private TypeName CategoryAttribute => categoryAttribute ?? + (categoryAttribute = NUnitTestFrameworkMetadata.AttributeName("Category")); /// /// Tries the get categories. @@ -360,9 +713,7 @@ protected override IEnumerable GetSatelliteAttributeTypes() /// /// The . /// - protected override bool TryGetCategories( - ICustomAttributeProviderEx element, - out IEnumerable names) + protected override bool TryGetCategories(ICustomAttributeProviderEx element, out IEnumerable names) { SafeDebug.AssumeNotNull(element, "element"); @@ -375,7 +726,7 @@ protected override bool TryGetCategories( /// The _assertion exception type. /// [NonSerialized] - TypeName _assertionExceptionType; + TypeName assertionExceptionType; /// /// Gets the type of the assertion exception. @@ -386,14 +737,12 @@ public override TypeName AssertionExceptionType get { System.Diagnostics.Debugger.Launch(); - if (this._assertionExceptionType == null) - this._assertionExceptionType = TypeDefinitionName.FromName( - NUnitTestFrameworkMetadata.AssemblyName, - -1, - false, - NUnitTestFrameworkMetadata.RootNamespace, - "AssertionException").SelfInstantiation; - return this._assertionExceptionType; + return assertionExceptionType ?? (assertionExceptionType = TypeDefinitionName.FromName( + NUnitTestFrameworkMetadata.AssemblyName, + -1, + false, + NUnitTestFrameworkMetadata.RootNamespace, + "AssertionException").SelfInstantiation); } } diff --git a/IntelliTest.NUnit/NUnitTestFrameworkPackage.cs b/IntelliTest.NUnit/NUnitTestFrameworkPackage.cs index 2c356c7..289bfdf 100644 --- a/IntelliTest.NUnit/NUnitTestFrameworkPackage.cs +++ b/IntelliTest.NUnit/NUnitTestFrameworkPackage.cs @@ -8,11 +8,13 @@ // -------------------------------------------------------------------------------------------------------------------- using Microsoft.Pex.Framework.Packages; -using Samples.Extensions.NUnit; +using TestGeneration.Extensions.IntelliTest.NUnit; + +[assembly: PexPackageType(typeof(NUnit2TestFrameworkPackage))] [assembly: PexPackageType(typeof(NUnitTestFrameworkPackage))] -namespace Samples.Extensions.NUnit +namespace TestGeneration.Extensions.IntelliTest.NUnit { using Microsoft.ExtendedReflection.ComponentModel; using Microsoft.Pex.Engine.ComponentModel; @@ -21,8 +23,29 @@ namespace Samples.Extensions.NUnit using Microsoft.Pex.Framework.Packages; /// - /// Sample extensions package for NUnit. + /// Extensions package for NUnit. /// + public class Nunit2TestFrameworkPackageAttribute : PexPackageAttributeBase + { + protected override void Initialize(IEngine engine) + { + base.Initialize(engine); + + var testFrameworkService = engine.GetService(); + var host = testFrameworkService as IPexComponent; + + testFrameworkService.AddTestFramework(new NUnit2TestFramework(host)); + } + + public override string Name => nameof(NUnit2TestFrameworkPackage); + } + + [Nunit2TestFrameworkPackage] + static class NUnit2TestFrameworkPackage + { + } + + public class NunitTestFrameworkPackageAttribute : PexPackageAttributeBase { protected override void Initialize(IEngine engine) @@ -35,7 +58,7 @@ protected override void Initialize(IEngine engine) testFrameworkService.AddTestFramework(new NUnitTestFramework(host)); } - public override string Name => "NUnitTestFrameworkPackage"; + public override string Name => nameof(NUnitTestFrameworkPackage); } [NunitTestFrameworkPackage] diff --git a/IntelliTest.NUnit/NunitTestFrameworkMetadata.cs b/IntelliTest.NUnit/NunitTestFrameworkMetadata.cs index 4e1c82f..ab9ac69 100644 --- a/IntelliTest.NUnit/NunitTestFrameworkMetadata.cs +++ b/IntelliTest.NUnit/NunitTestFrameworkMetadata.cs @@ -7,7 +7,7 @@ // // -------------------------------------------------------------------------------------------------------------------- -namespace Samples.Extensions.NUnit +namespace TestGeneration.Extensions.IntelliTest.NUnit { using Microsoft.ExtendedReflection.Metadata.Names; using Microsoft.ExtendedReflection.Utilities.Safe.Diagnostics; diff --git a/Osiris.Extended.ruleset b/Osiris.Extended.ruleset index 1f5b160..1ad3bbc 100644 --- a/Osiris.Extended.ruleset +++ b/Osiris.Extended.ruleset @@ -1,10 +1,13 @@  - + + + + diff --git a/TestGeneration.Extensions.NUnit/TestGeneration.Extensions.NUnit.csproj b/TestGeneration.Extensions.NUnit/TestGeneration.Extensions.NUnit.csproj index 582170d..92673dd 100644 --- a/TestGeneration.Extensions.NUnit/TestGeneration.Extensions.NUnit.csproj +++ b/TestGeneration.Extensions.NUnit/TestGeneration.Extensions.NUnit.csproj @@ -50,6 +50,10 @@ + + Always + true + diff --git a/TestGeneration.Extensions.NUnit/license.txt b/TestGeneration.Extensions.NUnit/license.txt new file mode 100644 index 0000000..d550c67 --- /dev/null +++ b/TestGeneration.Extensions.NUnit/license.txt @@ -0,0 +1,22 @@ +The MIT License (MIT) + +Copyright (c) <2015> +Copyright (c) <2015> + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. \ No newline at end of file diff --git a/TestGeneration.Extensions.NUnit/source.extension.vsixmanifest b/TestGeneration.Extensions.NUnit/source.extension.vsixmanifest index 9599a27..ee776d3 100644 --- a/TestGeneration.Extensions.NUnit/source.extension.vsixmanifest +++ b/TestGeneration.Extensions.NUnit/source.extension.vsixmanifest @@ -1,9 +1,12 @@ - - Package for Test Generation NUnit extensions - Test Generation NUnit extensions + + Test Generation NUnit extensions + Test Generation NUnit extensions + + license.txt + unit testing, NUnit