public async void SubmitInvestmentInvalidInvestmentAmount()
        {
            var createFundingModel = new CreateFundingModel()
            {
                ProjectId        = Guid.NewGuid(),
                InvestorId       = Guid.NewGuid(),
                InvestmentAmount = 10
            };

            var submitInvestmentResult = await _projectsController.SubmitInvestment(createFundingModel);

            Assert.IsType <BadRequestObjectResult>(submitInvestmentResult);
        }
        public async void SubmitInvestmentTest()
        {
            var createFundingModel = new CreateFundingModel()
            {
                ProjectId        = Guid.NewGuid(),
                InvestorId       = Guid.NewGuid(),
                InvestmentAmount = 1000
            };

            _projectService.Setup(x => x.CheckIfTheInvestmentExist(It.IsAny <Funding>())).ReturnsAsync(false);

            var submitInvestmentResult = await _projectsController.SubmitInvestment(createFundingModel);

            Assert.IsType <OkResult>(submitInvestmentResult);
        }
        public async void SubmitInvestmentInvalidInvestmentExist()
        {
            var createFundingModel = new CreateFundingModel()
            {
                ProjectId        = Guid.NewGuid(),
                InvestorId       = Guid.NewGuid(),
                InvestmentAmount = 1000
            };

            var funding = new Funding()
            {
                ProjectId        = createFundingModel.ProjectId,
                InvestorId       = createFundingModel.InvestorId,
                InvestmentAmount = createFundingModel.InvestmentAmount
            };

            _projectService.Setup(x => x.CheckIfTheInvestmentExist(It.IsAny <Funding>())).ReturnsAsync(true);

            var submitInvestmentResult = await _projectsController.SubmitInvestment(createFundingModel);

            Assert.IsType <ConflictObjectResult>(submitInvestmentResult);
        }
Esempio n. 4
0
        public async Task <IActionResult> SubmitInvestment(CreateFundingModel createFundingModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Invalid data."));
            }


            if (createFundingModel.InvestmentAmount < 100 || createFundingModel.InvestmentAmount > 10000)
            {
                return(BadRequest("The investment amount should be between 100 and 10.000"));
            }

            var funding = new Funding()
            {
                ProjectId        = createFundingModel.ProjectId,
                InvestorId       = createFundingModel.InvestorId,
                InvestmentAmount = createFundingModel.InvestmentAmount
            };

            // Check if there is only one investment amount for the project
            if (await _projectService.CheckIfTheInvestmentExist(funding))
            {
                return(Conflict("You can only submit an amount once per funding"));
            }

            try
            {
                await _projectService.SubmitInvestment(funding);
            }
            catch (Exception)
            {
                return(StatusCode(500));
            }

            return(Ok());
        }