internal static IRepository<UserRating> DummyUserRatingsRepository() { var repo = new Mock<IRepository<UserRating>>(); var ratings = new List<UserRating>(); for (int i = 0; i < NumberOfTestObjects; i++) { ratings.Add(new UserRating { Id = i, ClientId = "TestId" + i, HitmanId = "TestId" + (i % 2 == 0 ? i : 3), Rating = i % 6 }); } repo.Setup(r => r.All()).Returns(() => { return ratings.AsQueryable(); }); repo.Setup(r => r.SaveChanges()).Returns(ratings.Last().Id); repo.Setup(r => r.Add(It.IsAny<UserRating>())).Callback<UserRating>(ur => { ur.Id = ratings.LastOrDefault().Id + 1; ratings.Add(ur); }); return repo.Object; }
internal static IRepository<Image> DummyImagesRepository() { var repository = new Mock<IRepository<Image>>(); var images = new List<Image>(); for (int i = 0; i < NumberOfTestObjects; i++) { var user = DummyHitmenRepository() .All() .FirstOrDefault(u => u.Id == i.ToString()); images.Add(new Image() { Id = i, Name = "Image #" + i, Extension = ".png", UserId = user.Id, User = user }); } repository.Setup(r => r.All()).Returns(() => { return images.AsQueryable(); }); repository .Setup(r => r.Add(It.IsAny<Image>())) .Callback<Image>(i => { i.Id = images.LastOrDefault().Id + 1; images.Add(i); }); repository.Setup(r => r.SaveChanges()).Returns(images.Last().Id); repository .Setup(r => r.Delete(It.IsAny<Image>())) .Callback<Image>(i => { images.RemoveAt(i.Id); }); return repository.Object; }