-1

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:

  1. Download sources of rhino-mocks
  2. Convert project files by tool dotnet-migrate-2019.exe
  3. Migrate all projects to .net framework v.4.6.2 platform (min version required by castle.core)
  4. The gist of the way: update all rhino mocks project external references (xunit, castle.core 5 etc)
  5. 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.

aBaTaPbl4
  • 1
  • 1
  • I would say that you have following options 1) find a fork which has migrated the library 2) migrate it yourself 3) rewrite tests using another tool. – Guru Stron Apr 03 '23 at 16:07

1 Answers1

0

What a nostalgic question. Rhino Mocks was born from Ayende, around 2007 if memory serves me right. Then its maintenance diminished, to be picked up by Mike Meisinger in 2013. The last commit in their repo is from 2014, which is 9 years ago.

This predates .NET Core 1.0 by 2 years. Suffice to say: this project is dead, port your code to a maintained solution, such as Moq, of which v5 also has been in the making for years. But if it works, it works.

As to why: see the exception. The reflection APIs have changed significantly, and mocking is very reflection-heavy.

CodeCaster
  • 147,647
  • 23
  • 218
  • 272