Исключение в Mappermock.verifyC#

Место общения программистов C#
Ответить
Anonymous
 Исключение в Mappermock.verify

Сообщение Anonymous »

Ниже описан мой метод обслуживания

Код: Выделить всё

public async Task CreateAnnotation(AnnotationMasterRequest annotationMasterRequest)
{
return await serviceResponseExceptionHandler.HandleAsync(async () =>
{
var annotationMaster = _mapper.Map(annotationMasterRequest);
annotationMaster.AnnotationMasterId = Guid.NewGuid();

var responseResult = await base.Insert(annotationMaster);
return responseResult.DataResult;
}, annotationMasterRequest);
}
Тестовый пример для вышеуказанного метода

Код: Выделить всё

[Fact]
public async Task CreateAnnotation_Success()
{
// Arrange
var annotationRequest = new AnnotationMasterRequest
{
AnnotationMasterName = "test"
};

var annotationMaster = new AnnotationMaster
{
AnnotationMasterName = annotationRequest.AnnotationMasterName,
};

var annotationResponse = new AnnotationMasterResponse { };

var expectedResponse = new ServiceResponse
{
Success = true,
HttpStatusCode = HttpStatusCode.OK,
DataResult = annotationResponse
};

_mapperMock.Setup(m => m.Map(It.IsAny()))
.Callback(req => Console.WriteLine($"Mapper called with: {req}"))
.Returns(annotationMaster);

_baseRepositoryMock.Setup(repo => repo.Insert(It.IsAny())).ReturnsAsync(true); // or false, depending on the test

_exceptionHandlerMock.Setup(h => h.HandleAsync(It.IsAny(), annotationRequest)).ReturnsAsync(expectedResponse);

var result = await _annotationMasterService.CreateAnnotation(annotationRequest);

// Assert
Assert.NotNull(result);
Assert.True(result.Success);
Assert.Equal(HttpStatusCode.OK, result.HttpStatusCode);
Assert.NotNull(result.DataResult);

_mapperMock.Verify(m => m.Map(It.Is(req => req.AnnotationMasterName == annotationRequest.AnnotationMasterName)), Times.Once);
}
Получение ошибки в _mapperMock.Verify
Moq.MockException: '
Ожидается однократный вызов макета , но было 0 раз: m => m.Map(It.Is(req => req.AnnotationMasterName == annotationRequest.AnnotationMasterName))

Подробнее здесь: https://stackoverflow.com/questions/792 ... ock-verify
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»