2011-05-11 26 views
4

我試圖設置痣在我們的單元測試中使用。我們使用xunit,所以我是using Xunit擴展名,帶有痣(Microsoft.Moles.Framework.Xunit)。然而,當我們運行Xunit 1.7時,Moles抱怨說我沒有運行1.6.1.1521版(帶有FileLoadException)。在XUnit中使用痣 - 錯誤的dll版本

Moles Manual(第28頁)不會說:

xUnit.net版本:

1.5.0.1479(其他xUnit.net版本,重新編譯來源屬性)

這就是我卡住的地方 - 是這個xunit e的源代碼xtension可用嗎?或者我將不得不使用Moles需要的特定版本的xunit?

回答

1

雖然proxon的回答對於完成我的任務非常有幫助,但讓我在我進一步調查時發現更好的答案(希望可以幫助其他人解決此問題)。源代碼可在C:\Program Files\Microsoft Moles\Documentation\moles.samples.zip中找到。當然,與proxon反編譯的代碼非常相似。

你也可以在那裏找到NUnit和MbUnit包裝器。

2

您不能在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

如果你必須重新編譯,那麼你可以做到這一點。我查找了Moles源代碼,但是我無法在任何地方找到它。然後我嘗試拆卸Microsoft.Moles.Xunit.dll,我意識到該屬性只有幾行。

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; 
     } 
    } 
} 

您應該創建一個新的類庫,並添加引用你想要的任何版本的xunit.dll。它甚至應該與1.8.0.1545一起工作,因爲我沒有注意到對於XUnit.BeforeAfterTestAttribute有任何改變,這是唯一的依賴性。