public async Task <IActionResult> Get([FromRoute] GetUserStatisticByQuizQuery query)
        {
            using (var scope = _tracer.BuildSpan("GetUserStatisticByQuizId").StartActive(finishSpanOnDispose: true))
            {
                var response = await _mediator.Send(query);

                if (response == null)
                {
                    return(NotFound($"Statistic for user with ID '{query.UserId}' and quiz id {query.QuizId} was not found."));
                }

                //catch if failure
                return(Ok(response));
            }
        }
Beispiel #2
0
        public async Task GetLastUserStatisticByUserIdAndQuizIdHandler_NotExsistIds_ShouldArgumentNullException()
        {
            //Arrange
            var userId = Guid.NewGuid();
            var quizId = Guid.NewGuid();
            var query  = new GetUserStatisticByQuizQuery()
            {
                UserId = userId,
                QuizId = quizId
            };
            var handler = _autoMocker.CreateInstance <GetUserStatisticByQuizQueryHandler>();

            _userStatisticRepositoryMock.Setup(x => x.GetAllAsync(It.IsAny <ISpecification <UserStatistic> >()))
            .ReturnsAsync(default(List <UserStatistic>));
            //Act
            var result = await Assert.ThrowsAsync <ArgumentNullException>(() => handler.Handle(query, CancellationToken.None));

            //Assert
            Assert.Contains($"User statistic for user id {userId} and quiz id {quizId} not found", result.Message);
        }
Beispiel #3
0
        public async Task GetLastUserStatisticByUserIdAndQuizIdHandler_ExsistIds_ShouldSuccess()
        {
            //Arrange
            var userId = Guid.NewGuid();
            var quizId = Guid.NewGuid();
            var query  = new GetUserStatisticByQuizQuery()
            {
                UserId = userId,
                QuizId = quizId
            };
            var handler = _autoMocker.CreateInstance <GetUserStatisticByQuizQueryHandler>();

            _userStatisticRepositoryMock.Setup(x => x.GetAllAsync(It.IsAny <ISpecification <UserStatistic> >()))
            .ReturnsAsync(GetUserStatisticList(userId));
            _userStatisticServiceMock.Setup(x => x.GetUserStatistic(It.IsAny <UserStatistic>(), It.IsAny <EnglishLevel>()))
            .Returns(GetUserStatisticByQuizView());

            //Act
            var result = await handler.Handle(query, CancellationToken.None);

            //Assert
            Assert.NotNull(result);
        }