-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #159 from skomis-mm/scanbin
- Loading branch information
Showing
4 changed files
with
134 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
test/Serilog.Settings.Configuration.Tests/DllScanningAssemblyFinderTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using System; | ||
using System.IO; | ||
|
||
using Xunit; | ||
|
||
using Serilog.Settings.Configuration.Assemblies; | ||
|
||
namespace Serilog.Settings.Configuration.Tests | ||
{ | ||
public class DllScanningAssemblyFinderTests : IDisposable | ||
{ | ||
const string BinDir1 = "bin1"; | ||
const string BinDir2 = "bin2"; | ||
const string BinDir3 = "bin3"; | ||
|
||
readonly string _privateBinPath; | ||
|
||
public DllScanningAssemblyFinderTests() | ||
{ | ||
var d1 = GetOrCreateDirectory(BinDir1); | ||
var d2 = GetOrCreateDirectory(BinDir2); | ||
var d3 = GetOrCreateDirectory(BinDir3); | ||
|
||
_privateBinPath = $"{d1.Name};{d2.FullName};{d3.Name}"; | ||
|
||
DirectoryInfo GetOrCreateDirectory(string name) | ||
=> Directory.Exists(name) ? new DirectoryInfo(name) : Directory.CreateDirectory(name); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
Directory.Delete(BinDir1, true); | ||
Directory.Delete(BinDir2, true); | ||
Directory.Delete(BinDir3, true); | ||
} | ||
|
||
[Fact] | ||
public void ShouldProbeCurrentDirectory() | ||
{ | ||
var assemblyNames = new DllScanningAssemblyFinder().FindAssembliesContainingName("testdummies"); | ||
Assert.Single(assemblyNames); | ||
} | ||
|
||
#if PRIVATE_BIN | ||
[Fact] | ||
public void ShouldProbePrivateBinPath() | ||
{ | ||
File.Copy("testdummies.dll", $"{BinDir1}/customSink1.dll", true); | ||
File.Copy("testdummies.dll", $"{BinDir2}/customSink2.dll", true); | ||
File.Copy("testdummies.dll", $"{BinDir3}/thirdpartydependency.dll", true); | ||
|
||
var ad = AppDomain.CreateDomain("serilog", null, | ||
new AppDomainSetup | ||
{ | ||
ApplicationBase = AppDomain.CurrentDomain.BaseDirectory, | ||
PrivateBinPath = _privateBinPath | ||
}); | ||
|
||
try | ||
{ | ||
ad.DoCallBack(DoTestInner); | ||
} | ||
finally | ||
{ | ||
AppDomain.Unload(ad); | ||
} | ||
|
||
void DoTestInner() | ||
{ | ||
var assemblyNames = new DllScanningAssemblyFinder().FindAssembliesContainingName("customSink"); | ||
Assert.Equal(2, assemblyNames.Count); | ||
} | ||
} | ||
#endif | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters