diff --git a/src/NUnitTestAdapter/AdapterSettings.cs b/src/NUnitTestAdapter/AdapterSettings.cs
index c1105ad1..1b5fb8ef 100644
--- a/src/NUnitTestAdapter/AdapterSettings.cs
+++ b/src/NUnitTestAdapter/AdapterSettings.cs
@@ -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 = "";
// Visual Studio already gives a good error message if the .runsettings
// file is poorly formed, so we don't need to do anything more.
diff --git a/src/NUnitTestAdapterTests/AdapterSettingsTests.cs b/src/NUnitTestAdapterTests/AdapterSettingsTests.cs
index 3957a816..50df5556 100644
--- a/src/NUnitTestAdapterTests/AdapterSettingsTests.cs
+++ b/src/NUnitTestAdapterTests/AdapterSettingsTests.cs
@@ -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("")]
+ public void DefaultSettings(string xml)
{
- _settings.Load("");
+ _settings.Load(xml);
Assert.That(_settings.MaxCpuCount, Is.EqualTo(-1));
Assert.Null(_settings.ResultsDirectory);
Assert.Null(_settings.TargetFrameworkVersion);
diff --git a/src/NUnitTestAdapterTests/Fakes/FakeDiscoveryContext.cs b/src/NUnitTestAdapterTests/Fakes/FakeDiscoveryContext.cs
index e7dd6086..abc12bd9 100644
--- a/src/NUnitTestAdapterTests/Fakes/FakeDiscoveryContext.cs
+++ b/src/NUnitTestAdapterTests/Fakes/FakeDiscoveryContext.cs
@@ -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
}
}
diff --git a/src/NUnitTestAdapterTests/Fakes/FakeRunContext.cs b/src/NUnitTestAdapterTests/Fakes/FakeRunContext.cs
index bded4669..22f1e0b6 100644
--- a/src/NUnitTestAdapterTests/Fakes/FakeRunContext.cs
+++ b/src/NUnitTestAdapterTests/Fakes/FakeRunContext.cs
@@ -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
diff --git a/src/NUnitTestAdapterTests/TestDiscoveryTests.cs b/src/NUnitTestAdapterTests/TestDiscoveryTests.cs
index 0cc3663a..72732a16 100644
--- a/src/NUnitTestAdapterTests/TestDiscoveryTests.cs
+++ b/src/NUnitTestAdapterTests/TestDiscoveryTests.cs
@@ -32,8 +32,19 @@
namespace NUnit.VisualStudio.TestAdapter.Tests
{
using Fakes;
+ using System.Collections;
+
+ internal static class TestDiscoveryDataProvider
+ {
+ public static IEnumerable 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 =
@@ -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()
{
@@ -57,7 +75,7 @@ public void LoadMockassembly()
nunittestDiscoverer = ((ITestDiscoverer)new NUnit3TestDiscoverer());
nunittestDiscoverer.DiscoverTests(
new[] { MockAssemblyPath},
- new FakeDiscoveryContext(),
+ _context,
new MessageLoggerStub(),
this);
}
@@ -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);
}