public async Task <IActionResult> GetAverage( [FromQuery] GetAveragePriceDto data) { var query = this.Mapper.Map <GetAveragePriceQuery>(data); var result = await this.Mediator.Send(query); return(this.FromResult(result)); }
public async Task GetAveragePrice_WhenNoPrices_ShouldBeNotFound(GetAveragePriceDto dto) { // Arrange this.mediatorMock .Setup(m => m.Send(It.IsAny <GetAveragePriceQuery>(), default)) .ReturnsAsync(It.IsAny <NotFoundHandlerResult <AveragePriceViewModel> >()); // Act var actual = await this.sut.GetAverage(dto); // Assert actual.Should().BeOfType <NotFoundResult>(); }
public async Task GetAveragePrice_WhenCalled_ShouldMapDto(GetAveragePriceDto dto) { // Arrange this.mapperMock .Setup(m => m.Map <GetAveragePriceQuery>(dto)) .Returns(It.IsAny <GetAveragePriceQuery>()); // Act await this.sut.GetAverage(dto); // Assert this.mapperMock.Verify(x => x.Map <GetAveragePriceQuery>(dto), Times.Once); }
public async Task GetAveragePrice_WhenExistsPrices_ShouldBeOkObjectResult( AveragePriceViewModel resultDto, GetAveragePriceDto dto) { // Arrange this.mediatorMock .Setup(m => m.Send(It.IsAny <GetAveragePriceQuery>(), default)) .ReturnsAsync(new DataHandlerResult <AveragePriceViewModel>(resultDto)); // Act var actual = await this.sut.GetAverage(dto); // Assert actual.Should().BeOfType <OkObjectResult>() .Which.Value.Should().BeEquivalentTo(resultDto); }
public async Task GetAveragePrice_WhenCalled_ShouldSendQuery( GetAveragePriceDto dto, GetAveragePriceQuery query) { // Arrange this.mapperMock .Setup(m => m.Map <GetAveragePriceQuery>(dto)) .Returns(query); this.mediatorMock .Setup(m => m.Send(query, default)) .ReturnsAsync(It.IsAny <IHandlerResult <AveragePriceViewModel> >()); // Act await this.sut.GetAverage(dto); // Assert this.mediatorMock.VerifyAll(); }