Skip to content

Commit c5184f9

Browse files
authored
Fix for AppDomain creation should honor runsettings (#427)
* Fix for AppDomain creation should honor runsettings * Adding UT * PR comments
1 parent 1122663 commit c5184f9

File tree

2 files changed

+61
-11
lines changed

2 files changed

+61
-11
lines changed

src/Adapter/PlatformServices.Desktop/Services/DesktopTestSourceHost.cs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ internal TestSourceHost(string sourceFileName, IRunSettings runSettings, IFramew
7373
this.SetContext(sourceFileName);
7474

7575
// Set isAppDomainCreationDisabled flag
76-
this.AppDomainCreationDisabledInRunSettings();
76+
this.isAppDomainCreationDisabled = (this.runSettings != null) && MSTestAdapterSettings.IsAppDomainCreationDisabled(this.runSettings.SettingsXml);
7777
}
7878

7979
internal AppDomain AppDomain
@@ -354,16 +354,6 @@ private void ResetContext()
354354
}
355355
}
356356

357-
private void AppDomainCreationDisabledInRunSettings()
358-
{
359-
if (this.runSettings != null && MSTestAdapterSettings.IsAppDomainCreationDisabled(this.runSettings.SettingsXml))
360-
{
361-
this.isAppDomainCreationDisabled = true;
362-
}
363-
364-
this.isAppDomainCreationDisabled = false;
365-
}
366-
367357
private void AddSearchDirectoriesSpecifiedInRunSettingsToAssemblyResolver(AssemblyResolver assemblyResolver, string baseDirectory)
368358
{
369359
// Check if user specified any adapter settings

test/UnitTests/PlatformServices.Desktop.Unit.Tests/Services/DesktopTestSourceHostTests.cs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,66 @@ public void DisposeShouldSetTestHostShutdownOnIssueWithAppDomainUnload()
263263
// Assert
264264
frameworkHandle.VerifySet(fh => fh.EnableShutdownAfterTestRun = true);
265265
}
266+
267+
[TestMethod]
268+
public void NoAppDomainShouldGetCreatedWhenDisableAppDomainIsSetToTrue()
269+
{
270+
// Arrange
271+
DummyClass dummyclass = new DummyClass();
272+
string runSettingxml =
273+
@"<RunSettings>
274+
<RunConfiguration>
275+
<DisableAppDomain>True</DisableAppDomain>
276+
</RunConfiguration>
277+
</RunSettings>";
278+
279+
var location = typeof(TestSourceHost).Assembly.Location;
280+
var mockRunSettings = new Mock<IRunSettings>();
281+
mockRunSettings.Setup(rs => rs.SettingsXml).Returns(runSettingxml);
282+
283+
Mock<TestSourceHost> testSourceHost = new Mock<TestSourceHost>(location, mockRunSettings.Object, null) { CallBase = true };
284+
285+
try
286+
{
287+
// Act
288+
testSourceHost.Object.SetupHost();
289+
Assert.IsNull(testSourceHost.Object.AppDomain);
290+
}
291+
finally
292+
{
293+
testSourceHost.Object.Dispose();
294+
}
295+
}
296+
297+
[TestMethod]
298+
public void AppDomainShouldGetCreatedWhenDisableAppDomainIsSetToFalse()
299+
{
300+
// Arrange
301+
DummyClass dummyclass = new DummyClass();
302+
string runSettingxml =
303+
@"<RunSettings>
304+
<RunConfiguration>
305+
<DisableAppDomain>False</DisableAppDomain>
306+
</RunConfiguration>
307+
</RunSettings>";
308+
309+
var location = typeof(TestSourceHost).Assembly.Location;
310+
var mockRunSettings = new Mock<IRunSettings>();
311+
mockRunSettings.Setup(rs => rs.SettingsXml).Returns(runSettingxml);
312+
313+
Mock<TestSourceHost> testSourceHost = new Mock<TestSourceHost>(location, mockRunSettings.Object, null) { CallBase = true };
314+
315+
try
316+
{
317+
// Act
318+
testSourceHost.Object.SetupHost();
319+
Assert.IsNotNull(testSourceHost.Object.AppDomain);
320+
}
321+
finally
322+
{
323+
testSourceHost.Object.Dispose();
324+
}
325+
}
266326
}
267327

268328
public class DummyClass : MarshalByRefObject

0 commit comments

Comments
 (0)