以下构造函数参数没有匹配的装置数据,无法使用Moq和xunit进行单元测试。
已经使用依赖注入和模拟来测试类。
//this is how i register the DI.
services.AddScoped();
public interface IWaktuSolatServiceApi
{
Task GetAsyncSet();
}
// the unit test.
public class UnitTest1
{
Mock waktu;
public UnitTest1(IWaktuSolatServiceApi waktu)
{
this.waktu = new Mock();
}
[Fact]
public async Task ShoudReturn()
{
var request = new Solat
{
zone = "lala"
};
var response = waktu.Setup(x =>
x.GetAsyncSet()).Returns(Task.FromResult(request));
}
}
但我收到此错误:以下构造函数参数没有匹配的装置数据。
XUNIT没有使用DI来解析引用。
删除构造函数参数。至少在您的代码示例中,它无论如何都是未使用的。
// the unit test.
public class UnitTest1
{
Mock waktu;
/// HERE, remove the parameter
public UnitTest1()
{
this.waktu = new Mock();
}
[Fact]
public async Task ShoudReturn()
{
var request = new Solat
{
zone = "lala"
};
var response = waktu.Setup(x =>
x.GetAsyncSet()).Returns(Task.FromResult(request));
}
}
这篇关于单元测试xunit以下构造函数参数没有匹配的装置数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持吉威生活!
[英文标题]Unit Testing xunit The following constructor parameters did not have matching fixture data
声明:本媒体部分图片、文章来源于网络,版权归原作者所有,如有侵权,请联系QQ:330946442删除。