Простой moq для MediatR command
Редактировал(а) Alexandr Fokin 2024/01/04 19:19
Moq билдер для Тестирование.
using MediatR;
using Moq;
namespace test.Model
{
internal class MediatorMoqBuilder
{
private readonly Mock<IMediator> _mock = new Mock<IMediator>();
public MediatorMoqBuilder AddCommand<TParameter, TResult>(
Func<TParameter, CancellationToken, Task<TResult>> commandActionAsync
)
where TParameter : IRequest<TResult>
{
_mock
.Setup(
e => e.Send(It.IsAny<TParameter>(), It.IsAny<CancellationToken>())
)
.Returns(commandActionAsync);
return this;
}
public IMediator GetMediator()
{
return _mock.Object;
}
}
}
using Moq;
namespace test.Model
{
internal class MediatorMoqBuilder
{
private readonly Mock<IMediator> _mock = new Mock<IMediator>();
public MediatorMoqBuilder AddCommand<TParameter, TResult>(
Func<TParameter, CancellationToken, Task<TResult>> commandActionAsync
)
where TParameter : IRequest<TResult>
{
_mock
.Setup(
e => e.Send(It.IsAny<TParameter>(), It.IsAny<CancellationToken>())
)
.Returns(commandActionAsync);
return this;
}
public IMediator GetMediator()
{
return _mock.Object;
}
}
}