public async Task <IActionResult> GetOfferById([FromRoute] string id) { if (string.IsNullOrEmpty(id)) { throw new ApiException("The Offer can't be found.", StatusCodes.Status404NotFound); } Offer offer = await _offerService.GetByIdAsync(id); if (offer == null) { throw new ApiException("The Offer can't be found.", StatusCodes.Status404NotFound); } OfferViewModel offerViewModel = OfferViewModel.From(offer); return(Ok(SimpleResponse <OfferViewModel> .Create(offerViewModel))); }
public async Task GetAllAsyncWhenNoOffersReturnsEmptyCollection() { //Arrange var mockOfferRepository = GetDefaultIOfferRepositoryInstance(); var mockUnitOfWork = GetDefaultIUnitOfWorkInstance(); var offerId = 200; mockOfferRepository.Setup(r => r.FindById(offerId)) .Returns(Task.FromResult <Offer>(null)); var service = new OfferService(mockOfferRepository.Object, mockUnitOfWork.Object); //Act OfferResponse result = await service.GetByIdAsync(offerId); var message = result.Message; //Assert message.Should().Be("Offer not found"); }