Код: Выделить всё
public async Task Handle(BaseCommand request, CancellationToken cancellationToken)
=> request.MyAction switch
{
MyAction.FirstAction => await _mediator.Send(_mapper.Map(request), cancellationToken),
MyAction.SecondAction => await _mediator.Send(_mapper.Map(request), cancellationToken),
_ => throw new ArgumentOutOfRangeException().AddData(ErrorCodes.ArgumentOutOfRange)
};
Но он выполняет и то, и другое?
Это мой модульный тест:
Код: Выделить всё
[Fact]
public async void Handler_Should_Send_FirstActionCommand_Once()
{
// Arrange
var baseActionCommand = new BaseActionCommand()
{
MyAction = Action.FirstAction
};
// Act
await Sut.Handle(baseActionCommand, It.IsAny());
// Assert
_mediatorStub.Verify(x => x.Send(It.IsAny(), It.IsAny()), Times.Once);
_mediatorStub.Verify(x => x.Send(It.IsAny(), It.IsAny()), Times.Never);
}
Код: Выделить всё
Expected invocation on the mock should never have been performed, but was 1 times: x => x.Send(It.IsAny(), It.IsAny())
Подробнее здесь: https://stackoverflow.com/questions/793 ... t-shouldnt
Мобильная версия