Using Moles with XUnit - wrong dll version

I am trying to configure Moles for use in our unit testing. We use xunit, so I am using the Xunit extension that comes with moles ( Microsoft.Moles.Framework.Xunit ). However, since we are running Xunit 1.7, Moles complains that I am not running version 1.6.1.1521 (with FileLoadException ).

The Role Guide (p. 28) says:

xUnit.net Version:

1.5.0.1479 (for other versions of xUnit.net recompile the attribute from sources)

This is where I am stuck - is the source code for this xunit extension available somewhere? Or will I have to use the specific xunit version that Moles requires?

+4
source share
3 answers

While the proxon request was very useful for completing my task, let me present the best answer that I found as I explored further (I hope this helps others facing this problem). The source code is located in C:\Program Files\Microsoft Moles\Documentation\moles.samples.zip . Quite identical to the code, which, of course, was decompiled.

You can also find NUnit and MbUnit wrappers.

+1
source

Can't you define assembly binding redirection in moles.runner.exe.config ?

 <configuration> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="xunit.dll" publicKeyToken="8d05b1bb7a6fdb6c" /> <bindingRedirect oldVersion="1.5.0.1479" newVersion="1.6.1.1521" /> </dependentAssembly> </assemblyBinding> </runtime> </configuration> 
+2
source

If you need to recompile, you can do it. I was looking for Moles source code but I could not find it anywhere. Then I tried to parse Microsoft.Moles.Xunit.dll , and I realized that the attribute is just a few lines.

Download Source Package MoledAttribute:

 using System; using System.Reflection; using XUnit; namespace Microsoft.Moles.Framework.Xunit { public sealed class MoledAttribute : BeforeAfterTestAttribute { // Fields private IDisposable _molesContext; public override void Before(MethodInfo methodUnderTest) { this._molesContext = MolesContext.Create(); } public override void After(MethodInfo methodUnderTest) { IDisposable disposable = this._molesContext; if (disposable != null) { disposable.Dispose(); } this._molesContext = null; } } } 

You should create a new class library and add a link to xunit.dll of any version you want. It should work even with 1.8.0.1545, since I did not notice any changes in XUnit.BeforeAfterTestAttribute , which is the only parameter.

+2
source

All Articles