Example #1
0
        private ThumbnailTaskSearchService CreateTargetService()
        {
            var entities = ThumbnailTaskEntitiesDataSource.ToList();
            var entitiesQueryableMock = entities.AsQueryable().BuildMock();
            var repoMock = new Mock <IThumbnailRepository>();

            repoMock.Setup(x => x.ThumbnailTasks).Returns(entitiesQueryableMock.Object);

            repoMock.Setup(x => x.GetThumbnailTasksByIdsAsync(It.IsAny <string[]>()))
            .ReturnsAsync((string[] ids) =>
            {
                return(entitiesQueryableMock.Object.Where(t => ids.Contains(t.Id)).ToArray());
            });

            var thumbnailTaskServiceMock = new Mock <IThumbnailTaskService>();

            thumbnailTaskServiceMock.Setup(x => x.GetByIdsAsync(It.IsAny <string[]>()))
            .ReturnsAsync((string[] ids) =>
            {
                return(ThumbnailTaskEntitiesDataSource.Where(entity => ids.Contains(entity.Id))
                       .Select(entity => entity.ToModel(new ThumbnailTask()))
                       .ToArray());
            });

            return(new ThumbnailTaskSearchService(() => repoMock.Object, thumbnailTaskServiceMock.Object));
        }
Example #2
0
        public void Search_SearchByExistingKeyword_TasksFound()
        {
            // Arrange
            var keyword = "NameLong";
            var target  = CreateTargetService();
            var count   = ThumbnailTaskEntitiesDataSource.Count(x => x.Name.Contains(keyword));

            // Act
            var resultTasks = target.SearchAsync(new ThumbnailTaskSearchCriteria {
                Keyword = keyword
            });

            // Assert
            Assert.Equal(resultTasks.Result.Results.Count, count);
        }
Example #3
0
        public void Search_ThumbnailOptionSearchCriteria_ReturnsGenericSearchResponseOfTasksInExpectedOrder()
        {
            // Arrange
            var target   = CreateTargetService();
            var criteria = new ThumbnailTaskSearchCriteria {
                Sort = "Name:desc;WorkPath:desc"
            };
            var expectedTasks = ThumbnailTaskEntitiesDataSource.Select(x => x.ToModel(new ThumbnailTask())).OrderByDescending(t => t.Name).ThenByDescending(t => t.WorkPath).ToArray();

            // Act
            var resultTasks = target.SearchAsync(criteria);

            // Assert
            Assert.Equal(expectedTasks, resultTasks.Result.Results);
        }
Example #4
0
        public void Search_ThumbnailOptionSearchCriteria_ReturnsGenericSearchResponseOfTasksInExpectedOrder()
        {
            var repoMock       = GetOptionsRepositoryMock();
            var optionsService = new ThumbnailOptionService(() => repoMock.Object);

            var target   = new ThumbnailOptionSearchService(() => repoMock.Object, optionsService);
            var criteria = new ThumbnailOptionSearchCriteria {
                Sort = "Name:desc;FileSuffix:desc"
            };
            var resultTasks = target.SearchAsync(criteria).GetAwaiter().GetResult();

            var expectedTasks = ThumbnailTaskEntitiesDataSource.Select(x => x.ToModel(new ThumbnailOption())).OrderByDescending(t => t.Name).ThenByDescending(t => t.FileSuffix).ToArray();

            Assert.Equal(expectedTasks, resultTasks.Results);
        }
Example #5
0
        public Mock <IThumbnailRepository> GetOptionsRepositoryMock()
        {
            var entities = ThumbnailTaskEntitiesDataSource.ToList();
            var entitiesQueryableMock = entities.AsQueryable().BuildMock();
            var repoMock = new Mock <IThumbnailRepository>();

            repoMock.Setup(x => x.ThumbnailOptions).Returns(entitiesQueryableMock.Object);

            repoMock.Setup(x => x.GetThumbnailOptionsByIdsAsync(It.IsAny <string[]>()))
            .Returns((string[] ids) =>
            {
                return(Task.FromResult(entitiesQueryableMock.Object.Where(t => ids.Contains(t.Id)).ToArray()));
            });

            return(repoMock);
        }