private static PagedAnsweredQuestionsQuery PagedAnsweredQuestionsQuery()
        {
            var queryDispatcherMock = new Mock <IQueryDispatcher>();
            var query = new PagedAnsweredQuestionsQuery(queryDispatcherMock.Object);

            return(query);
        }
Exemple #2
0
        public void HandleAsync_Returns_Task_Of_IResultWithTotalCount_Of_AnsweredQuestionDto()
        {
            //Arrange
            var handler        = PagedAnsweredQuestionsQueryHandler();
            var dispatcherMock = new Mock <IQueryDispatcher>();
            var query          = new PagedAnsweredQuestionsQuery(dispatcherMock.Object);

            //Act
            var result = handler.HandleAsync(query);

            //Assert
            Assert.IsInstanceOf <Task <IResultWithTotalCount <QuestionDto> > >(result);
        }
        public override async Task <IResultWithTotalCount <QuestionDto> > HandleAsync(PagedAnsweredQuestionsQuery query, CancellationToken token)
        {
            var answeredQuestions = Entities().Include(x => x.Category)
                                    .Where(x => x.DateAnswered.HasValue)
                                    .OrderByDescending(x => x.DateAnswered);

            var answeredQuestionsDataTransferObjects = ProjectTo <QuestionDto>(answeredQuestions);

            var result = new ResultWithTotalCount <QuestionDto>
            {
                Result = await answeredQuestionsDataTransferObjects.Skip(query.Paging.CalculateSkip()).Take(query.Paging.PageSize).ToArrayAsync(token),

                TotalCount = await answeredQuestionsDataTransferObjects.CountAsync(token)
            };

            return(result);
        }
Exemple #4
0
        public override async Task <IResultWithTotalCount <QuestionDto> > HandleAsync(PagedAnsweredQuestionsQuery query, CancellationToken token)
        {
            //const string sql = @"SELECT Questions.Id, Questions.DateCreated, Questions.DateAnswered, Questions.QuestionText, Questions.DisplayName, Questions.EmailAddress, Questions.AnswerText, Categories.Name AS CategoryName
            //FROM Questions INNER JOIN
            //Categories ON Questions.CategoryId = Categories.Id
            //WHERE(NOT(Questions.DateAnswered IS NULL))
            //ORDER BY Questions.DateAnswered DESC LIMIT @Take OFFSET @Skip;

            //SELECT count(id) FROM Questions WHERE (NOT (Questions.DateAnswered IS NULL))";


            const string sql = @"SELECT Questions.Id, Questions.DateCreated, Questions.DateAnswered, Questions.QuestionText, Questions.DisplayName, Questions.EmailAddress, Questions.AnswerText, Categories.Name AS CategoryName
            FROM Questions INNER JOIN
            Categories ON Questions.CategoryId = Categories.Id
            WHERE(NOT(Questions.DateAnswered IS NULL))
            ORDER BY Questions.DateAnswered DESC OFFSET @Skip ROWS FETCH NEXT @Take ROWS ONLY;

            SELECT count(id) FROM Questions WHERE (NOT (Questions.DateAnswered IS NULL))";


            IResultWithTotalCount <QuestionDto> result;

            using (var connection = GetConnection())
            {
                using (var multi = connection.QueryMultipleAsync(sql, new { Take = query.Paging.PageSize, Skip = query.Paging.CalculateSkip() }).Result)
                {
                    result = new ResultWithTotalCount <QuestionDto>
                    {
                        Result = (await multi.ReadAsync <QuestionDto>()).ToArray(),


                        // SQLite TotalCount = (int) await multi.ReadFirstAsync<long>()

                        TotalCount = await multi.ReadFirstAsync <int>()
                    };
                }
            }

            return(result);
        }
Exemple #5
0
        public override async Task <IResultWithTotalCount <QuestionDto> > HandleAsync(PagedAnsweredQuestionsQuery query, CancellationToken token)
        {
            var questions = await Session.QueryOver <Question>().Where(p => p.DateAnswered != null)
                            .OrderBy(p => p.DateAnswered).Desc.Skip(query.Paging.CalculateSkip()).Take(query.Paging.PageSize)
                            .ListAsync(token);

            var result = new ResultWithTotalCount <QuestionDto>
            {
                Result = MapTo <QuestionDto[]>(questions),

                TotalCount = await Session.QueryOver <Question>().Where(p => p.DateAnswered != null).RowCountAsync(token)
            };

            return(result);
        }