public async Task UpdateProduct_Success() { //Arrange var guid = Guid.NewGuid(); const string titleText = "Title1"; const string descriptionText = "Description1"; const string jwt = ""; var updateProductModel = new UpdateDelegateOfferModel { Title = titleText, Description = descriptionText }; var product1 = new DelegateOffer { Id = guid, Title = titleText, Description = descriptionText }; _delegateService.Setup(x => x.UpdateDelegateOffer(guid, updateProductModel, jwt)).ReturnsAsync(product1); //Act var result = await _delegateController.UpdateDelegateOffer(guid, updateProductModel, jwt) as ObjectResult; //Assert Assert.NotNull(result); Assert.IsType <OkObjectResult>(result); Assert.Equal(product1, (DelegateOffer)result.Value); }
public async Task <DelegateOffer> UpdateDelegateOffer(Guid id, UpdateDelegateOfferModel updateDelegateOfferModel, string jwt) { if (string.IsNullOrEmpty(updateDelegateOfferModel.Title) || string.IsNullOrEmpty(updateDelegateOfferModel.Description)) { throw new EmptyFieldException(); } var delegateOffer = await GetDelegateOffer(id); if (delegateOffer.Provider.Id != _jwtIdClaimReaderHelper.getUserIdFromToken(jwt)) { throw new NotAuthenticatedException(); } delegateOffer.Id = id; delegateOffer.Title = updateDelegateOfferModel.Title; delegateOffer.Description = updateDelegateOfferModel.Description; delegateOffer.Region = updateDelegateOfferModel.Region; delegateOffer.LiskPerMonth = updateDelegateOfferModel.LiskPerMonth; delegateOffer.AvailableForInMonths = updateDelegateOfferModel.AvailableForInMonths; return(await _delegateRepository.UpdateDelegateOffer(id, delegateOffer)); }
public async Task <IActionResult> UpdateDelegateOffer(Guid id, UpdateDelegateOfferModel updateDelegateOfferModel, [FromHeader(Name = "Authorization")] string jwt) { try { return(Ok(await _delegateService.UpdateDelegateOffer(id, updateDelegateOfferModel, jwt))); } catch (Exception e) { return(BadRequest(e.Message)); } }
public async Task UpdateDelegateOffer_Success() { const string titleText = "Title Text"; const string descriptionText = "Description Text"; var id = Guid.NewGuid(); const string jwt = ""; var userid = Guid.NewGuid(); var product = new DelegateOffer { Id = id, Title = titleText, Description = descriptionText, Provider = new User() { Id = userid } }; var updatedProduct = new DelegateOffer { Id = id, Title = "New Title", Description = "New Description", Provider = new User() { Id = userid } }; var updateProductModel = new UpdateDelegateOfferModel { Title = updatedProduct.Title, Description = updatedProduct.Description }; _marketplaceRepository.Setup(x => x.GetDelegateOffer(product.Id)).ReturnsAsync(product); _jwtIdClaimReaderHelper.Setup(x => x.getUserIdFromToken(jwt)).Returns(userid); _marketplaceRepository.Setup(x => x.UpdateDelegateOffer(product.Id, product)).ReturnsAsync(updatedProduct); var result = await _marketplaceService.UpdateDelegateOffer(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 UpdateDelegateOfferModel { Title = titleText, Description = descriptionText }; _delegateService.Setup(x => x.UpdateDelegateOffer(guid, updateProductModel, jwt)).Throws <OfferUpdateFailedException>(); //Act var result = await _delegateController.UpdateDelegateOffer(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 DelegateOffer { Id = id, Title = titleText, Description = descriptionText }; var updatedProduct = new DelegateOffer { Id = id, Title = "", Description = "New Description" }; var updateProductModel = new UpdateDelegateOfferModel { Title = updatedProduct.Title, Description = updatedProduct.Description }; _marketplaceRepository.Setup(x => x.UpdateDelegateOffer(product.Id, product)).ReturnsAsync(updatedProduct); var result = await Assert.ThrowsAsync <EmptyFieldException>(() => _marketplaceService.UpdateDelegateOffer(product.Id, updateProductModel, jwt)); Assert.NotNull(result); Assert.IsType <EmptyFieldException>(result); }