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)); }
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); }