Beispiel #1
0
        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 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 CreateDelegateOffer_BadRequest()
        {
            //Arrange
            var          guid            = Guid.NewGuid();
            const string titleText       = "Title Text";
            const string descriptionText = "Description Text";
            const string jwt             = "";
            var          productModel    = new CreateDAppOfferModel()
            {
                Title       = titleText,
                Description = descriptionText
            };

            _jwtIdClaimReaderHelper.Setup(x => x.getUserIdFromToken(jwt)).Returns(guid);


            _dAppService.Setup(x => x.CreateDAppOffer(productModel, jwt))
            .Throws <EmptyFieldException>();

            //Act
            var result = await _dAppController.CreateDAppOffer(productModel, jwt);

            //Assert
            Assert.NotNull(result);
            Assert.IsType <BadRequestObjectResult>(result);
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        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);
        }
Beispiel #6
0
 public async Task <IActionResult> CreateDAppOffer([FromBody] CreateDAppOfferModel createDAppOfferModel, [FromHeader(Name = "Authorization")] string jwt)
 {
     try
     {
         return(Ok(await _dAppService.CreateDAppOffer(createDAppOfferModel, jwt)));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }