-
Notifications
You must be signed in to change notification settings - Fork 0
/
LibraryTests.cs
43 lines (36 loc) · 1.66 KB
/
LibraryTests.cs
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
using LibraryUser;
using Nethermind.Test.Utils;
using TestInfluence;
using TestLibrary;
namespace TestLibraryUser
{
[TestFixture]
public class LibraryTests
{
[Test]
public void TestDafault()
{
var user = new UserOfTheLibrary();
Assert.Pass();
}
//Note that this test is as similar as possible to one above. And is representative to real use case
[Test]
public void TestWithUpdatedConstructor()
{
//Make LibraryToBeModified constructor add one to TestInjection counter. This creates new DLL.
InsertionFactory.ModifyTypeConstructor<LibraryToBeModified>(typeof(TestInjection), nameof(TestInjection.AddCounter));
InsertionFactory.ModifyTypeConstructor<UserOfTheLibrary>(typeof(TestInjection), nameof(TestInjection.AddCounter));
//Create a new AssemblyLoadContext to load the modified libraries respecting new DLLs from InsertionFactory
AssemblyLoadContextThatUsesInsertionFactoryLibs alc = new();
//Get an assembly (note that Assembly with UserOfTheLibrary is dependent on the Assembly of LibraryToBeModified
var assembly = alc.LoadFromAssemblyName(typeof(UserOfTheLibrary).Assembly.GetName());
//Instantiate an item
var userType = assembly.GetType(typeof(UserOfTheLibrary).FullName);
object result = Activator.CreateInstance(userType);
var dbg = TestInjection.Counter;
//Check that modified dll actually worked
Assert.AreEqual(TestInjection.Counter, 3);
Assert.Pass();
}
}
}