如果你必須重新編譯,那麼你可以做到這一點。我查找了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有任何改變,這是唯一的依賴性。