public async Task DeleteDelegateOfferById() { //Arrange var product1 = new DelegateOffer { Id = Guid.NewGuid(), Title = "Title1", Description = "Description1" }; var product2 = new DelegateOffer { Id = Guid.NewGuid(), Title = "Title2", Description = "Description2" }; await _delegateRepository.CreateDelegateOffer(product1); await _delegateRepository.CreateDelegateOffer(product2); //Act await _delegateRepository.DeleteDelegateOffer(product1.Id); var result = await _delegateRepository.GetDelegateOffer(product1.Id); var resultAll = await _delegateRepository.GetAllDelegateOffers(); //Assert Assert.Null(result); Assert.NotNull(resultAll); Assert.NotEmpty(resultAll); Assert.Single(resultAll); }
public async Task GetAll() { //Arrange var product1 = new DelegateOffer { Id = Guid.NewGuid(), Title = "Title1", Description = "Description Text" }; var product2 = new DelegateOffer { Id = Guid.NewGuid(), Title = "Title2", Description = "Description Text" }; await _delegateRepository.CreateDelegateOffer(product1); await _delegateRepository.CreateDelegateOffer(product2); //Act var result = await _delegateRepository.GetAllDelegateOffers(); //Assert Assert.NotNull(result); Assert.NotEmpty(result); Assert.Equal(2, result.Count); Assert.Equal(product1.Title, result[0].Title); Assert.Equal(product2.Title, result[1].Title); }
public async Task UpdateDelegateOffer() { //Arrange var product1 = new DelegateOffer { Id = Guid.NewGuid(), Title = "Title1", Description = "Description1" }; var product2 = new DelegateOffer { Id = Guid.NewGuid(), Title = "Title2", Description = "Description2" }; await _delegateRepository.CreateDelegateOffer(product1); await _delegateRepository.CreateDelegateOffer(product2); //Act product1.Title = "Title1Edited"; await _delegateRepository.UpdateDelegateOffer(product1.Id, product1); var result = await _delegateRepository.GetDelegateOffer(product1.Id); //Assert Assert.NotNull(result); Assert.Equal(product1.Title, result.Title); }
public async Task CreateDelegateOffer_Success() { const string titleText = "Title Text"; const string descriptionText = "Description Text"; const string jwt = ""; var userid = Guid.NewGuid(); var product = new DelegateOffer { Title = titleText, Description = descriptionText, Provider = new User() { Id = userid } }; var createProductModel = new CreateDelegateOfferModel { Title = titleText, Description = descriptionText, Provider = new User() { Id = userid } }; _marketplaceRepository.Setup(x => x.CreateDelegateOffer(It.IsAny <DelegateOffer>())).ReturnsAsync(product); _jwtIdClaimReaderHelper.Setup(x => x.getUserIdFromToken(jwt)).Returns(userid); var result = await _marketplaceService.CreateDelegateOffer(createProductModel, jwt); Assert.Equal(product.Title, result.Title); Assert.Equal(1, 1); }
public async Task CreateDelegateOffer_Success() { const string titleText = "Title Text"; const string descriptionText = "Description Text"; const string jwt = ""; var guid = Guid.NewGuid(); var product = new DelegateOffer() { Id = guid, Title = titleText, Description = descriptionText }; var createProductModel = new CreateDelegateOfferModel() { Guid = guid, Title = titleText, Description = descriptionText }; _delegateService.Setup(x => x.CreateDelegateOffer(createProductModel, jwt)).ReturnsAsync(product); var result = await _delegateController.CreateDelegateOffer(createProductModel, jwt) as ObjectResult; Assert.NotNull(result); Assert.IsType <OkObjectResult>(result); Assert.Equal(product.Id, ((DelegateOffer)result.Value).Id); }
public async Task CreateProduct_Failed() { const string titleText = "Title Text"; const string descriptionText = "Description Text"; const string jwt = ""; var product = new DelegateOffer { Title = titleText, Description = descriptionText }; var createProductModel = new CreateDelegateOfferModel { Title = "", Description = "" }; _marketplaceRepository.Setup(x => x.CreateDelegateOffer(It.IsAny <DelegateOffer>())).ReturnsAsync(product); var result = await Assert.ThrowsAsync <EmptyFieldException>(() => _marketplaceService.CreateDelegateOffer(createProductModel, jwt)); Assert.NotNull(result); Assert.IsType <EmptyFieldException>(result); }
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> CreateDelegateOffer(CreateDelegateOfferModel creatDelegateOfferModel, string jwt) { if (string.IsNullOrEmpty(creatDelegateOfferModel.Title) || string.IsNullOrEmpty(creatDelegateOfferModel.Description)) { throw new EmptyFieldException(); } var delegateOffer = new DelegateOffer { Id = Guid.NewGuid(), Provider = creatDelegateOfferModel.Provider, Title = creatDelegateOfferModel.Title, Description = creatDelegateOfferModel.Description, Region = creatDelegateOfferModel.Region, LiskPerMonth = creatDelegateOfferModel.LiskPerMonth, AvailableForInMonths = creatDelegateOfferModel.AvailableForInMonths }; var id = _jwtIdClaimReaderHelper.getUserIdFromToken(jwt); if (delegateOffer.Provider.Id != id) { throw new NotAuthenticatedException(); } return(await _delegateRepository.CreateDelegateOffer(delegateOffer)); }
public async Task CreateProduct() { var product = new DelegateOffer { Id = Guid.NewGuid(), Title = "Title Text", Description = "Description Text" }; var result = await _delegateRepository.CreateDelegateOffer(product); Assert.NotNull(result); Assert.Equal(product, result); }
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 GetDelegateOffer_BadRequest() { //Arrange var guid = Guid.NewGuid(); const string titleText = "Title Text"; const string descriptionText = "Description Text"; var product1 = new DelegateOffer() { Id = guid, Title = titleText, Description = descriptionText }; _delegateService.Setup(x => x.GetDelegateOffer(product1.Id)).Throws <OfferNotFoundException>(); //Act var result = await _delegateController.GetDelegateOffer(product1.Id); //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); }
public async Task GetDelegateOffer_Success() { //Arrange var guid = Guid.NewGuid(); const string titleText = "Title Text"; const string descriptionText = "Description Text"; var product1 = new DelegateOffer { Id = guid, Title = titleText, Description = descriptionText }; _delegateService.Setup(x => x.GetDelegateOffer(product1.Id)).ReturnsAsync(product1); //Act var result = await _delegateController.GetDelegateOffer(product1.Id) as ObjectResult; //Assert Assert.NotNull(result); Assert.IsType <OkObjectResult>(result); Assert.Equal(product1.Id, ((DelegateOffer)result.Value).Id); }
public async Task <DelegateOffer> UpdateDelegateOffer(Guid id, DelegateOffer productIn) { await _delegateOffers.ReplaceOneAsync(f => f.Id == id, productIn); return(productIn); }
public async Task <DelegateOffer> CreateDelegateOffer(DelegateOffer product) { await _delegateOffers.InsertOneAsync(product); return(product); }