Received() did not recognize call that certainly was performed correctly
KittKillward opened this issue · 1 comments
KittKillward commented
Describe the bug
Received() did not recognize call that certainly was performed correctly
To Reproduce
- Make interface with such members
public Task<string> SendMessageAsync(
string UserChatId,
string message,
bool replyKeyboardRemove = false,
int typeMessage = 1,
object AddOptions = null,
int priority=0,
Action<Exception> CallBackException = null,
bool RunningFromCustomDebug = false);
public int BotId { get; }
public int IdService { get; }
- Set Returns() like this.
var facebookServiceMock = Substitute.For<IServiceMessenger>();
facebookServiceMock.IdService.Returns((int)MessengerTypeEnum.Facebook);
facebookServiceMock.BotId.Returns(2391);
This Returns() are not involved in checking of Received()
- Perform testing call like this
{
IServiceMessenger serviceMessenger = facebookServiceMock;
MessengerTypeEnum MetaSendingType = MetaSendingTypeEnum.ACCOUNT_UPDATE
result = await serviceMessenger.SendMessageAsync(
UserChatId,
_text,
AddOptions: new SendingOption { MetaSendingType = MetaSendingType },
priority: 99);
}
- Check Call like this
//Assert
var result = await facebookServiceMock.Received().SendMessageAsync(
Arg.Any<string>(),
Arg.Any<string>(),
AddOptions: Arg.Is<SendingOption>(so => so.MetaSendingType == MetaSendingTypeEnum.ACCOUNT_UPDATE),
priority: Arg.Any<int>());
- On test debug ensure that MetaSendingType is correct, but NSubstitute returns error
NSubstitute.Exceptions.ReceivedCallsException : Expected to receive exactly 1 call matching:
SendMessageAsync(any String, any String, False, 1, so => (Convert(so.MetaSendingType, Int32) == 1), any Int32, <null>, False)
Actually received no matching calls.
Expected behaviour
NSubstitute see that call was received
Environment:
- NSubstitute version: 5.1.0]
- NSubstitute.Analyzers version: CSharp 1.0.17]
- Platform: Windows 10, Visual Studio 2022 17,10,5, .Net 8
KittKillward commented
I found problem. During executing of tested method, instance of mock was deep cloned.