Is any way to make rhino.mocks
work in test project with .NET 6
platform?
I am always getting Exception, when the code below is called (under .NET 6 project).
Exception:
Method not found: 'System.Reflection.Emit.AssemblyBuilder System.AppDomain.DefineDynamicAssembly(System.Reflection.AssemblyName, System.Reflection.Emit.AssemblyBuilderAccess)'.'
Code:
public interface IFoo
{
void Go();
int Run();
}
[TestFixture]
public class UnixTest
{
private MockRepository _repo;
[SetUp]
public void Setup()
{
_repo = new MockRepository();
}
[Test]
public void Test()
{
var stub = _repo.StrictMock<IFoo>();
Assert.NotNull(stub);
}
}
update: So, the number of tests are using rhino was huge, so I had to discover the problem. The Exception is thrown by Castle.DynamicProxy logic at net6 runtime. And here is one way you can resolve the problem:
- Download sources of rhino-mocks
- Convert project files by tool dotnet-migrate-2019.exe
- Migrate all projects to .net framework v.4.6.2 platform (min version required by castle.core)
- The gist of the way: update all rhino mocks project external references (xunit, castle.core 5 etc)
- Sources modification is required to make the solution compile. Also, you will lose delegates stubbing, and remoting stubs (cross app domain stubbing). Actually, in our tests we don’t use both features, so it was not problem for me. As the result, you can create Test project with net6.0 or net6.0-windows platform. Add explicit links to compiled rhino library and all will work fine. Under windows system of course.
PS: If my company allows me, I will upload modified solution to github later.
PPS: Rhino tests passed, but there is «between test runs» dependencies. So, if you run all tests together some of them may randomly failed, but the problem disappeared if you run failed test separately.