示例#1
0
        public async System.Threading.Tasks.Task TestCreateValidAsync()
        {
            // Arrange
            var mockTest   = new Mock <ProjectSpeedy.Services.IServiceBase>();
            var betService = new ProjectSpeedy.Services.BetFeedback(mockTest.Object);
            var form       = new ProjectSpeedy.Models.BetFeedback.BetFeedbackNewUpdate()
            {
                Comment = "feedback"
            };

            mockTest.Setup(d => d.DocumentCreate(It.IsAny <ProjectSpeedy.Models.BetFeedback.BetFeedbackNewUpdate>(), ProjectSpeedy.Services.BetFeedback.PARTITION))
            .Returns(Task.FromResult("TestNewId"));

            // Act
            var test = await betService.CreateAsync("ProjectId", "ProblemId", "BetId", form);

            // Assert
            Assert.AreEqual(true, test);
        }
示例#2
0
        public async System.Threading.Tasks.Task <ActionResult> PutAsync(string projectId, string problemId, string betId, ProjectSpeedy.Models.BetFeedback.BetFeedbackNewUpdate form)
        {
            try
            {
                // Checks we have a valid request.
                if (form == null || !ModelState.IsValid)
                {
                    return(this.BadRequest());
                }

                // Gets the problem and checks the project id / bet id is valid against it.
                var problem = await this._problemServices.GetAsync(projectId, problemId);

                if (problem.ProjectId != ProjectSpeedy.Services.Project.PREFIX + projectId ||
                    !problem.Bets.Any(b => b.Id == ProjectSpeedy.Services.Bet.PREFIX + betId))
                {
                    return(this.NotFound());
                }

                // Tries to add the comment
                if (await this._betFeedback.CreateAsync(projectId, problemId, betId, form))
                {
                    return(this.Accepted());
                }

                // If we get here something has gone wrong.
                return(this.Problem());
            }
            catch (HttpRequestException e)
            {
                // Can we find the problem.
                if (e.StatusCode == System.Net.HttpStatusCode.NotFound)
                {
                    return(NotFound());
                }

                // There has been a problem loading or saving data.
                this._logger.LogError(e, e.Message);
                return(this.Problem());
            }
            catch (Exception e)
            {
                this._logger.LogError(e, e.Message);
                return(this.Problem());
            }
        }