public async Task <DAppOffer> CreateDAppOffer(CreateDAppOfferModel createDAppOfferModel, string jwt) { if (string.IsNullOrEmpty(createDAppOfferModel.Title) || string.IsNullOrEmpty(createDAppOfferModel.Description)) { throw new EmptyFieldException(); } var offer = new DAppOffer { Id = Guid.NewGuid(), Title = createDAppOfferModel.Title, Provider = createDAppOfferModel.Provider, Description = createDAppOfferModel.Description, OfferLengthInMonths = createDAppOfferModel.OfferLengthInMonths, LiskPerMonth = createDAppOfferModel.LiskPerMonth, DelegatesNeededForOffer = createDAppOfferModel.DelegatesNeededForOffer, DelegatesCurrentlyInOffer = new List <User>(), Region = createDAppOfferModel.Region, DateEnd = createDAppOfferModel.DateEnd, DateStart = createDAppOfferModel.DateStart }; if (offer.Provider.Id != _jwtIdClaimReaderHelper.getUserIdFromToken(jwt)) //authorization { throw new NotAuthenticatedException(); } return(await _dAppRepository.CreateDAppOffer(offer)); }
public async Task DeleteDAppOfferById() { //Arrange var product1 = new DAppOffer { Id = Guid.NewGuid(), Title = "Title1", Description = "Description1" }; var product2 = new DAppOffer { Id = Guid.NewGuid(), Title = "Title2", Description = "Description2" }; await _dAppRepository.CreateDAppOffer(product1); await _dAppRepository.CreateDAppOffer(product2); //Act await _dAppRepository.DeleteDAppOffer(product1.Id); var result = await _dAppRepository.GetDAppOffer(product1.Id); var resultAll = await _dAppRepository.GetAllDAppOffers(); //Assert Assert.Null(result); Assert.NotNull(resultAll); Assert.NotEmpty(resultAll); Assert.Single(resultAll); }
public async Task GetAll() { //Arrange var product1 = new DAppOffer { Id = Guid.NewGuid(), Title = "Title1", Description = "Description Text" }; var product2 = new DAppOffer { Id = Guid.NewGuid(), Title = "Title2", Description = "Description Text" }; await _dAppRepository.CreateDAppOffer(product1); await _dAppRepository.CreateDAppOffer(product2); //Act var result = await _dAppRepository.GetAllDAppOffers(); //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 UpdateDAppOffer() { //Arrange var product1 = new DAppOffer { Id = Guid.NewGuid(), Title = "Title1", Description = "Description1" }; var product2 = new DAppOffer { Id = Guid.NewGuid(), Title = "Title2", Description = "Description2" }; await _dAppRepository.CreateDAppOffer(product1); await _dAppRepository.CreateDAppOffer(product2); //Act product1.Title = "Title1Edited"; await _dAppRepository.UpdateDAppOffer(product1.Id, product1); var result = await _dAppRepository.GetDAppOffer(product1.Id); //Assert Assert.NotNull(result); Assert.Equal(product1.Title, result.Title); }
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 CreateDAppOffer_Success() { var userid = Guid.NewGuid(); const string titleText = "Title Text"; const string descriptionText = "Description Text"; const string jwt = ""; var product = new DAppOffer() { Title = titleText, Description = descriptionText }; var createProductModel = new CreateDAppOfferModel() { Provider = new User { Id = userid }, Title = titleText, Description = descriptionText }; _jwtIdClaimReaderHelper.Setup(x => x.getUserIdFromToken(jwt)).Returns(userid); _dAppService.Setup(x => x.CreateDAppOffer(createProductModel, jwt)).ReturnsAsync(product); var result = await _dAppController.CreateDAppOffer(createProductModel, jwt) as ObjectResult; Assert.NotNull(result); Assert.IsType <OkObjectResult>(result); Assert.Equal(product.Title, ((DAppOffer)result.Value).Title); }
public async Task CreateDAppOffer_Success() { var userid = Guid.NewGuid(); const string titleText = "Title Text"; const string descriptionText = "Description Text"; const string jwt = ""; DAppOffer product = new DAppOffer { Title = titleText, Description = descriptionText, Provider = new User() { Id = userid } }; var createProductModel = new CreateDAppOfferModel { Title = titleText, Description = descriptionText, Provider = new User() { Id = userid } }; _dAppRepository.Setup(x => x.CreateDAppOffer(It.IsAny <DAppOffer>())).ReturnsAsync(product); _jwtIdClaimReaderHelper.Setup(x => x.getUserIdFromToken(jwt)).Returns(userid); var result = await _dAppService.CreateDAppOffer(createProductModel, jwt); Assert.Equal(titleText, result.Title); }
public async Task CreateProduct_Failed() { const string titleText = "Title Text"; const string descriptionText = "Description Text"; const string jwt = ""; var product = new DAppOffer { Title = titleText, Description = descriptionText }; var createProductModel = new CreateDAppOfferModel { Title = "", Description = "" }; _dAppRepository.Setup(x => x.CreateDAppOffer(It.IsAny <DAppOffer>())).ReturnsAsync(product); var result = await Assert.ThrowsAsync <EmptyFieldException>(() => _dAppService.CreateDAppOffer(createProductModel, jwt)); Assert.NotNull(result); Assert.IsType <EmptyFieldException>(result); }
public async Task CreateProduct() { var product = new DAppOffer { Id = Guid.NewGuid(), Title = "Title Text", Description = "Description Text" }; var result = await _dAppRepository.CreateDAppOffer(product); Assert.NotNull(result); Assert.Equal(product, result); }
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 GetDelegateOffer_Success() { //Arrange var guid = Guid.NewGuid(); const string titleText = "Title Text"; const string descriptionText = "Description Text"; var product1 = new DAppOffer { Id = guid, Title = titleText, Description = descriptionText }; _dAppService.Setup(x => x.GetDAppOffer(guid)).ReturnsAsync(product1); //Act var result = await _dAppController.GetDAppOffer(product1.Id) as ObjectResult; //Assert Assert.NotNull(result); Assert.IsType <OkObjectResult>(result); Assert.Equal(product1.Id, ((DAppOffer)result.Value).Id); }
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); }
public async Task <DAppOffer> RemoveDelegateFromDAppOffer(Guid id, DAppOffer offerIn) { await _dAppOffers.ReplaceOneAsync(f => f.Id == id, offerIn); return(offerIn); }
public async Task <DAppOffer> UpdateDAppOffer(Guid id, DAppOffer productIn) { await _dAppOffers.ReplaceOneAsync(f => f.Id == id, productIn); return(productIn); }
public async Task <DAppOffer> CreateDAppOffer(DAppOffer product) { await _dAppOffers.InsertOneAsync(product); return(product); }