小编Cha*_*mon的帖子

AutoFixture/AutoMoq:无法创建实例(`BadImageFormatException`)

以下是我当前遇到的问题的一个最小示例:

using System.Net.WebSockets;
using AutoFixture;
using AutoFixture.AutoMoq;
using FluentAssertions;
using Xunit;

...

[Fact]
public void Test1()
{
    var fixture = new Fixture().Customize(new AutoMoqCustomization() { ConfigureMembers = true });
    var sut = fixture.Create<WebSocket>();
    sut.Should().NotBeNull();
}

[Fact]
public void Test2()
{
    var fixture = new Fixture().Customize(new AutoMoqCustomization() { ConfigureMembers = true });
    var sut = new Mock<WebSocket>().Object;
    fixture.Inject(sut);
    sut.Should().NotBeNull();
}
...
Run Code Online (Sandbox Code Playgroud)

当我运行第一个测试时,出现以下异常:

AutoFixture.ObjectCreationExceptionWithPath : AutoFixture was unable to create an instance from Moq.Mock`1[System.IO.Stream] because creation unexpectedly failed with exception. Please refer to …
Run Code Online (Sandbox Code Playgroud)

moq autofixture automoq

2
推荐指数
1
解决办法
8776
查看次数

标签 统计

autofixture ×1

automoq ×1

moq ×1