Пример #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));
        }
        public async Task GetRandomAsyncFailureTest()
        {
            // Arrange
            IQbQuestionService qbQuestionService = Substitute.For <IQbQuestionService>();
            QbQuestion         question          = null;

            qbQuestionService.GetRandomAsync(Arg.Any <int?>()).Returns(question);
            QbQuestionsController controller = new QbQuestionsController(qbQuestionService, mapper);

            // Act
            IActionResult result = await controller.GetRandomAsync(null);

            // Assert
            result.Should().BeOfType <NotFoundResult>();
        }