зеркало из
1
0
Форкнуть 0

Merge pull request #11 from nunit/issue-10

Updated the settings and added unit tests
This commit is contained in:
Rob Prouse 2016-07-12 21:06:16 -04:00 коммит произвёл GitHub
Родитель 0fc4eeb163 c4bcf64b87
Коммит 9faaaf90b1
19 изменённых файлов: 1214 добавлений и 248 удалений

Просмотреть файл

@ -9,7 +9,10 @@
<ToolsOptions>
<ToolsOptionsCategory name="TextEditor">
<ToolsOptionsSubCategory name="CSharp-Specific">
<PropertyValue name="AddImport_SuggestForTypesInNuGetPackages">0</PropertyValue>
<PropertyValue name="AddImport_SuggestForTypesInReferenceAssemblies">0</PropertyValue>
<PropertyValue name="AutoComment">1</PropertyValue>
<PropertyValue name="AutoInsertAsteriskForNewLinesOfBlockComments">1</PropertyValue>
<PropertyValue name="BringUpOnIdentifier">1</PropertyValue>
<PropertyValue name="CSharpClosedFileDiagnostics">-1</PropertyValue>
<PropertyValue name="ClosedFileDiagnostics">-1</PropertyValue>
@ -81,7 +84,7 @@
<PropertyValue name="Style_PreferIntrinsicPredefinedTypeKeywordInMemberAccess">1</PropertyValue>
<PropertyValue name="Style_QualifyMemberAccessWithThisOrMe">0</PropertyValue>
<PropertyValue name="Style_UseVarWhenDeclaringLocals">1</PropertyValue>
<PropertyValue name="WarnOnBuildErrors">1</PropertyValue>
<PropertyValue name="WarnOnBuildErrors">0</PropertyValue>
<PropertyValue name="WarnWhenMembersCauseCompilerGeneratedReferences">1</PropertyValue>
<PropertyValue name="Wrapping_IgnoreSpacesAroundBinaryOperators">0</PropertyValue>
<PropertyValue name="Wrapping_IgnoreSpacesAroundVariableDeclaration">0</PropertyValue>

Просмотреть файл

@ -0,0 +1,119 @@
// ***********************************************************************
// Copyright (c) 2014 Charlie Poole
//
// 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.
// ***********************************************************************
namespace NUnit.Engine
{
/// <summary>
/// PackageSettings is a static class containing constant values that
/// are used as keys in setting up a TestPackage. These values are used in
/// the engine and framework. Setting values may be a string, int or bool.
/// </summary>
public static class FrameworkSettings
{
#region Common Settings - Used by both the Engine and the 3.0 Framework
/// <summary>
/// Flag (bool) indicating whether tests are being debugged.
/// </summary>
public const string DebugTests = "DebugTests";
/// <summary>
/// Flag (bool) indicating whether to pause execution of tests to allow
/// the user to attache a debugger.
/// </summary>
public const string PauseBeforeRun = "PauseBeforeRun";
/// <summary>
/// The InternalTraceLevel for this run. Values are: "Default",
/// "Off", "Error", "Warning", "Info", "Debug", "Verbose".
/// Default is "Off". "Debug" and "Verbose" are synonyms.
/// </summary>
public const string InternalTraceLevel = "InternalTraceLevel";
/// <summary>
/// Full path of the directory to be used for work and result files.
/// This path is provided to tests by the frameowrk TestContext.
/// </summary>
public const string WorkDirectory = "WorkDirectory";
#endregion
#region Framework Settings - Passed through and used by the 3.0 Framework
/// <summary>
/// Integer value in milliseconds for the default timeout value
/// for test cases. If not specified, there is no timeout except
/// as specified by attributes on the tests themselves.
/// </summary>
public const string DefaultTimeout = "DefaultTimeout";
/// <summary>
/// A TextWriter to which the internal trace will be sent.
/// </summary>
public const string InternalTraceWriter = "InternalTraceWriter";
/// <summary>
/// A list of tests to be loaded.
/// </summary>
// TODO: Remove?
public const string LOAD = "LOAD";
/// <summary>
/// The number of test threads to run for the assembly. If set to
/// 1, a single queue is used. If set to 0, tests are executed
/// directly, without queuing.
/// </summary>
public const string NumberOfTestWorkers = "NumberOfTestWorkers";
/// <summary>
/// The random seed to be used for this assembly. If specified
/// as the value reported from a prior run, the framework should
/// generate identical random values for tests as were used for
/// that run, provided that no change has been made to the test
/// assembly. Default is a random value itself.
/// </summary>
public const string RandomSeed = "RandomSeed";
/// <summary>
/// If true, execution stops after the first error or failure.
/// </summary>
public const string StopOnError = "StopOnError";
/// <summary>
/// If true, use of the event queue is suppressed and test events are synchronous.
/// </summary>
public const string SynchronousEvents = "SynchronousEvents";
/// <summary>
/// The default naming pattern used in generating test names
/// </summary>
public const string DefaultTestNamePattern = "DefaultTestNamePattern";
/// <summary>
/// Parameters to be passed on to the test
/// </summary>
public const string TestParameters = "TestParameters";
#endregion
}
}

Просмотреть файл

@ -144,7 +144,7 @@ using System.Text.RegularExpressions;
// Missing XML Docs
#pragma warning disable 1591
using NUnit.Compatibility;
using NUnit.Engine;
using System.Linq;
namespace NUnit.Options

Просмотреть файл

