public FundsControllerTest() { serviceMock = new Mock <IFundsService>(); mapperMock = new Mock <IMapper>(); _controller = new FundsController(serviceMock.Object, mapperMock.Object); fundReponseNotFound = new FundResponse("Fund not found"); fund = new Fund { Id = 1, Name = "Fund1", Description = "Description fund 1" }; fundResource = new FundsResource { Id = 1, Name = "Fund1", Description = "Description fund 1" }; saveFundResource = new SaveFundsResource { Name = "Fund1", Description = "Description fund 1" }; id = 1L; }
public async Task UpdateFundTest() { var fund2 = new Fund { Id = 2, Name = "Fund2", Description = "Description fund 2" }; var fundResource = new FundsResource { Id = 2, Name = "Fund2", Description = "Description fund 2" }; mapperMock.Setup(m => m.Map <SaveFundsResource, Fund>(It.IsAny <SaveFundsResource>())).Returns(fund2); serviceMock.Setup(x => x.FindAsync(id)).ReturnsAsync(new FundResponse(fund)); serviceMock.Setup(x => x.UpdateAsync(fund2)).ReturnsAsync(new FundResponse(fund2)); mapperMock.Setup(m => m.Map <Fund, FundsResource>(It.IsAny <Fund>())).Returns(fundResource); var result = await _controller.PutAsync(id, saveFundResource); serviceMock.Verify(x => x.UpdateAsync(fund2), Times.Once); mapperMock.Verify(x => x.Map <Fund, FundsResource>(fund2), Times.Once); Assert.NotNull(result); }