public void Delete_ThumbnailOptionIds_DeletedThumbnailTasksWithPassedIds() { var taskEntities = ThumbnailTaskEntitysDataSource.ToList(); var ids = taskEntities.Select(t => t.Id).ToArray(); var mock = new Mock <IThumbnailRepository>(); mock.SetupGet(x => x.UnitOfWork).Returns(new Mock <IUnitOfWork>().Object); mock.Setup(r => r.RemoveThumbnailTasksByIds(It.IsIn <string[]>(ids))).Callback( (string[] arr) => { var entities = taskEntities.Where(e => arr.Contains(e.Id)).ToList(); foreach (var entity in entities) { taskEntities.Remove(entity); } }); var sut = new ThumbnailTaskService(() => mock.Object); sut.RemoveByIds(ids); Assert.Empty(taskEntities); }
public Mock <IThumbnailRepository> GetTaskRepositoryMock() { var entites = ThumbnailTaskEntitysDataSource.ToList(); var entitesQuerableMock = TestUtils.CreateQuerableMock(entites); var repoMock = new Mock <IThumbnailRepository>(); repoMock.Setup(x => x.ThumbnailTasks).Returns(entitesQuerableMock.Object); repoMock.Setup(x => x.GetThumbnailTasksByIdsAsync(It.IsAny <string[]>()).Result) .Returns((string[] ids) => { return(entitesQuerableMock.Object.Where(t => ids.Contains(t.Id)).ToArray()); }); return(repoMock); }
public Mock <IThumbnailRepository> GetOptionsRepositoryMock() { var entities = ThumbnailTaskEntitysDataSource.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); }