@ -8,10 +8,10 @@
// 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
@ -23,7 +23,7 @@
using System;
namespace NUnit.Common
namespace NUnit.Engine
{
/// <summary>
/// OutputSpecification encapsulates a file output path and format

Просмотреть файл

@ -1,231 +0,0 @@
// ***********************************************************************
// Copyright (c) 2014 Charlie Poole
//
// 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.
// ***********************************************************************
namespace NUnit.Common
{
/// <summary>
/// PackageSettings is a static class containing constant values that
/// are used as keys in setting up a TestPackage. These values are used in
/// the engine and framework. Setting values may be a string, int or bool.
/// </summary>
public static class PackageSettings
{
#region Common Settings - Used by both the Engine and the 3.0 Framework
/// <summary>
/// Flag (bool) indicating whether tests are being debugged.
/// </summary>
public const string DebugTests = "DebugTests";
/// <summary>
/// Flag (bool) indicating whether to pause execution of tests to allow
/// the user to attache a debugger.
/// </summary>
public const string PauseBeforeRun = "PauseBeforeRun";
/// <summary>
/// The InternalTraceLevel for this run. Values are: "Default",
/// "Off", "Error", "Warning", "Info", "Debug", "Verbose".
/// Default is "Off". "Debug" and "Verbose" are synonyms.
/// </summary>
public const string InternalTraceLevel = "InternalTraceLevel";
/// <summary>
/// Full path of the directory to be used for work and result files.
/// This path is provided to tests by the frameowrk TestContext.
/// </summary>
public const string WorkDirectory = "WorkDirectory";
#endregion
#region Engine Settings - Used by the Engine itself
/// <summary>
/// The name of the config to use in loading a project.
/// If not specified, the first config found is used.
/// </summary>
public const string ActiveConfig = "ActiveConfig";
/// <summary>
/// Bool indicating whether the engine should determine the private
/// bin path by examining the paths to all the tests. Defaults to
/// true unless PrivateBinPath is specified.
/// </summary>
public const string AutoBinPath = "AutoBinPath";
/// <summary>
/// The ApplicationBase to use in loading the tests. If not
/// specified, and each assembly has its own process, then the
/// location of the assembly is used. For multiple assemblies
/// in a single process, the closest common root directory is used.
/// </summary>
public const string BasePath = "BasePath";
/// <summary>
/// Path to the config file to use in running the tests.
/// </summary>
public const string ConfigurationFile = "ConfigurationFile";
/// <summary>
/// Bool flag indicating whether a debugger should be launched at agent
/// startup. Used only for debugging NUnit itself.
/// </summary>
public const string DebugAgent = "DebugAgent";
/// <summary>
/// Indicates how to load tests across AppDomains. Values are:
/// "Default", "None", "Single", "Multiple". Default is "Multiple"
/// if more than one assembly is loaded in a process. Otherwise,
/// it is "Single".
/// </summary>
public const string DomainUsage = "DomainUsage";
/// <summary>
/// The private binpath used to locate assemblies. Directory paths
/// is separated by a semicolon. It's an error to specify this and
/// also set AutoBinPath to true.
/// </summary>
public const string PrivateBinPath = "PrivateBinPath";
/// <summary>
/// The maximum number of test agents permitted to run simultneously.
/// Ignored if the ProcessModel is not set or defaulted to Multiple.
/// </summary>
public const string MaxAgents = "MaxAgents";
/// <summary>
/// Indicates how to allocate assemblies to processes. Values are:
/// "Default", "Single", "Separate", "Multiple". Default is "Multiple"
/// for more than one assembly, "Separate" for a single assembly.
/// </summary>
public const string ProcessModel = "ProcessModel";
/// <summary>
/// Indicates the desired runtime to use for the tests. Values
/// are strings like "net-4.5", "mono-4.0", etc. Default is to
/// use the target framework for which an assembly was built.
/// </summary>
public const string RuntimeFramework = "RuntimeFramework";
/// <summary>
/// Bool flag indicating that the test should be run in a 32-bit process
/// on a 64-bit system. By default, NUNit runs in a 64-bit process on
/// a 64-bit system. Ignored if set on a 32-bit system.
/// </summary>
public const string RunAsX86 = "RunAsX86";
/// <summary>
/// Indicates that test runners should be disposed after the tests are executed
/// </summary>
public const string DisposeRunners = "DisposeRunners";
/// <summary>
/// Bool flag indicating that the test assemblies should be shadow copied.
/// Defaults to false.
/// </summary>
public const string ShadowCopyFiles = "ShadowCopyFiles";
#endregion
#region Framework Settings - Passed through and used by the 3.0 Framework
/// <summary>
/// Integer value in milliseconds for the default timeout value
/// for test cases. If not specified, there is no timeout except
/// as specified by attributes on the tests themselves.
/// </summary>
public const string DefaultTimeout = "DefaultTimeout";
/// <summary>
/// A TextWriter to which the internal trace will be sent.
/// </summary>
public const string InternalTraceWriter = "InternalTraceWriter";
/// <summary>
/// A list of tests to be loaded.
/// </summary>
// TODO: Remove?
public const string LOAD = "LOAD";
/// <summary>
/// The number of test threads to run for the assembly. If set to
/// 1, a single queue is used. If set to 0, tests are executed
/// directly, without queuing.
/// </summary>
public const string NumberOfTestWorkers = "NumberOfTestWorkers";
/// <summary>
/// The random seed to be used for this assembly. If specified
/// as the value reported from a prior run, the framework should
/// generate identical random values for tests as were used for
/// that run, provided that no change has been made to the test
/// assembly. Default is a random value itself.
/// </summary>
public const string RandomSeed = "RandomSeed";
/// <summary>
/// If true, execution stops after the first error or failure.
/// </summary>
public const string StopOnError = "StopOnError";
/// <summary>
/// If true, use of the event queue is suppressed and test events are synchronous.
/// </summary>
public const string SynchronousEvents = "SynchronousEvents";
/// <summary>
/// The default naming pattern used in generating test names
/// </summary>
public const string DefaultTestNamePattern = "DefaultTestNamePattern";
#endregion
#region Internal Settings - Used only within the engine
/// <summary>
/// If the package represents an assembly, then this is the CLR version
/// stored in the assembly image. If it represents a project or other
/// group of assemblies, it is the maximum version for all the assemblies.
/// </summary>
public const string ImageRuntimeVersion = "ImageRuntimeVersion";
/// <summary>
/// True if any assembly in the package requires running as a 32-bit
/// process when on a 64-bit system.
/// </summary>
public const string ImageRequiresX86 = "ImageRequiresX86";
/// <summary>
/// True if any assembly in the package requires a special assembly resolution hook
/// in the default AppDomain in order to find dependent assemblies.
/// </summary>
public const string ImageRequiresDefaultAppDomainAssemblyResolver = "ImageRequiresDefaultAppDomainAssemblyResolver";
/// <summary>
/// The FrameworkName specified on a TargetFrameworkAttribute for the assembly
/// </summary>
public const string ImageTargetFrameworkName = "ImageTargetFrameworkName";
#endregion
}
}

Просмотреть файл

@ -8,10 +8,10 @@
// 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
@ -23,10 +23,10 @@
using System.Collections.Generic;
namespace NUnit.Common
namespace NUnit.Engine
{
/// <summary>
/// TestNameParser is used to parse the arguments to the
/// TestNameParser is used to parse the arguments to the
/// -run option, separating testnames at the correct point.
/// </summary>
public class TestNameParser

Просмотреть файл

@ -23,7 +23,7 @@
using System;
using System.Reflection;
namespace NUnit.Compatibility
namespace NUnit.Engine
{
/// <summary>
/// Provides a platform-independent methods for getting attributes

Просмотреть файл

@ -26,7 +26,7 @@ using System.Collections.Generic;
using System.Reflection;
using System.Linq;
namespace NUnit.Compatibility
namespace NUnit.Engine
{
/// <summary>
/// Provides NUnit specific extensions to aid in Reflection

Просмотреть файл

@ -24,7 +24,6 @@
using System;
using System.Linq;
using System.Collections.Generic;
using NUnit.Compatibility;
using NUnit.Engine.Internal;
using System.Reflection;

Просмотреть файл

@ -8,10 +8,10 @@
// 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
@ -24,7 +24,6 @@
using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Common;
// Missing XML Docs
#pragma warning disable 1591

Просмотреть файл

@ -0,0 +1,64 @@
// ***********************************************************************
// Copyright (c) 2016 Charlie Poole
//
// 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.
// ***********************************************************************
using System;
using System.IO;
using System.Reflection;
using NUnit.Framework;
namespace NUnit.Engine.Tests
{
[TestFixture]
public class AssemblyHelperTests
{
#if NET451
private static readonly string THIS_ASSEMBLY_PATH = "NUnit.Portable.Agent.Tests.exe";
#else
private static readonly string THIS_ASSEMBLY_PATH = "NUnit.Portable.Agent.Tests.dll";
#endif
private static readonly string THIS_ASSEMBLY_NAME = "NUnit.Portable.Agent.Tests";
public void GetNameForAssembly()
{
var assemblyName = AssemblyHelper.GetAssemblyName(this.GetType().GetTypeInfo().Assembly);
Assert.That(assemblyName.Name, Is.EqualTo(THIS_ASSEMBLY_NAME).IgnoreCase);
Assert.That(assemblyName.FullName, Is.EqualTo(THIS_ASSEMBLY_PATH).IgnoreCase);
}
[Test]
public void GetPathForAssembly()
{
string path = AssemblyHelper.GetAssemblyPath(this.GetType().GetTypeInfo().Assembly);
Assert.That(Path.GetFileName(path), Is.EqualTo(THIS_ASSEMBLY_PATH).IgnoreCase);
Assert.That(File.Exists(path));
}
[Test]
public void GetPathForType()
{
string path = AssemblyHelper.GetAssemblyPath(this.GetType());
Assert.That(Path.GetFileName(path), Is.EqualTo(THIS_ASSEMBLY_PATH).IgnoreCase);
Assert.That(File.Exists(path));
}
}
}

Просмотреть файл

@ -0,0 +1,126 @@
// ***********************************************************************
// Copyright (c) 2016 Charlie Poole
//
// 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.
// ***********************************************************************
using System;
using NUnit.Common;
using NUnit.Framework;
namespace NUnit.Engine.Tests
{
public class OutputSpecificationTests
{
[Test]
public void SpecMayNotBeNull()
{
Assert.That(
() => new NUnit.Engine.OutputSpecification(null),
Throws.TypeOf<NullReferenceException>());
}
[Test]
public void SpecOptionMustContainEqualSign()
{
Assert.That(
() => new NUnit.Engine.OutputSpecification("MyFile.xml;transform.xslt"),
Throws.TypeOf<ArgumentException>());
}
[Test]
public void SpecOptionMustContainJustOneEqualSign()
{
Assert.That(
() => new NUnit.Engine.OutputSpecification("MyFile.xml;transform=xslt=transform.xslt"),
Throws.TypeOf<ArgumentException>());
}
[Test]
public void FileNameOnly()
{
var spec = new NUnit.Engine.OutputSpecification("MyFile.xml");
Assert.That(spec.OutputPath, Is.EqualTo("MyFile.xml"));
Assert.That(spec.Format, Is.EqualTo("nunit3"));
Assert.Null(spec.Transform);
}
[Test]
public void FileNamePlusFormat()
{
var spec = new NUnit.Engine.OutputSpecification("MyFile.xml;format=nunit2");
Assert.That(spec.OutputPath, Is.EqualTo("MyFile.xml"));
Assert.That(spec.Format, Is.EqualTo("nunit2"));
Assert.Null(spec.Transform);
}
[Test]
public void FileNamePlusTransform()
{
var spec = new NUnit.Engine.OutputSpecification("MyFile.xml;transform=transform.xslt");
Assert.That(spec.OutputPath, Is.EqualTo("MyFile.xml"));
Assert.That(spec.Format, Is.EqualTo("user"));
Assert.That(spec.Transform, Is.EqualTo("transform.xslt"));
}
[Test]
public void UserFormatMayBeIndicatedExplicitlyAfterTransform()
{
var spec = new NUnit.Engine.OutputSpecification("MyFile.xml;transform=transform.xslt;format=user");
Assert.That(spec.OutputPath, Is.EqualTo("MyFile.xml"));
Assert.That(spec.Format, Is.EqualTo("user"));
Assert.That(spec.Transform, Is.EqualTo("transform.xslt"));
}
[Test]
public void UserFormatMayBeIndicatedExplicitlyBeforeTransform()
{
var spec = new NUnit.Engine.OutputSpecification("MyFile.xml;format=user;transform=transform.xslt");
Assert.That(spec.OutputPath, Is.EqualTo("MyFile.xml"));
Assert.That(spec.Format, Is.EqualTo("user"));
Assert.That(spec.Transform, Is.EqualTo("transform.xslt"));
}
[Test]
public void MultipleFormatSpecifiersNotAllowed()
{
Assert.That(
() => new NUnit.Engine.OutputSpecification("MyFile.xml;format=nunit2;format=nunit3"),
Throws.TypeOf<ArgumentException>());
}
[Test]
public void MultipleTransformSpecifiersNotAllowed()
{
Assert.That(
() => new NUnit.Engine.OutputSpecification("MyFile.xml;transform=transform1.xslt;transform=transform2.xslt"),
Throws.TypeOf<ArgumentException>());
}
[Test]
public void TransformWithNonUserFormatNotAllowed()
{
Assert.That(
() => new NUnit.Engine.OutputSpecification("MyFile.xml;format=nunit2;transform=transform.xslt"),
Throws.TypeOf<ArgumentException>());
}
}
}

Просмотреть файл

@ -0,0 +1,59 @@
// ***********************************************************************
// Copyright (c) 2016 Charlie Poole
//
// 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.
// ***********************************************************************
using NUnit.Framework;
namespace NUnit.Engine.Tests
{
public class TestNameParserTests
{
[TestCase("Test.Namespace.Fixture.Method")]
[TestCase("Test.Namespace.Fixture.Method,")]
[TestCase(" Test.Namespace.Fixture.Method ")]
[TestCase(" Test.Namespace.Fixture.Method ,")]
[TestCase("Test.Namespace.Fixture.Method()")]
[TestCase("Test.Namespace.Fixture.Method(\"string,argument\")")]
[TestCase("Test.Namespace.Fixture.Method(1,2,3)")]
[TestCase("Test.Namespace.Fixture.Method<int,int>()")]
[TestCase("Test.Namespace.Fixture.Method(\")\")")]
public void SingleName(string name)
{
string[] names = TestNameParser.Parse(name);
Assert.AreEqual(1, names.Length);
Assert.AreEqual(name.Trim(new char[] { ' ', ',' }), names[0]);
}
[TestCase("Test.Namespace.Fixture.Method1", "Test.Namespace.Fixture.Method2")]
[TestCase("Test.Namespace.Fixture.Method1", "Test.Namespace.Fixture.Method2,")] // <= trailing comma
[TestCase("Test.Namespace.Fixture.Method1(1,2)", "Test.Namespace.Fixture.Method2(3,4)")]
[TestCase("Test.Namespace.Fixture.Method1(\"(\")", "Test.Namespace.Fixture.Method2(\"<\")")]
public void TwoNames(string name1, string name2)
{
char[] delims = new char[] { ' ', ',' };
string[] names = TestNameParser.Parse(name1 + "," + name2);
Assert.AreEqual(2, names.Length);
Assert.AreEqual(name1.Trim(delims), names[0]);
Assert.AreEqual(name2.Trim(delims), names[1]);
}
}
}

Просмотреть файл

@ -0,0 +1,79 @@
// ***********************************************************************
// Copyright (c) 2016 Charlie Poole
//
// 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.
// ***********************************************************************
using System;
using NUnit.Framework;
namespace NUnit.Engine.Tests
{
public class TestSelectionParserTests
{
private TestSelectionParser _parser;
[SetUp]
public void CreateParser()
{
_parser = new TestSelectionParser();
}
[TestCase("cat=Urgent", "<cat>Urgent</cat>")]
[TestCase("cat==Urgent", "<cat>Urgent</cat>")]
[TestCase("cat!=Urgent", "<not><cat>Urgent</cat></not>")]
[TestCase("cat =~ Urgent", "<cat re='1'>Urgent</cat>")]
[TestCase("cat !~ Urgent", "<not><cat re='1'>Urgent</cat></not>")]
[TestCase("cat = Urgent || cat = High", "<or><cat>Urgent</cat><cat>High</cat></or>")]
[TestCase("Priority == High", "<prop name='Priority'>High</prop>")]
[TestCase("Priority != Urgent", "<not><prop name='Priority'>Urgent</prop></not>")]
[TestCase("Author =~ Jones", "<prop name='Author' re='1'>Jones</prop>")]
[TestCase("Author !~ Jones", "<not><prop name='Author' re='1'>Jones</prop></not>")]
[TestCase("name='SomeTest'", "<name>SomeTest</name>")]
[TestCase("method=TestMethod", "<method>TestMethod</method>")]
[TestCase("method=Test1||method=Test2||method=Test3", "<or><method>Test1</method><method>Test2</method><method>Test3</method></or>")]
[TestCase("test='My.Test.Fixture.Method(42)'", "<test>My.Test.Fixture.Method(42)</test>")]
[TestCase("test='My.Test.Fixture.Method(\"xyz\")'", "<test>My.Test.Fixture.Method(&quot;xyz&quot;)</test>")]
[TestCase("test='My.Test.Fixture.Method(\"abc\\'s\")'", "<test>My.Test.Fixture.Method(&quot;abc&apos;s&quot;)</test>")]
[TestCase("test='My.Test.Fixture.Method(\"x&y&z\")'", "<test>My.Test.Fixture.Method(&quot;x&amp;y&amp;z&quot;)</test>")]
[TestCase("test='My.Test.Fixture.Method(\"<xyz>\")'", "<test>My.Test.Fixture.Method(&quot;&lt;xyz&gt;&quot;)</test>")]
[TestCase("cat==Urgent && test=='My.Tests'", "<and><cat>Urgent</cat><test>My.Tests</test></and>")]
[TestCase("cat==Urgent and test=='My.Tests'", "<and><cat>Urgent</cat><test>My.Tests</test></and>")]
[TestCase("cat==Urgent || test=='My.Tests'", "<or><cat>Urgent</cat><test>My.Tests</test></or>")]
[TestCase("cat==Urgent or test=='My.Tests'", "<or><cat>Urgent</cat><test>My.Tests</test></or>")]
[TestCase("cat==Urgent || test=='My.Tests' && cat == high", "<or><cat>Urgent</cat><and><test>My.Tests</test><cat>high</cat></and></or>")]
[TestCase("cat==Urgent && test=='My.Tests' || cat == high", "<or><and><cat>Urgent</cat><test>My.Tests</test></and><cat>high</cat></or>")]
[TestCase("cat==Urgent && (test=='My.Tests' || cat == high)", "<and><cat>Urgent</cat><or><test>My.Tests</test><cat>high</cat></or></and>")]
[TestCase("cat==Urgent && !(test=='My.Tests' || cat == high)", "<and><cat>Urgent</cat><not><or><test>My.Tests</test><cat>high</cat></or></not></and>")]
public void TestParser(string input, string output)
{
Assert.That(_parser.Parse(input), Is.EqualTo(output));
}
[TestCase(null, typeof(ArgumentNullException))]
[TestCase("", typeof(TestSelectionParserException))]
[TestCase(" ", typeof(TestSelectionParserException))]
[TestCase(" \t\t ", typeof(TestSelectionParserException))]
public void TestParser_InvalidInput(string input, Type type)
{
Assert.That(() => _parser.Parse(input), Throws.TypeOf(type));
}
}
}

Просмотреть файл

@ -0,0 +1,162 @@
// ***********************************************************************
// Copyright (c) 2016 Charlie Poole
//
// 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.
// ***********************************************************************
using NUnit.Framework;
namespace NUnit.Engine.Tests
{
public class TokenizerTests
{
[Test]
public void NullInputThrowsException()
{
Assert.That(() => new Tokenizer(null), Throws.ArgumentNullException);
}
[Test]
public void BlankStringReturnsEof()
{
var tokenizer = new Tokenizer(" ");
Assert.That(tokenizer.NextToken(), Is.EqualTo(new Token(TokenKind.Eof)), "First Call");
Assert.That(tokenizer.NextToken(), Is.EqualTo(new Token(TokenKind.Eof)), "Second Call");
Assert.That(tokenizer.NextToken(), Is.EqualTo(new Token(TokenKind.Eof)), "Third Call");
}
[Test]
public void IdentifierTokens()
{
var tokenizer = new Tokenizer(" Identifiers x abc123 a1x ");
Assert.That(tokenizer.NextToken(), Is.EqualTo(new Token(TokenKind.Word, "Identifiers")));
Assert.That(tokenizer.NextToken(), Is.EqualTo(new Token(TokenKind.Word, "x")));
Assert.That(tokenizer.NextToken(), Is.EqualTo(new Token(TokenKind.Word, "abc123")));
Assert.That(tokenizer.NextToken(), Is.EqualTo(new Token(TokenKind.Word, "a1x")));
Assert.That(tokenizer.NextToken(), Is.EqualTo(new Token(TokenKind.Eof)));
}
[Test]
public void WordsInUnicode()
{
var tokenizer = new Tokenizer("method == Здравствуйте");
Assert.That(tokenizer.NextToken(), Is.EqualTo(new Token(TokenKind.Word, "method")));
Assert.That(tokenizer.NextToken(), Is.EqualTo(new Token(TokenKind.Symbol, "==")));
Assert.That(tokenizer.NextToken(), Is.EqualTo(new Token(TokenKind.Word, "Здравствуйте")));
Assert.That(tokenizer.NextToken(), Is.EqualTo(new Token(TokenKind.Eof)));
}
[Test]
public void StringWithDoubleQuotes()
{
var tokenizer = new Tokenizer("\"string at start\" \"may contain ' char\" \"string at end\"");
Assert.That(tokenizer.NextToken(), Is.EqualTo(new Token(TokenKind.String, "string at start")));
Assert.That(tokenizer.NextToken(), Is.EqualTo(new Token(TokenKind.String, "may contain ' char")));
Assert.That(tokenizer.NextToken(), Is.EqualTo(new Token(TokenKind.String, "string at end")));
Assert.That(tokenizer.NextToken(), Is.EqualTo(new Token(TokenKind.Eof)));
}
[Test]
public void StringWithSingleQuotes()
{
var tokenizer = new Tokenizer("'string at start' 'may contain \" char' 'string at end'");
Assert.That(tokenizer.NextToken(), Is.EqualTo(new Token(TokenKind.String, "string at start")));
Assert.That(tokenizer.NextToken(), Is.EqualTo(new Token(TokenKind.String, "may contain \" char")));
Assert.That(tokenizer.NextToken(), Is.EqualTo(new Token(TokenKind.String, "string at end")));
Assert.That(tokenizer.NextToken(), Is.EqualTo(new Token(TokenKind.Eof)));
}
[Test]
public void StringWithSlashes()
{
var tokenizer = new Tokenizer("/string at start/ /may contain \" char/ /string at end/");
Assert.That(tokenizer.NextToken(), Is.EqualTo(new Token(TokenKind.String, "string at start")));
Assert.That(tokenizer.NextToken(), Is.EqualTo(new Token(TokenKind.String, "may contain \" char")));
Assert.That(tokenizer.NextToken(), Is.EqualTo(new Token(TokenKind.String, "string at end")));
Assert.That(tokenizer.NextToken(), Is.EqualTo(new Token(TokenKind.Eof)));
}
[Test]
public void StringsMayContainEscapedQuoteChar()
{
var tokenizer = new Tokenizer("/abc\\/xyz/ 'abc\\'xyz' \"abc\\\"xyz\"");
Assert.That(tokenizer.NextToken(), Is.EqualTo(new Token(TokenKind.String, "abc/xyz")));
Assert.That(tokenizer.NextToken(), Is.EqualTo(new Token(TokenKind.String, "abc'xyz")));
Assert.That(tokenizer.NextToken(), Is.EqualTo(new Token(TokenKind.String, "abc\"xyz")));
Assert.That(tokenizer.NextToken(), Is.EqualTo(new Token(TokenKind.Eof)));
}
[Test]
public void SymbolTokens_SingleChar()
{
var tokenizer = new Tokenizer("=!&|()");
Assert.That(tokenizer.NextToken(), Is.EqualTo(new Token(TokenKind.Symbol, "=")));
Assert.That(tokenizer.NextToken(), Is.EqualTo(new Token(TokenKind.Symbol, "!")));
Assert.That(tokenizer.NextToken(), Is.EqualTo(new Token(TokenKind.Symbol, "&")));
Assert.That(tokenizer.NextToken(), Is.EqualTo(new Token(TokenKind.Symbol, "|")));
Assert.That(tokenizer.NextToken(), Is.EqualTo(new Token(TokenKind.Symbol, "(")));
Assert.That(tokenizer.NextToken(), Is.EqualTo(new Token(TokenKind.Symbol, ")")));
Assert.That(tokenizer.NextToken(), Is.EqualTo(new Token(TokenKind.Eof)));
}
[Test]
public void SymbolTokens_DoubleChar()
{
var tokenizer = new Tokenizer("==&&||!==~!~");
Assert.That(tokenizer.NextToken(), Is.EqualTo(new Token(TokenKind.Symbol, "==")));
Assert.That(tokenizer.NextToken(), Is.EqualTo(new Token(TokenKind.Symbol, "&&")));
Assert.That(tokenizer.NextToken(), Is.EqualTo(new Token(TokenKind.Symbol, "||")));
Assert.That(tokenizer.NextToken(), Is.EqualTo(new Token(TokenKind.Symbol, "!=")));
Assert.That(tokenizer.NextToken(), Is.EqualTo(new Token(TokenKind.Symbol, "=~")));
Assert.That(tokenizer.NextToken(), Is.EqualTo(new Token(TokenKind.Symbol, "!~")));
Assert.That(tokenizer.NextToken(), Is.EqualTo(new Token(TokenKind.Eof)));
}
[Test]
public void MixedTokens_Simple()
{
var tokenizer = new Tokenizer("id=123");
Assert.That(tokenizer.NextToken(), Is.EqualTo(new Token(TokenKind.Word, "id")));
Assert.That(tokenizer.NextToken(), Is.EqualTo(new Token(TokenKind.Symbol, "=")));
Assert.That(tokenizer.NextToken(), Is.EqualTo(new Token(TokenKind.Word, "123")));
Assert.That(tokenizer.NextToken(), Is.EqualTo(new Token(TokenKind.Eof)));
}
[Test]
public void MixedTokens_Complex()
{
var tokenizer = new Tokenizer("name =~ '*DataBase*' && (category = Urgent || Priority = High)");
Assert.That(tokenizer.NextToken(), Is.EqualTo(new Token(TokenKind.Word, "name")));
Assert.That(tokenizer.NextToken(), Is.EqualTo(new Token(TokenKind.Symbol, "=~")));
Assert.That(tokenizer.NextToken(), Is.EqualTo(new Token(TokenKind.String, "*DataBase*")));
Assert.That(tokenizer.NextToken(), Is.EqualTo(new Token(TokenKind.Symbol, "&&")));
Assert.That(tokenizer.NextToken(), Is.EqualTo(new Token(TokenKind.Symbol, "(")));
Assert.That(tokenizer.NextToken(), Is.EqualTo(new Token(TokenKind.Word, "category")));
Assert.That(tokenizer.NextToken(), Is.EqualTo(new Token(TokenKind.Symbol, "=")));
Assert.That(tokenizer.NextToken(), Is.EqualTo(new Token(TokenKind.Word, "Urgent")));
Assert.That(tokenizer.NextToken(), Is.EqualTo(new Token(TokenKind.Symbol, "||")));
Assert.That(tokenizer.NextToken(), Is.EqualTo(new Token(TokenKind.Word, "Priority")));
Assert.That(tokenizer.NextToken(), Is.EqualTo(new Token(TokenKind.Symbol, "=")));
Assert.That(tokenizer.NextToken(), Is.EqualTo(new Token(TokenKind.Word, "High")));
Assert.That(tokenizer.NextToken(), Is.EqualTo(new Token(TokenKind.Symbol, ")")));
Assert.That(tokenizer.NextToken(), Is.EqualTo(new Token(TokenKind.Eof)));
}
}
}

Просмотреть файл

@ -0,0 +1,146 @@
// ***********************************************************************
// Copyright (c) 2016 Charlie Poole
//
// 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.
// ***********************************************************************
using System.Reflection;
using NUnit.Framework;
namespace NUnit.Engine.Tests.Compatibility
{
[TestFixture]
public class AttributeHelperTests
{
[Test]
public void CanGetAttributesOnAssemblies()
{
var assembly = typeof(AttributeHelperTests).GetTypeInfo().Assembly;
Assert.That(assembly, Is.Not.Null);
var attr = AttributeHelper.GetCustomAttributes(assembly, typeof(AssemblyCompanyAttribute), true);
Assert.That(attr, Is.Not.Null);
Assert.That(attr.Length, Is.GreaterThanOrEqualTo(1));
}
[Test]
public void CanGetAttributesOnClasses()
{
var type = typeof(A);
Assert.That(type, Is.Not.Null);
var attr = AttributeHelper.GetCustomAttributes(type, typeof(CategoryAttribute), true);
Assert.That(attr, Is.Not.Null);
Assert.That(attr.Length, Is.EqualTo(1));
}
[Test]
public void CanGetAttributesOnDerivedClasses()
{
var type = typeof(B);
Assert.That(type, Is.Not.Null);
var attr = AttributeHelper.GetCustomAttributes(type, typeof(CategoryAttribute), true);
Assert.That(attr, Is.Not.Null);
Assert.That(attr.Length, Is.EqualTo(1));
}
[Test]
public void DoesNotGetAttributesOnDerivedClassesWhenInheritedIsFalse()
{
var type = typeof(B);
Assert.That(type, Is.Not.Null);
var attr = AttributeHelper.GetCustomAttributes(type, typeof(CategoryAttribute), false);
Assert.That(attr, Is.Not.Null);
Assert.That(attr.Length, Is.EqualTo(0));
}
[Test]
public void CanGetAttributesOnMethods()
{
var type = typeof(A);
Assert.That(type, Is.Not.Null);
var method = type.GetMethod("Add");
Assert.That(method, Is.Not.Null);
var attr = AttributeHelper.GetCustomAttributes(method, typeof(AuthorAttribute), true);
Assert.That(attr, Is.Not.Null);
Assert.That(attr.Length, Is.EqualTo(1));
}
[Test]
public void CanGetAttributesOnProperties()
{
var type = typeof(A);
Assert.That(type, Is.Not.Null);
var property = type.GetProperty("MyProperty");
Assert.That(property, Is.Not.Null);
var attr = AttributeHelper.GetCustomAttributes(property, typeof(DatapointSourceAttribute), true);
Assert.That(attr, Is.Not.Null);
Assert.That(attr.Length, Is.EqualTo(1));
}
[Test]
public void CanGetAttributesOnFields()
{
var type = typeof(A);
Assert.That(type, Is.Not.Null);
var field = type.GetField("field");
Assert.That(field, Is.Not.Null);
var attr = AttributeHelper.GetCustomAttributes(field, typeof(DatapointAttribute), true);
Assert.That(attr, Is.Not.Null);
Assert.That(attr.Length, Is.EqualTo(1));
}
[Test]
public void CanGetAttributesOnParameters()
{
var type = typeof(A);
Assert.That(type, Is.Not.Null);
var method = type.GetMethod("Add");
Assert.That(method, Is.Not.Null);
ParameterInfo[] param = method.GetParameters();
Assert.That(param, Is.Not.Null);
Assert.That(param.Length, Is.EqualTo(2));
foreach (var p in param)
{
var attr = AttributeHelper.GetCustomAttributes(p, typeof(RandomAttribute), true);
Assert.That(attr, Is.Not.Null);
Assert.That(attr.Length, Is.EqualTo(1));
}
}
[Category("A Category")]
class A
{
[Author("John Doe")]
public int Add([Random(1)]int x, [Random(1)]int y)
{
return x + y;
}
[DatapointSource]
public int MyProperty { get; set; }
[Datapoint]
public int field = 1;
}
class B : A
{
}
}
}

Просмотреть файл

@ -0,0 +1,333 @@
// ***********************************************************************
// Copyright (c) 2016 Charlie Poole
//
// 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.
// ***********************************************************************
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
using NUnit.Framework;
namespace NUnit.Engine.Tests.Compatibility
{
/// <summary>
/// A series of unit tests to ensure that the type extensions in the portable
/// framework behave the same as their counterparts in the full framework
/// </summary>
[TestFixture]
public class ReflectionExtensionsTests
{
[Test]
public void CanCallTypeInfoOnAllPlatforms()
{
var result = typeof(Object).GetTypeInfo();
Assert.That(result, Is.Not.Null);
}
[Test]
public void CanGetGenericArguments()
{
var result = typeof(GenericTestClass<string, DateTime>).GetGenericArguments();
Assert.That(result.Length, Is.EqualTo(2));
Assert.That(result[0], Is.EqualTo(typeof(string)));
Assert.That(result[1], Is.EqualTo(typeof(DateTime)));
}
[Test]
public void CanGetConstructors()
{
var result = typeof(DerivedTestClass).GetConstructors();
Assert.That(result.Length, Is.EqualTo(3));
foreach (var ctor in result)
{
Assert.That(ctor.IsStatic, Is.False);
Assert.That(ctor.IsPublic, Is.True);
}
}
[TestCase(typeof(string))]
[TestCase(typeof(double))]
[TestCase(typeof(int))]
public void CanGetContructorWithParams(Type paramType)
{
var result = typeof(DerivedTestClass).GetConstructor(new[] { paramType });
Assert.That(result, Is.Not.Null);
}
[Test]
public void CanGetGenericConstructor()
{
var result = typeof(GenericTestClass<double, double>)
.GetConstructor(new[] { typeof(double), typeof(int) });
Assert.That(result, Is.Not.Null);
}
[Test]
public void IsAssignableFromTest()
{
bool pass = typeof(BaseTestClass).IsAssignableFrom(typeof(DerivedTestClass));
bool fail = typeof(DerivedTestClass).IsAssignableFrom(typeof(BaseTestClass));
Assert.That(pass, Is.True);
Assert.That(fail, Is.False);
}
[Test]
public void IsInstanceOfTypeTest()
{
var baseClass = new BaseTestClass();
var derivedClass = new DerivedTestClass();
Assert.That(typeof(BaseTestClass).IsInstanceOfType(baseClass), Is.True);
Assert.That(typeof(BaseTestClass).IsInstanceOfType(derivedClass), Is.True);
Assert.That(typeof(DerivedTestClass).IsInstanceOfType(derivedClass), Is.True);
Assert.That(typeof(DerivedTestClass).IsInstanceOfType(baseClass), Is.False);
Assert.That(typeof(DerivedTestClass).IsInstanceOfType(null), Is.False);
}
[TestCase(typeof(BaseTestClass), typeof(IDisposable))]
[TestCase(typeof(DerivedTestClass), typeof(IDisposable))]
[TestCase(typeof(List<int>), typeof(IList<int>))]
[TestCase(typeof(List<int>), typeof(IEnumerable<int>))]
public void CanGetInterfaces(Type type, Type @interface)
{
var result = type.GetInterfaces();
Assert.That(result, Is.Not.Null);
Assert.That(result, Does.Contain(@interface));
}
[TestCase(typeof(BaseTestClass), "Name")]
[TestCase(typeof(BaseTestClass), "StaticString")]
[TestCase(typeof(BaseTestClass), "Protected")]
[TestCase(typeof(BaseTestClass), "Dispose")]
[TestCase(typeof(BaseTestClass), "Private")]
[TestCase(typeof(DerivedTestClass), "Name")]
[TestCase(typeof(DerivedTestClass), "Protected")]
[TestCase(typeof(DerivedTestClass), "Dispose")]
public void CanGetMember(Type type, string name)
{
var result = type.GetMember(name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance | BindingFlags.FlattenHierarchy);
Assert.That(result, Is.Not.Null);
Assert.That(result.Length, Is.EqualTo(1));
}
[Test]
public void GetStaticMemberOnBaseClass()
{
var result = typeof(DerivedTestClass).GetMember("StaticString", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance | BindingFlags.FlattenHierarchy);
Assert.That(result, Is.Not.Null);
Assert.That(result.Length, Is.GreaterThan(0));
}
[Test]
public void CanGetPublicField()
{
var result = typeof(DerivedTestClass).GetField("_public");
Assert.That(result, Is.Not.Null);
}
[Test]
public void DoesNotGetPrivateField()
{
var result = typeof(DerivedTestClass).GetField("_private");
Assert.That(result, Is.Null);
}
[TestCase(typeof(BaseTestClass), "Name")]
[TestCase(typeof(DerivedTestClass), "Name")]
[TestCase(typeof(BaseTestClass), "StaticString")]
public void CanGetProperty(Type type, string name)
{
var result = type.GetProperty(name);
Assert.That(result, Is.Not.Null);
}
[Test]
public void DoesNotGetStaticPropertyOnBase()
{
var result = typeof(DerivedTestClass).GetProperty("StaticString");
Assert.That(result, Is.Null);
}
[TestCase(typeof(BaseTestClass), "Name", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, true)]
[TestCase(typeof(DerivedTestClass), "Name", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, true)]
[TestCase(typeof(BaseTestClass), "Private", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, true)]
[TestCase(typeof(BaseTestClass), "StaticString", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, false)]
[TestCase(typeof(DerivedTestClass), "StaticString", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, false)]
[TestCase(typeof(BaseTestClass), "Name", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static, false)]
[TestCase(typeof(DerivedTestClass), "Name", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static, false)]
[TestCase(typeof(BaseTestClass), "Private", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static, false)]
[TestCase(typeof(DerivedTestClass), "Private", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static, false)]
[TestCase(typeof(BaseTestClass), "StaticString", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static, true)]
[TestCase(typeof(DerivedTestClass), "StaticString", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static, false)]
[TestCase(typeof(BaseTestClass), "Name", BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance, true)]
[TestCase(typeof(DerivedTestClass), "Name", BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance, true)]
[TestCase(typeof(BaseTestClass), "Private", BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance, false)]
[TestCase(typeof(DerivedTestClass), "Private", BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance, false)]
[TestCase(typeof(BaseTestClass), "StaticString", BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance, true)]
[TestCase(typeof(DerivedTestClass), "StaticString", BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance, false)]
[TestCase(typeof(BaseTestClass), "Name", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance, false)]
[TestCase(typeof(DerivedTestClass), "Name", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance, false)]
[TestCase(typeof(BaseTestClass), "Private", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance, true)]
[TestCase(typeof(BaseTestClass), "StaticString", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance, false)]
[TestCase(typeof(DerivedTestClass), "StaticString", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance, false)]
[TestCase(typeof(BaseTestClass), "PubPriv", BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance, true)]
[TestCase(typeof(DerivedTestClass), "PubPriv", BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance, true)]
[TestCase(typeof(BaseTestClass), "PubPriv", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance, false)]
[TestCase(typeof(DerivedTestClass), "PubPriv", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance, false)]
public void CanGetPropertyWithBindingFlags(Type type, string name, BindingFlags flags, bool shouldFind)
{
var result = type.GetProperty(name, flags);
Assert.AreEqual(shouldFind, result != null);
}
[TestCase(typeof(BaseTestClass), "Dispose", true)]
[TestCase(typeof(DerivedTestClass), "Dispose", true)]
[TestCase(typeof(BaseTestClass), "Goodbye", false)]
[TestCase(typeof(DerivedTestClass), "Goodbye", false)]
public void CanGetMethodByName(Type type, string name, bool shouldFind)
{
var result = type.GetMethod(name);
Assert.AreEqual(shouldFind, result != null);
}
[TestCase(typeof(BaseTestClass), "Hello", new Type[] { }, true)]
[TestCase(typeof(DerivedTestClass), "Hello", new Type[] { }, true)]
[TestCase(typeof(BaseTestClass), "Hello", new Type[] { typeof(string) }, true)]
[TestCase(typeof(DerivedTestClass), "Hello", new Type[] { typeof(string) }, true)]
[TestCase(typeof(BaseTestClass), "Goodbye", new Type[] { typeof(double) }, false)]
[TestCase(typeof(DerivedTestClass), "Goodbye", new Type[] { typeof(int) }, false)]
public void CanGetMethodByNameAndArgs(Type type, string name, Type[] args, bool shouldFind)
{
var result = type.GetMethod(name, args);
Assert.AreEqual(shouldFind, result != null);
}
[TestCase(typeof(BaseTestClass), "Dispose", BindingFlags.Public | BindingFlags.Instance, true)]
[TestCase(typeof(DerivedTestClass), "Dispose", BindingFlags.Public | BindingFlags.Instance, true)]
[TestCase(typeof(BaseTestClass), "Dispose", BindingFlags.Public | BindingFlags.Instance, true)]
[TestCase(typeof(DerivedTestClass), "Dispose", BindingFlags.Public | BindingFlags.Instance, true)]
[TestCase(typeof(BaseTestClass), "StaticMethod", BindingFlags.Public | BindingFlags.Static, true)]
[TestCase(typeof(DerivedTestClass), "StaticMethod", BindingFlags.Public | BindingFlags.Static, false)]
[TestCase(typeof(BaseTestClass), "Goodbye", BindingFlags.NonPublic | BindingFlags.Instance, true)]
public void CanGetMethodByNameAndBindingFlags(Type type, string name, BindingFlags flags, bool shouldFind)
{
var result = type.GetMethod(name, flags);
Assert.AreEqual(shouldFind, result != null);
}
public void CanGetStaticMethodsOnBase(BindingFlags flags)
{
var result = typeof(DerivedTestClass).GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy);
foreach (var info in result)
{
if (info.Name == "StaticMethod")
Assert.Pass();
}
Assert.Fail("Did not find StaticMethod on the base class");
}
[TestCase(BindingFlags.Static)]
[TestCase(BindingFlags.FlattenHierarchy)]
[TestCase(BindingFlags.Default)]
public void DoesNotFindStaticMethodsOnBase(BindingFlags flags)
{
var result = typeof(DerivedTestClass).GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | flags);
foreach (var info in result)
{
if (info.Name == "StaticMethod")
Assert.Fail("Should not have found StaticMethod on the base class");
}
}
[TestCase("Name", false, true)]
[TestCase("Name", true, true)]
[TestCase("Private", false, false)]
[TestCase("Private", true, true)]
public void CanGetGetMethod(string name, bool nonPublic, bool shouldFind)
{
var pinfo = typeof(BaseTestClass).GetProperty(name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
Assert.That(pinfo, Is.Not.Null);
var minfo = pinfo.GetGetMethod(nonPublic);
Assert.That(minfo != null, Is.EqualTo(shouldFind));
}
}
public class BaseTestClass : IDisposable
{
public static string StaticString { get; set; }
protected string Protected { get; set; }
public string Name { get; set; }
private string Private { get; set; }
public string PubPriv { get; private set; }
public BaseTestClass() : this("Joe") { }
public BaseTestClass(string name) { Name = name; }
public virtual void Hello() { }
public virtual void Hello(string msg) { }
public static void StaticMethod() { }
private void Goodbye(double d) { }
public void Dispose() { }
}
public class DerivedTestClass : BaseTestClass
{
#pragma warning disable 0169
private string _private;
#pragma warning restore
public string _public;
static DerivedTestClass() { StaticString = "static"; }
public DerivedTestClass() : this("Rob") { }
public DerivedTestClass(string name) : base(name) { }
public DerivedTestClass(double d) : this(d.ToString()) { }
private DerivedTestClass(StringBuilder name) : this(name.ToString()) { }
public override void Hello() { }
public override void Hello(string msg) { }
}
public class GenericTestClass<T1, T2>
{
public T1 PropertyOne { get; set; }
public T2 PropertyTwo { get; set; }
public GenericTestClass(T1 one, T2 two)
{
PropertyOne = one;
PropertyTwo = two;
}
}
}

Просмотреть файл

@ -0,0 +1,107 @@
// ***********************************************************************
// Copyright (c) 2016 Charlie Poole
//
// 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.
// ***********************************************************************
using NUnit.Framework;
namespace NUnit.Engine.Tests.Services
{
public class TestFilterBuilderTests
{
TestFilterBuilder builder;
[SetUp]
public void CreateBuilder()
{
this.builder = new TestFilterBuilder();
}
[Test]
public void EmptyFilter()
{
TestFilter filter = builder.GetFilter();
Assert.That(filter.Text, Is.EqualTo("<filter></filter>"));
}
[Test]
public void OneTestSelected()
{
builder.AddTest("My.Test.Name");
TestFilter filter = builder.GetFilter();
Assert.That(filter.Text, Is.EqualTo(
"<filter><test>My.Test.Name</test></filter>"));
}
[Test]
public void OneTestSelected_XmlEscape()
{
builder.AddTest("My.Test.Name<T>(\"abc\")");
TestFilter filter = builder.GetFilter();
Assert.That(filter.Text, Is.EqualTo(
"<filter><test>My.Test.Name&lt;T&gt;(&quot;abc&quot;)</test></filter>"));
}
[Test]
public void ThreeTestsSelected()
{
builder.AddTest("My.First.Test");
builder.AddTest("My.Second.Test");
builder.AddTest("My.Third.Test");
TestFilter filter = builder.GetFilter();
Assert.That(filter.Text, Is.EqualTo(
"<filter><or><test>My.First.Test</test><test>My.Second.Test</test><test>My.Third.Test</test></or></filter>"));
}
[Test]
public void WhereClause()
{
builder.SelectWhere("cat==Dummy");
TestFilter filter = builder.GetFilter();
Assert.That(filter.Text, Is.EqualTo("<filter><cat>Dummy</cat></filter>"));
}
[Test]
public void WhereClause_XmlEscape()
{
builder.SelectWhere("test=='My.Test.Name<T>(\"abc\")'");
TestFilter filter = builder.GetFilter();
Assert.That(filter.Text, Is.EqualTo(
"<filter><test>My.Test.Name&lt;T&gt;(&quot;abc&quot;)</test></filter>"));
}
[Test]
public void OneTestAndWhereClause()
{
builder.AddTest("My.Test.Name");
builder.SelectWhere("cat != Slow");
TestFilter filter = builder.GetFilter();
Assert.That(filter.Text, Is.EqualTo(
"<filter><test>My.Test.Name</test><not><cat>Slow</cat></not></filter>"));
}
}
}

Просмотреть файл

@ -18,7 +18,8 @@
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet"
"netstandard1.3",
"portable-net45+win8"
],
"dependencies": {
"Microsoft.NETCore.App": {
@ -29,7 +30,7 @@
"System.Console": "4.0.0"
}
},
"net45": {}
"net451": {}
},
"dependencies": {