public async Task <ActionResult <ValueFundResource> > PutAsync(long id, [FromBody] ValueFundResource valueFundResource) { var valueFund = _mapper.Map <ValueFundResource, ValueFund>(valueFundResource); var existingFund = await _fundService.FindAsync(valueFund.FundId); if (!existingFund.Success) { return(NotFound(existingFund.Message)); } var resultFindValueFund = await _valueFundService.FindAsync(id); if (!resultFindValueFund.Success) { return(NotFound(resultFindValueFund.Message)); } var result = await _valueFundService.UpdateAsync(valueFund); if (!result.Success) { return(BadRequest(result.Message)); } var valueFundResult = _mapper.Map <ValueFund, ValueFundResource>(result.ValueFund); return(Ok(valueFundResult)); }
public ValueFundControllerTest() { serviceMock = new Mock <IValueFundService>(); mapperMock = new Mock <IMapper>(); fundService = new Mock <IFundsService>(); _controller = new ValueFundController(serviceMock.Object, mapperMock.Object, fundService.Object); fund = new Fund { Id = 1, Name = "Fund1", Description = "Description fund 1" }; fundReponseNotFound = new FundResponse("Fund not found"); valueFundResponseNotFound = new ValueFundResponse("Value fund not found"); valueFund = new ValueFund { Id = 1, DateFund = DateTime.UtcNow, Value = 100, FundId = 1 }; valueFundResource = new ValueFundResource { Id = 1, DateFund = DateTime.UtcNow, Value = 100, FundId = 1 }; id = 1L; }
public async Task UpdateValueFundTest() { var valueFund2 = new ValueFund { Id = 2, DateFund = DateTime.UtcNow, Value = 200, FundId = 1 }; var valueFundResource = new ValueFundResource { Id = 2, DateFund = DateTime.UtcNow, Value = 200, FundId = 1 }; mapperMock.Setup(m => m.Map <ValueFundResource, ValueFund>(It.IsAny <ValueFundResource>())).Returns(valueFund2); fundService.Setup(x => x.FindAsync(valueFund2.FundId)).ReturnsAsync(new FundResponse(fund)); serviceMock.Setup(x => x.FindAsync(id)).ReturnsAsync(new ValueFundResponse(valueFund)); serviceMock.Setup(x => x.UpdateAsync(valueFund2)).ReturnsAsync(new ValueFundResponse(valueFund2)); mapperMock.Setup(m => m.Map <ValueFund, ValueFundResource>(It.IsAny <ValueFund>())).Returns(valueFundResource); var result = await _controller.PutAsync(id, valueFundResource); serviceMock.Verify(x => x.UpdateAsync(valueFund2), Times.Once); mapperMock.Verify(x => x.Map <ValueFund, ValueFundResource>(valueFund2), Times.Once); Assert.NotNull(result); }