Skip to content

Commit

Permalink
Fix for AppDomain creation should honor runsettings (#427)
Browse files Browse the repository at this point in the history
* Fix for AppDomain creation should honor runsettings

* Adding UT

* PR comments
  • Loading branch information
jayaranigarg authored May 24, 2018
1 parent 1122663 commit c5184f9
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
@"<RunSettings>
<RunConfiguration>
<DisableAppDomain>True</DisableAppDomain>
</RunConfiguration>
</RunSettings>";

var location = typeof(TestSourceHost).Assembly.Location;
var mockRunSettings = new Mock<IRunSettings>();
mockRunSettings.Setup(rs => rs.SettingsXml).Returns(runSettingxml);

Mock<TestSourceHost> testSourceHost = new Mock<TestSourceHost>(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 =
@"<RunSettings>
<RunConfiguration>
<DisableAppDomain>False</DisableAppDomain>
</RunConfiguration>
</RunSettings>";

var location = typeof(TestSourceHost).Assembly.Location;
var mockRunSettings = new Mock<IRunSettings>();
mockRunSettings.Setup(rs => rs.SettingsXml).Returns(runSettingxml);

Mock<TestSourceHost> testSourceHost = new Mock<TestSourceHost>(location, mockRunSettings.Object, null) { CallBase = true };

try
{
// Act
testSourceHost.Object.SetupHost();
Assert.IsNotNull(testSourceHost.Object.AppDomain);
}
finally
{
testSourceHost.Object.Dispose();
}
}
}

public class DummyClass : MarshalByRefObject
Expand Down

0 comments on commit c5184f9

Please sign in to comment.