当我按照下面的顺序(即Test1然后是Test2)进行以下测试时,会抛出上述错误。但是,如果按相反的顺序(即Test2然后是Test1)运行,效果很好。
[事实]
// file1.c (OR: file_mysym_implementation.c):
#ifdef MY_SYMBOL
// code goes here
#endif
// file2.c (OR: file_non_mysym_implementation.c):
#ifndef MY_SYMBOL
// code goes here
#endif
在public async Task Test1()
{
var body = GenerateStreamFromString();
var rawMessage = new BrokeredMessage(body);
ProductContractIngestFunc.GetProductContractDataHandler = log => Task.FromResult(_dataHandler);
await ProductContractIngestFunc.Ingest(rawMessage, _logger);
await _feedbackService.DidNotReceiveWithAnyArgs().ReportIssueAsync(
Arg.Any<BrokeredMessage>(),
Arg.Any<DataSyncValidationException>());
}
[Fact]
public async Task Test2()
{
var body = GenerateStreamFromString();
var rawMessage = new BrokeredMessage(body);
var mockFeatureFlagService = Substitute.For<IFeatureFlagService>();
var featureFlag = new FeatureFlag { Enabled = false };
mockFeatureFlagService.GetFeatureFlagAsync(ApplicationConstant.SyncDataType.ProductContract)
.Returns(Task.FromResult(featureFlag));
ServiceInjector.GetFeedbackService = log => _feedbackService;
ServiceInjector.GetFeatureFlagService = log => mockFeatureFlagService;
await ProductContractIngestFunc.Ingest(rawMessage, _logger);
await _feedbackService.ReceivedWithAnyArgs().ReportIssueAsync(
Arg.Any<BrokeredMessage>(),
Arg.Any<FeatureFlagException>());
}
中发生以下错误
错误:
_feedbackService.ReceivedWithAnyArgs()
最初,我认为这是因为共享同一对象,然后尝试在每个测试中重置模拟对象仍然没有区别。