Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net Autofixture和Moq v4_.net_Unit Testing_Moq_Autofixture - Fatal编程技术网

.net Autofixture和Moq v4

.net Autofixture和Moq v4,.net,unit-testing,moq,autofixture,.net,Unit Testing,Moq,Autofixture,我用Nuget安装了Autofixture和Moq。所以我有Moq版本4 当运行以下代码时 var fixture = new Fixture().Customize(new AutoMoqCustomization()); fixture.CreateAnonymous<ISomething>(); var fixture=newfixture().Customize(新的AutoMoqCustomization()); fixture.CreateAnonymous(); 出

我用Nuget安装了Autofixture和Moq。所以我有Moq版本4

当运行以下代码时

var fixture = new Fixture().Customize(new AutoMoqCustomization());
fixture.CreateAnonymous<ISomething>();
var fixture=newfixture().Customize(新的AutoMoqCustomization());
fixture.CreateAnonymous();
出现以下错误

System.IO.FileLoadException:无法 不加载文件或程序集的Moq, 版本=3.1.416.3,区域性=中性, PublicKeyToken=69f491c39445e920'

我还尝试将其重定向到v4,但没有成功

<configuration>
  <runtime>
    <assemblyBinding>
    <dependentAssembly>
      <assemblyIdentity name="Moq" publicKeyToken="69f491c39445e920" culture="neutral"/>
      <bindingRedirect oldVersion="3.1.416.3" newVersion="4.0.10827.0"/>
    </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>


这里可能有什么问题?

要重定向配置文件中的程序集绑定,需要在中指定
urn:schemas microsoft com:asm.v1
命名空间,如本例所示:

<configuration>
    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="Moq"
                                  publicKeyToken="69f491c39445e920"
                                  culture="neutral"/>
                <bindingRedirect oldVersion="3.1.416.3"
                                 newVersion="4.0.10827.0"/>
            </dependentAssembly>
        </assemblyBinding>
    </runtime>
</configuration>

和)将自动加载到运行在.NET 4.0上的进程中,因为。以下是MSDN对此的引用:

如果应用程序是使用 .NETFramework4运行时 包括已构建的库 使用早期运行时,该库 将使用.NET Framework 4运行时 也但是,如果您有 使用 早期运行时和 使用.NETFramework4构建,您可以 必须强制您的应用程序也 使用.NETFramework 4

相关资源:


    • 接受的答案对我不起作用,因为我想使用与AutoFixture.AutoMoq相同类库(非exe)中的Moq 4。似乎也有支持Moq 4的自动夹具。最后,我使用了AutoFixture.AutoHinoMocks作为下一个最受欢迎的选择,这与Moq 4没有冲突。

      另请参阅此问题:在安装NuGet软件包时,从现在开始,就有必要的程序集绑定重定向。您看到了哪些问题?我已经使用AutoFixture.AutoMoq和Moq 4多年了,没有任何问题。