我有一个具有以下课程的 Web API 项目。此类基本上是注册所有ApiController
实例并设置DependencyResolver
.
public class DependencyResolverConfig
{
public static void Register(HttpConfiguration configuration, ContainerBuilder containerBuilder)
{
containerBuilder.RegisterApiControllers(Assembly.GetExecutingAssembly());
var container = containerBuilder.Build();
var resolver = new AutofacWebApiDependencyResolver(container);
configuration.DependencyResolver = resolver;
}
}
为了测试这个类实际上设置了所有 API 控制器,我有以下测试
[Test]
public void RegistersApiControllers()
{
var config = new HttpConfiguration();
var containerBuilder = Substitute.For<ContainerBuilder>();
containerBuilder.RegisterApiControllers(Arg.Any<Assembly>());
DependencyResolverConfig.Register(config, containerBuilder);
containerBuilder.Received(2).RegisterApiControllers();
}
当我运行这个测试时,我得到以下异常NSubstitute
NSubstitute.Exceptions.ReceivedCallsException : Expected to receive exactly 2 calls matching:
RegisterCallback(Action<IComponentRegistry>)
Actually received no matching calls.
Received 2 non-matching calls (non-matching arguments indicated with '*' characters):
RegisterCallback(*Action<IComponentRegistry>*)
RegisterCallback(*Action<IComponentRegistry>*)
这是令人困惑的输出。NSubstitute
当实际呼叫和预期呼叫完全相同时,我不明白为什么不高兴。有什么线索吗?