Esempio n. 1
0
        public void Merge()
        {
            //Arrange
            var merger             = Merger();
            var accommodationItems = new ResultWithTotalCount <AccommodationItem>()
            {
                Result = new[]
                {
                    new AccommodationItem
                    {
                        Id = 1
                    },
                }
            };


            var accommodationPhotos = new[]
            {
                new AccommodationPhoto
                {
                    AccommodationId = 1,
                    Path            = "Path",
                    Name            = "Name",
                    Extension       = "Extension"
                },
            };

            //Act
            var merge  = merger.Merge(accommodationItems, accommodationPhotos);
            var result = merge.Result.FirstOrDefault()?.Photo;

            //Assert
            Assert.IsTrue(result != null && result == "https://i.travelapi.com/hotels/Path/Name_l.Extension");
        }
Esempio n. 2
0
        public void Instance_Implement_Interface_IResultWithTotalCount()
        {
            //Arrange
            var type = typeof(IResultWithTotalCount <object>);

            //Act
            var pagedResult = new ResultWithTotalCount <object>();

            //Assert
            Assert.IsInstanceOf(type, pagedResult);
        }
Esempio n. 3
0
        public void TotalCount()
        {
            //Arrange
            var result = new ResultWithTotalCount <int>()
            {
                TotalCount = 100
            };

            //Act
            var totalCount = result.TotalCount;

            //Assert
            Assert.IsInstanceOf <int>(totalCount);
        }
Esempio n. 4
0
        public void Result()
        {
            //Arrange
            var result = new ResultWithTotalCount <object>()
            {
                Result = new[] { new object(), }
            };

            //Act
            var objects = result.Result;

            //Assert
            Assert.IsInstanceOf <object[]>(objects);
        }
        public override async Task <IResultWithTotalCount <AccommodationItem> > HandleAsync(PagedAccommodationItemsByLanguageIdQuery query, CancellationToken cancellationToken)
        {
            var localizedAccommodations = PreHandle(Source, query);
            var accommodationItems      = ProjectTo <AccommodationItem>(localizedAccommodations);

            var result = new ResultWithTotalCount <AccommodationItem>
            {
                Result = await accommodationItems.Skip(query.Paging.CalculateSkip()).Take(query.Paging.PageSize).ToArrayAsync(cancellationToken),

                TotalCount = await accommodationItems.CountAsync(cancellationToken)
            };

            return(result);
        }
Esempio n. 6
0
        public override IResultWithTotalCount <AccommodationItem> Handle(GetPagedAccommodationItems query)
        {
            var localizedAccommodations = PreHandle(Source, query);

            var accommodationItems = ProjectTo <AccommodationItem>(localizedAccommodations);

            var result = new ResultWithTotalCount <AccommodationItem>
            {
                Result = accommodationItems.Skip(query.Paging.CalculateSkip()).Take(query.Paging.PageSize).ToArray(),

                TotalCount = accommodationItems.Count()
            };

            return(result);
        }
Esempio n. 7
0
        public override async Task <IResultWithTotalCount <UnansweredQuestionDto> > HandleAsync(PagedUnansweredQuestionsQuery query, CancellationToken token)
        {
            var questions = await Session.QueryOver <Question>().Where(p => p.DateAnswered == null)
                            .OrderBy(p => p.DateCreated).Desc.Skip(query.Paging.CalculateSkip()).Take(query.Paging.PageSize)
                            .ListAsync(token);

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

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

            return(result);
        }
        public override async Task <IResultWithTotalCount <UnansweredQuestionDto> > HandleAsync(PagedUnansweredQuestionsQuery query, CancellationToken token)
        {
            var unansweredQuestions = Entities().Include(x => x.Category)
                                      .Where(x => !x.DateAnswered.HasValue)
                                      .OrderByDescending(x => x.DateCreated);

            var unansweredQuestionsDataTransferObjects = ProjectTo <UnansweredQuestionDto>(unansweredQuestions);

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

                TotalCount = await unansweredQuestionsDataTransferObjects.CountAsync(token)
            };

            return(result);
        }
Esempio n. 9
0
        private static AccommodationService AccommodationsService()
        {
            var queryDispatcher = new Mock <IQueryDispatcher>();

            queryDispatcher.Setup(p => p.Dispatch(It.IsAny <AccommodationDetailByAccommodationIdAndLanguageIdQuery>()))
            .Returns(new AccommodationDetail());



            var items = new[]
            {
                new AccommodationItem
                {
                    Id = 1
                }
            };

            var result = new ResultWithTotalCount <AccommodationItem>()
            {
                Result = items
            };

            queryDispatcher.Setup(p => p.Dispatch(It.IsAny <PagedAccommodationItemsByLanguageIdQuery>())).Returns(result);

            var providerMock = new Mock <IQueryDispatcher>();



            var queryFactoryMock = new Mock <IQueryFactory>();

            queryFactoryMock.Setup(p => p.Get <AccommodationDetailByAccommodationIdAndLanguageIdQuery>())
            .Returns(new AccommodationDetailByAccommodationIdAndLanguageIdQuery(queryDispatcher.Object));

            queryFactoryMock.Setup(p => p.Get <PagedAccommodationItemsByLanguageIdQuery>())
            .Returns(new PagedAccommodationItemsByLanguageIdQuery(queryDispatcher.Object));

            queryFactoryMock.Setup(p => p.Get <PhotosOfAccommodationsByAccommodationIdsQuery>())
            .Returns(new PhotosOfAccommodationsByAccommodationIdsQuery(queryDispatcher.Object));

            queryFactoryMock.Setup(p => p.Get <AccommodationSuggestionsQuery>())
            .Returns(new AccommodationSuggestionsQuery(queryDispatcher.Object));

            var mockMerger = new AccommodationItemPhotoMerge();

            return(new AccommodationService(queryFactoryMock.Object, mockMerger));
        }
Esempio n. 10
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);
        }
Esempio n. 11
0
        private static AccommodationsFacade CreateAccommodationsFacade()
        {
            var queryDispatcher = new Mock <IProvider>();

            queryDispatcher.Setup(p => p.Execute(It.IsAny <GetAccommodationDetailById>()))
            .Returns(new AccommodationDetail());

            var items = new[]
            {
                new AccommodationItem
                {
                    Id = 1
                }
            };

            var result = new ResultWithTotalCount <AccommodationItem>()
            {
                Result = items
            };

            queryDispatcher.Setup(p => p.Execute(It.IsAny <GetPagedAccommodationItems>())).Returns(result);

            var providerMock = new Mock <IProvider>();

            providerMock.Setup(p => p.Create <GetAccommodationDetailById>())
            .Returns(new GetAccommodationDetailById(queryDispatcher.Object));

            providerMock.Setup(p => p.Create <GetPagedAccommodationItems>())
            .Returns(new GetPagedAccommodationItems(queryDispatcher.Object));

            providerMock.Setup(p => p.Create <GetPhotosOfAccommodations>())
            .Returns(new GetPhotosOfAccommodations(queryDispatcher.Object));

            var mockMerger = new AccommodationItemPhotoMerge();

            return(new AccommodationsFacade(providerMock.Object, mockMerger));
        }