Ejemplo n.º 1
0
        public async Task <IActionResult> GetRandomAsync(string level = null)
        {
            int?levelInt = null;

            if (!String.IsNullOrEmpty(level))
            {
                Enum.TryParse(level, true, out ETournamentLevel levelEnum);
                // 0 is default enum value, which is returned if TryParse fails
                if (levelEnum != 0)
                {
                    levelInt = (int?)levelEnum;
                }
                else
                {
                    return(BadRequest());
                }
            }

            QbQuestion question = await _qbQuestionService.GetRandomAsync(levelInt);

            if (question == null)
            {
                return(NotFound());
            }

            QbQuestionResource resource = _mapper.Map <QbQuestion, QbQuestionResource>(question);

            return(Ok(resource));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> DeleteAsync(int id)
        {
            QbQuestionResponse result = await _qbQuestionService.DeleteAsync(id);

            if (!result.Success)
            {
                return(BadRequest(result.Message));
            }

            QbQuestionResource questionResource = _mapper.Map <QbQuestion, QbQuestionResource>(result.QbQuestion);

            return(Ok(questionResource));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> GetAsync(int id)
        {
            QbQuestion question = await _qbQuestionService.GetAsync(id);

            if (question == null)
            {
                return(NotFound());
            }

            QbQuestionResource resource = _mapper.Map <QbQuestion, QbQuestionResource>(question);

            return(Ok(resource));
        }
        public async Task DeleteAsyncSuccessTest()
        {
            // Arrange
            QbQuestion         question          = new QbQuestion();
            QbQuestionResponse response          = new QbQuestionResponse(question);
            IQbQuestionService qbQuestionService = Substitute.For <IQbQuestionService>();

            qbQuestionService.DeleteAsync(Arg.Any <int>()).Returns(response);
            QbQuestionResource resource = new QbQuestionResource();

            mapper.Map <QbQuestion, QbQuestionResource>(Arg.Any <QbQuestion>()).Returns(resource);
            QbQuestionsController controller = new QbQuestionsController(qbQuestionService, mapper);

            // Act
            IActionResult result = await controller.DeleteAsync(1);

            // Assert
            result.Should().BeOfType <OkObjectResult>();
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> PutAsync(int id, [FromBody] SaveQbQuestionResource resource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetErrorMessages()));
            }

            QbQuestion         question = _mapper.Map <SaveQbQuestionResource, QbQuestion>(resource);
            QbQuestionResponse result   = await _qbQuestionService.UpdateAsync(id, question);

            if (!result.Success)
            {
                return(BadRequest(result.Message));
            }

            QbQuestionResource questionResource = _mapper.Map <QbQuestion, QbQuestionResource>(result.QbQuestion);

            return(Ok(questionResource));
        }