public async Task Handle(AddOngoingIncidentAttachmentCommand request, CancellationToken cancellationToken)
{
var hasSetting = _serverSettings.TryGetValue(ServerSettingKey.SendPdfToLocusMobile, out var isPdfToBeSentToLocusMobile);
var result = await _incidentAttachmentWebBlobDal.AddOnGoingIncidentAttachment(request.Attachment, request.FileContent, request.User);
var isPdfAttachment = request.Attachment.IncidentAttachmentDataType == (IncidentAttachmentDataType)SharedTypes.Enums.IncidentAttachmentDataType.Pdf;
var shouldNotifyLocusMobile = hasSetting && isPdfToBeSentToLocusMobile;
if (!isPdfAttachment || shouldNotifyLocusMobile)
{
_locusMobilePublisher.SendIncidentMessageToCalledOutResources(result.IncidentId);
}
return result;
}
< /code>
Мой тест - что -то вроде этого < /p>
[Test]
public async Task Handle_ShouldNotNotifyLocusMobile_WhenPdfAttachmentProvidedAndSettingDisabled()
{
// Arrange
var incident = await GetIncident(await GetAnExistingIncidentId());
var pdfContent = new byte[] { };
var incidentAttachmentDto = new IncidentAttachmentWebDto
{
CompleteIncidentNumber = incident.CompleteIncidentNumber,
FileName = "test-attachment-pdf",
IncidentAttachmentDataType = IncidentAttachmentDataType.Pdf,
CreatedAt = DateTimeOffset.Now,
UpdatedAt = DateTimeOffset.Now,
Description = "PDF test",
ResourceName = "test",
Latitude = null,
Longitude = null,
Thumbnail = null,
Id = incident.Id
};
bool isPdfToBeSentToLocusMobile = false;
_mockServerSettingCache
.Setup(cache => cache.TryGetValue(ServerSettingKey.SendPdfToLocusMobile, out It.Ref.IsAny))
.Callback((string key, out bool value) => value = isPdfToBeSentToLocusMobile)
.Returns(true); //
// Act
var incidentAttachmentCreationResponse = await Mediator.Send(new AddOngoingIncidentAttachmentCommand
{
Attachment = incidentAttachmentDto,
FileContent = pdfContent,
User = "test",
});
// Assert
Assert.That(incidentAttachmentCreationResponse, Is.Not.Null);
_mockLocusMobilePublisher.Verify(
pub => pub.SendIncidentMessageToCalledOutResources(It.IsAny()),
Times.Never,
"LocusMobile should NOT be notified when PDF is attached and setting is disabled."
);
}
Получение ошибки не может преобразовать выражение лямбда в тип «wollocationAction», потому что это не тип делегата
Я получаю Линия, где я настраиваю _mockserversettingcache
Я пытаюсь настроить MOQ, и я не хорош настройку модульных тестов. Я пытаюсь проверить обработчик, который имеет следующий код < /p> [code] public async Task Handle(AddOngoingIncidentAttachmentCommand request, CancellationToken cancellationToken) { var hasSetting = _serverSettings.TryGetValue(ServerSettingKey.SendPdfToLocusMobile, out var isPdfToBeSentToLocusMobile); var result = await _incidentAttachmentWebBlobDal.AddOnGoingIncidentAttachment(request.Attachment, request.FileContent, request.User);
var isPdfAttachment = request.Attachment.IncidentAttachmentDataType == (IncidentAttachmentDataType)SharedTypes.Enums.IncidentAttachmentDataType.Pdf; var shouldNotifyLocusMobile = hasSetting && isPdfToBeSentToLocusMobile;
if (!isPdfAttachment || shouldNotifyLocusMobile) { _locusMobilePublisher.SendIncidentMessageToCalledOutResources(result.IncidentId);
} return result; } < /code> Мой тест - что -то вроде этого < /p> [Test] public async Task Handle_ShouldNotNotifyLocusMobile_WhenPdfAttachmentProvidedAndSettingDisabled() { // Arrange var incident = await GetIncident(await GetAnExistingIncidentId()); var pdfContent = new byte[] { }; var incidentAttachmentDto = new IncidentAttachmentWebDto { CompleteIncidentNumber = incident.CompleteIncidentNumber, FileName = "test-attachment-pdf", IncidentAttachmentDataType = IncidentAttachmentDataType.Pdf, CreatedAt = DateTimeOffset.Now, UpdatedAt = DateTimeOffset.Now, Description = "PDF test", ResourceName = "test", Latitude = null, Longitude = null, Thumbnail = null, Id = incident.Id };
bool isPdfToBeSentToLocusMobile = false;
_mockServerSettingCache .Setup(cache => cache.TryGetValue(ServerSettingKey.SendPdfToLocusMobile, out It.Ref.IsAny)) .Callback((string key, out bool value) => value = isPdfToBeSentToLocusMobile) .Returns(true); //
// Act var incidentAttachmentCreationResponse = await Mediator.Send(new AddOngoingIncidentAttachmentCommand { Attachment = incidentAttachmentDto, FileContent = pdfContent, User = "test", });
_mockLocusMobilePublisher.Verify( pub => pub.SendIncidentMessageToCalledOutResources(It.IsAny()), Times.Never, "LocusMobile should NOT be notified when PDF is attached and setting is disabled." ); } [/code] Получение ошибки [b] не может преобразовать выражение лямбда в тип «wollocationAction», потому что это не тип делегата [/b] Я получаю Линия, где я настраиваю _mockserversettingcache