public async Task <DAppOffer> UpdateDAppOffer(Guid id, UpdateDAppOfferModel updateDAppOfferModel, string jwt) { if (string.IsNullOrEmpty(updateDAppOfferModel.Title) || string.IsNullOrEmpty(updateDAppOfferModel.Description)) { throw new EmptyFieldException(); } var offer = await GetDAppOffer(id); offer.Id = id; offer.Title = updateDAppOfferModel.Title; offer.Description = updateDAppOfferModel.Description; offer.OfferLengthInMonths = updateDAppOfferModel.OfferLengthInMonths; offer.LiskPerMonth = updateDAppOfferModel.LiskPerMonth; offer.DelegatesNeededForOffer = updateDAppOfferModel.DelegatesNeededForOffer; offer.Region = updateDAppOfferModel.Region; offer.DateStart = updateDAppOfferModel.DateStart; offer.DateEnd = updateDAppOfferModel.DateEnd; if (offer.Provider.Id != _jwtIdClaimReaderHelper.getUserIdFromToken(jwt)) //authorization { throw new NotAuthenticatedException(); } return(await _dAppRepository.UpdateDAppOffer(id, offer)); }
public async Task UpdateProduct_Success() { //Arrange var guid = Guid.NewGuid(); const string titleText = "Title1"; const string descriptionText = "Description1"; const string jwt = ""; var updateProductModel = new UpdateDAppOfferModel { Title = titleText, Description = descriptionText }; var product1 = new DAppOffer { Id = guid, Title = titleText, Description = descriptionText }; _dAppService.Setup(x => x.UpdateDAppOffer(guid, updateProductModel, jwt)).ReturnsAsync(product1); //Act var result = await _dAppController.UpdateDAppOffer(guid, updateProductModel, jwt) as ObjectResult; //Assert Assert.NotNull(result); Assert.IsType <OkObjectResult>(result); Assert.Equal(product1, (DAppOffer)result.Value); }
public async Task <IActionResult> UpdateDAppOffer(Guid id, UpdateDAppOfferModel updateDAppOfferModel, [FromHeader(Name = "Authorization")] string jwt) { try { return(Ok(await _dAppService.UpdateDAppOffer(id, updateDAppOfferModel, jwt))); } catch (Exception e) { return(BadRequest(e.Message)); } }
public async Task UpdateDAppOffer_Success() { const string titleText = "Title Text"; const string descriptionText = "Description Text"; var id = Guid.NewGuid(); var userid = Guid.NewGuid(); const string jwt = ""; var product = new DAppOffer { Id = id, Title = titleText, Description = descriptionText, Provider = new User() { Id = userid } }; var updatedProduct = new DAppOffer { Id = id, Title = "New Title", Description = "New Description", Provider = new User() { Id = userid } }; var updateProductModel = new UpdateDAppOfferModel { Title = updatedProduct.Title, Description = updatedProduct.Description, }; _dAppRepository.Setup(x => x.GetDAppOffer(product.Id)).ReturnsAsync(product); _dAppRepository.Setup(x => x.UpdateDAppOffer(product.Id, product)).ReturnsAsync(updatedProduct); _jwtIdClaimReaderHelper.Setup(x => x.getUserIdFromToken(jwt)).Returns(userid); var result = await _dAppService.UpdateDAppOffer(product.Id, updateProductModel, jwt); Assert.NotNull(result); Assert.Equal(updatedProduct, result); Assert.NotEqual(titleText, result.Description); Assert.NotEqual(descriptionText, result.Title); }
public async Task UpdateProduct_BadRequest() { //Arrange var guid = Guid.NewGuid(); const string titleText = "Title1"; const string descriptionText = "Description1"; const string jwt = ""; var updateProductModel = new UpdateDAppOfferModel { Title = titleText, Description = descriptionText }; _dAppService.Setup(x => x.UpdateDAppOffer(guid, updateProductModel, jwt)).Throws <OfferUpdateFailedException>(); //Act var result = await _dAppController.UpdateDAppOffer(guid, updateProductModel, jwt); //Assert Assert.NotNull(result); Assert.IsType <BadRequestObjectResult>(result); }
public async Task UpdateProduct_EmptyTitleFailed() { const string titleText = "Title Text"; const string descriptionText = "Description Text"; var id = Guid.NewGuid(); const string jwt = ""; var product = new DAppOffer { Id = id, Title = titleText, Description = descriptionText }; var updatedProduct = new DAppOffer { Id = id, Title = "", Description = "New Description" }; var updateProductModel = new UpdateDAppOfferModel { Title = updatedProduct.Title, Description = updatedProduct.Description }; _dAppRepository.Setup(x => x.UpdateDAppOffer(product.Id, product)).ReturnsAsync(updatedProduct); var result = await Assert.ThrowsAsync <EmptyFieldException>(() => _dAppService.UpdateDAppOffer(product.Id, updateProductModel, jwt)); Assert.NotNull(result); Assert.IsType <EmptyFieldException>(result); }