以下是我目前遇到的问题的一个最小示例:
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();
}
...
当我运行第一个测试时,我得到以下异常:
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 the inner exception to investigate the root cause of the failure.
Inner exception messages:
System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
第二次测试成功。
我希望能够使用 AutoFixture 创建一个类的实例,它将 aWebSocket
作为构造函数参数,而无需先注入一个模拟对象(最终,这样我就可以使用一个AutoMoqData
属性,并摆脱一些样板文件) . 我在这里有任何误用或误解,还是将其作为 GitHub 问题更好?在此期间,我能做些什么来解决这个问题吗?