-
Notifications
You must be signed in to change notification settings - Fork 63
Expand file tree
/
Copy pathDirectoryAssemblyResolverTests.cs
More file actions
69 lines (58 loc) · 2.06 KB
/
DirectoryAssemblyResolverTests.cs
File metadata and controls
69 lines (58 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using System.Diagnostics;
using System.IO;
using Java.Interop.Tools.Cecil;
using Mono.Cecil;
using NUnit.Framework;
namespace Java.Interop.Tools.JavaCallableWrappersTests
{
[TestFixture]
public class DirectoryAssemblyResolverTests
{
static void Log (TraceLevel level, string message)
{
TestContext.Out.WriteLine ($"{level}: {message}");
if (level == TraceLevel.Error)
Assert.Fail (message);
}
static string assembly_path;
static string symbol_path;
[OneTimeSetUp]
public static void SetUp()
{
var assembly = typeof (DirectoryAssemblyResolverTests).Assembly;
assembly_path = Path.Combine (Path.GetTempPath (), Path.GetFileName (assembly.Location));
symbol_path = Path.ChangeExtension (assembly_path, ".pdb");
File.Copy (assembly.Location, assembly_path, overwrite: true);
File.Copy (Path.ChangeExtension (assembly.Location, ".pdb"), symbol_path, overwrite: true);
}
[OneTimeTearDown]
public static void TearDown ()
{
File.Delete (assembly_path);
File.Delete (symbol_path);
}
[Test]
public void LoadSymbols ([Values (true, false)] bool loadDebugSymbols, [Values (true, false)] bool readWrite)
{
using var resolver = new DirectoryAssemblyResolver (Log, loadDebugSymbols: loadDebugSymbols, new ReaderParameters {
ReadWrite = readWrite
});
var assembly = resolver.Load (assembly_path);
Assert.IsNotNull (assembly);
Assert.AreEqual (loadDebugSymbols, assembly.MainModule.HasSymbols);
}
[Test]
public void LoadSymbols_LockedPdb ([Values (true, false)] bool readWrite)
{
// Lock the PDB file exclusively so LoadSymbols will fail with IOException
using var lockStream = new FileStream (symbol_path, FileMode.Open, FileAccess.ReadWrite, FileShare.None);
using var resolver = new DirectoryAssemblyResolver (Log, loadDebugSymbols: true, new ReaderParameters {
ReadWrite = readWrite
});
// Should succeed by retrying without symbols instead of throwing
var assembly = resolver.Load (assembly_path);
Assert.IsNotNull (assembly);
Assert.IsFalse (assembly.MainModule.HasSymbols);
}
}
}