Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
rprouse committed Apr 28, 2017
1 parent 983dceb commit d345c72
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 32 deletions.
8 changes: 3 additions & 5 deletions src/NUnitTestAdapter/AdapterSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,13 @@ public void Load(IDiscoveryContext context)
if (context == null)
throw new ArgumentNullException("context", "Load called with null context");

Load(context.RunSettings.SettingsXml);
Load(context?.RunSettings?.SettingsXml);
}

public void Load(string settingsXml)
{
if (settingsXml == null)
throw new ArgumentNullException("settingsXml", "Load called with null XML string");
if (settingsXml == string.Empty)
throw new ArgumentException("settingsXml", "Load called with empty XML string");
if (string.IsNullOrEmpty(settingsXml))
settingsXml = "<RunSettings />";

// Visual Studio already gives a good error message if the .runsettings
// file is poorly formed, so we don't need to do anything more.
Expand Down
20 changes: 5 additions & 15 deletions src/NUnitTestAdapterTests/AdapterSettingsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,12 @@ public void NullContextThrowsException()
Assert.That(() => _settings.Load((IDiscoveryContext)null), Throws.ArgumentNullException);
}

[Test]
public void NullStringThrowsException()
{
Assert.That(() => _settings.Load((string)null), Throws.ArgumentNullException);
}

[Test]
public void EmptyStringThrowsException()
{
Assert.That(() => _settings.Load(string.Empty), Throws.ArgumentException);
}

[Test]
public void DefaultSettings()
[TestCase(null)]
[TestCase("")]
[TestCase("<RunSettings />")]
public void DefaultSettings(string xml)
{
_settings.Load("<RunSettings/>");
_settings.Load(xml);
Assert.That(_settings.MaxCpuCount, Is.EqualTo(-1));
Assert.Null(_settings.ResultsDirectory);
Assert.Null(_settings.TargetFrameworkVersion);
Expand Down
13 changes: 6 additions & 7 deletions src/NUnitTestAdapterTests/Fakes/FakeDiscoveryContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,21 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ***********************************************************************

using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;

namespace NUnit.VisualStudio.TestAdapter.Tests.Fakes
{
class FakeDiscoveryContext : IDiscoveryContext
{
#region IDiscoveryContextMembers

IRunSettings IDiscoveryContext.RunSettings
public FakeDiscoveryContext(IRunSettings runSettings)
{
get { return new FakeRunSettings(); }
RunSettings = runSettings;
}

#region IDiscoveryContextMembers

public IRunSettings RunSettings { get; private set; }

#endregion
}
}
4 changes: 4 additions & 0 deletions src/NUnitTestAdapterTests/Fakes/FakeRunContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ namespace NUnit.VisualStudio.TestAdapter.Tests.Fakes
{
class FakeRunContext : FakeDiscoveryContext, IRunContext
{
public FakeRunContext() : base(new FakeRunSettings())
{
}

#region IRunContext Members

bool IRunContext.InIsolation
Expand Down
28 changes: 23 additions & 5 deletions src/NUnitTestAdapterTests/TestDiscoveryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,19 @@
namespace NUnit.VisualStudio.TestAdapter.Tests
{
using Fakes;
using System.Collections;

internal static class TestDiscoveryDataProvider
{
public static IEnumerable<IDiscoveryContext> TestDiscoveryData()
{
yield return new FakeDiscoveryContext(null);
yield return new FakeDiscoveryContext(new FakeRunSettings());
}
}

[Category("TestDiscovery")]
[TestFixtureSource(typeof(TestDiscoveryDataProvider), nameof(TestDiscoveryDataProvider.TestDiscoveryData))]
public class TestDiscoveryTests : ITestCaseDiscoverySink
{
static readonly string MockAssemblyPath =
Expand All @@ -43,6 +54,13 @@ public class TestDiscoveryTests : ITestCaseDiscoverySink

private static ITestDiscoverer nunittestDiscoverer;

private IDiscoveryContext _context;

public TestDiscoveryTests(IDiscoveryContext context)
{
_context = context;
}

[OneTimeSetUp]
public void LoadMockassembly()
{
Expand All @@ -57,7 +75,7 @@ public void LoadMockassembly()
nunittestDiscoverer = ((ITestDiscoverer)new NUnit3TestDiscoverer());
nunittestDiscoverer.DiscoverTests(
new[] { MockAssemblyPath},
new FakeDiscoveryContext(),
_context,
new MessageLoggerStub(),
this);
}
Expand Down Expand Up @@ -106,15 +124,15 @@ public class EmptyAssemblyDiscoveryTests : ITestCaseDiscoverySink
Path.Combine(TestContext.CurrentContext.TestDirectory, "empty-assembly.dll");

private static ITestDiscoverer nunittestDiscoverer;

[Test]
public void VerifyLoading()
[TestCaseSource(typeof(TestDiscoveryDataProvider), nameof(TestDiscoveryDataProvider.TestDiscoveryData))]
public void VerifyLoading(IDiscoveryContext context)
{
// Load the NUnit empty-assembly.dll once for this test
nunittestDiscoverer = ((ITestDiscoverer)new NUnit3TestDiscoverer());
nunittestDiscoverer.DiscoverTests(
new[] { EmptyAssemblyPath},
new FakeDiscoveryContext(),
context,
new MessageLoggerStub(),
this);
}
Expand Down

0 comments on commit d345c72

Please sign in to comment.