From 657071c9871d87a9925c2abf508099d238cc59b8 Mon Sep 17 00:00:00 2001 From: jagarg Date: Thu, 24 May 2018 14:05:48 +0530 Subject: [PATCH 1/3] Fix for AppDomain creation should honor runsettings --- .../Services/DesktopTestSourceHost.cs | 1 + .../Services/DesktopTestSourceHostTests.cs | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/src/Adapter/PlatformServices.Desktop/Services/DesktopTestSourceHost.cs b/src/Adapter/PlatformServices.Desktop/Services/DesktopTestSourceHost.cs index dc6c4d3ecc..ef2ae3e57e 100644 --- a/src/Adapter/PlatformServices.Desktop/Services/DesktopTestSourceHost.cs +++ b/src/Adapter/PlatformServices.Desktop/Services/DesktopTestSourceHost.cs @@ -359,6 +359,7 @@ private void AppDomainCreationDisabledInRunSettings() if (this.runSettings != null && MSTestAdapterSettings.IsAppDomainCreationDisabled(this.runSettings.SettingsXml)) { this.isAppDomainCreationDisabled = true; + return; } this.isAppDomainCreationDisabled = false; diff --git a/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Services/DesktopTestSourceHostTests.cs b/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Services/DesktopTestSourceHostTests.cs index 77a000d8a5..37d96b88de 100644 --- a/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Services/DesktopTestSourceHostTests.cs +++ b/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Services/DesktopTestSourceHostTests.cs @@ -263,6 +263,36 @@ 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 sourceHost = new Mock(location, mockRunSettings.Object, null) { CallBase = true }; + + try + { + // Act + sourceHost.Object.SetupHost(); + Assert.IsNull(sourceHost.Object.AppDomain); + } + finally + { + sourceHost.Object.Dispose(); + } + } } public class DummyClass : MarshalByRefObject From 3cc918b43ae2b7271cf05b141de9fdc0763a46de Mon Sep 17 00:00:00 2001 From: jagarg Date: Thu, 24 May 2018 14:17:58 +0530 Subject: [PATCH 2/3] Adding UT --- .../Services/DesktopTestSourceHostTests.cs | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Services/DesktopTestSourceHostTests.cs b/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Services/DesktopTestSourceHostTests.cs index 37d96b88de..48ce24c587 100644 --- a/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Services/DesktopTestSourceHostTests.cs +++ b/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Services/DesktopTestSourceHostTests.cs @@ -293,6 +293,36 @@ public void NoAppDomainShouldGetCreatedWhenDisableAppDomainIsSetToTrue() sourceHost.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 sourceHost = new Mock(location, mockRunSettings.Object, null) { CallBase = true }; + + try + { + // Act + sourceHost.Object.SetupHost(); + Assert.IsNotNull(sourceHost.Object.AppDomain); + } + finally + { + sourceHost.Object.Dispose(); + } + } } public class DummyClass : MarshalByRefObject From 0294b17cbe8079824fb3ac99d1c6e54a2db80025 Mon Sep 17 00:00:00 2001 From: jagarg Date: Thu, 24 May 2018 15:47:58 +0530 Subject: [PATCH 3/3] PR comments --- .../Services/DesktopTestSourceHost.cs | 13 +------------ .../Services/DesktopTestSourceHostTests.cs | 16 ++++++++-------- 2 files changed, 9 insertions(+), 20 deletions(-) diff --git a/src/Adapter/PlatformServices.Desktop/Services/DesktopTestSourceHost.cs b/src/Adapter/PlatformServices.Desktop/Services/DesktopTestSourceHost.cs index ef2ae3e57e..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,17 +354,6 @@ private void ResetContext() } } - private void AppDomainCreationDisabledInRunSettings() - { - if (this.runSettings != null && MSTestAdapterSettings.IsAppDomainCreationDisabled(this.runSettings.SettingsXml)) - { - this.isAppDomainCreationDisabled = true; - return; - } - - 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 48ce24c587..22af3fe0d8 100644 --- a/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Services/DesktopTestSourceHostTests.cs +++ b/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Services/DesktopTestSourceHostTests.cs @@ -280,17 +280,17 @@ public void NoAppDomainShouldGetCreatedWhenDisableAppDomainIsSetToTrue() var mockRunSettings = new Mock(); mockRunSettings.Setup(rs => rs.SettingsXml).Returns(runSettingxml); - Mock sourceHost = new Mock(location, mockRunSettings.Object, null) { CallBase = true }; + Mock testSourceHost = new Mock(location, mockRunSettings.Object, null) { CallBase = true }; try { // Act - sourceHost.Object.SetupHost(); - Assert.IsNull(sourceHost.Object.AppDomain); + testSourceHost.Object.SetupHost(); + Assert.IsNull(testSourceHost.Object.AppDomain); } finally { - sourceHost.Object.Dispose(); + testSourceHost.Object.Dispose(); } } @@ -310,17 +310,17 @@ public void AppDomainShouldGetCreatedWhenDisableAppDomainIsSetToFalse() var mockRunSettings = new Mock(); mockRunSettings.Setup(rs => rs.SettingsXml).Returns(runSettingxml); - Mock sourceHost = new Mock(location, mockRunSettings.Object, null) { CallBase = true }; + Mock testSourceHost = new Mock(location, mockRunSettings.Object, null) { CallBase = true }; try { // Act - sourceHost.Object.SetupHost(); - Assert.IsNotNull(sourceHost.Object.AppDomain); + testSourceHost.Object.SetupHost(); + Assert.IsNotNull(testSourceHost.Object.AppDomain); } finally { - sourceHost.Object.Dispose(); + testSourceHost.Object.Dispose(); } } }