diff --git a/src/Adapter/PlatformServices.Desktop/Services/DesktopTestSourceHost.cs b/src/Adapter/PlatformServices.Desktop/Services/DesktopTestSourceHost.cs index dc6c4d3ecc..b238127b38 100644 --- a/src/Adapter/PlatformServices.Desktop/Services/DesktopTestSourceHost.cs +++ b/src/Adapter/PlatformServices.Desktop/Services/DesktopTestSourceHost.cs @@ -73,7 +73,7 @@ internal TestSourceHost(string sourceFileName, IRunSettings runSettings, IFramew this.SetContext(sourceFileName); // Set isAppDomainCreationDisabled flag - this.AppDomainCreationDisabledInRunSettings(); + this.isAppDomainCreationDisabled = (this.runSettings != null) && MSTestAdapterSettings.IsAppDomainCreationDisabled(this.runSettings.SettingsXml); } internal AppDomain AppDomain @@ -354,16 +354,6 @@ private void ResetContext() } } - private void AppDomainCreationDisabledInRunSettings() - { - if (this.runSettings != null && MSTestAdapterSettings.IsAppDomainCreationDisabled(this.runSettings.SettingsXml)) - { - this.isAppDomainCreationDisabled = true; - } - - this.isAppDomainCreationDisabled = false; - } - private void AddSearchDirectoriesSpecifiedInRunSettingsToAssemblyResolver(AssemblyResolver assemblyResolver, string baseDirectory) { // Check if user specified any adapter settings diff --git a/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Services/DesktopTestSourceHostTests.cs b/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Services/DesktopTestSourceHostTests.cs index 77a000d8a5..22af3fe0d8 100644 --- a/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Services/DesktopTestSourceHostTests.cs +++ b/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Services/DesktopTestSourceHostTests.cs @@ -263,6 +263,66 @@ public void DisposeShouldSetTestHostShutdownOnIssueWithAppDomainUnload() // Assert frameworkHandle.VerifySet(fh => fh.EnableShutdownAfterTestRun = true); } + + [TestMethod] + public void NoAppDomainShouldGetCreatedWhenDisableAppDomainIsSetToTrue() + { + // Arrange + DummyClass dummyclass = new DummyClass(); + string runSettingxml = + @" + + True + + "; + + var location = typeof(TestSourceHost).Assembly.Location; + var mockRunSettings = new Mock(); + mockRunSettings.Setup(rs => rs.SettingsXml).Returns(runSettingxml); + + Mock testSourceHost = new Mock(location, mockRunSettings.Object, null) { CallBase = true }; + + try + { + // Act + testSourceHost.Object.SetupHost(); + Assert.IsNull(testSourceHost.Object.AppDomain); + } + finally + { + testSourceHost.Object.Dispose(); + } + } + + [TestMethod] + public void AppDomainShouldGetCreatedWhenDisableAppDomainIsSetToFalse() + { + // Arrange + DummyClass dummyclass = new DummyClass(); + string runSettingxml = + @" + + False + + "; + + var location = typeof(TestSourceHost).Assembly.Location; + var mockRunSettings = new Mock(); + mockRunSettings.Setup(rs => rs.SettingsXml).Returns(runSettingxml); + + Mock testSourceHost = new Mock(location, mockRunSettings.Object, null) { CallBase = true }; + + try + { + // Act + testSourceHost.Object.SetupHost(); + Assert.IsNotNull(testSourceHost.Object.AppDomain); + } + finally + { + testSourceHost.Object.Dispose(); + } + } } public class DummyClass : MarshalByRefObject