public void GetLatestShouldThrowErrorForInvalidCount(int count) { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: "GetLatestShouldThrowErrorForInvalidCount").Options; var dbContext = new ApplicationDbContext(options); var postsRepo = new EfDeletableEntityRepository <Post>(dbContext); var makesRepo = new EfDeletableEntityRepository <Make>(dbContext); var makesService = new MakesService(makesRepo); var postsService = new PostsService(postsRepo, makesService); Assert.Throws <ArgumentNullException>(() => postsService.GetLatest <PostDetailsViewModel>(count)); }
public async Task GetLatestShouldWork() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: "GetLatestShouldWork").Options; var dbContext = new ApplicationDbContext(options); var postsRepo = new EfDeletableEntityRepository <Post>(dbContext); var makesRepo = new EfDeletableEntityRepository <Make>(dbContext); var makesService = new MakesService(makesRepo); var postsService = new PostsService(postsRepo, makesService); var post1 = new Post() { Id = 1, Name = "random name", Price = 53222, Currency = Currency.LV, Mileage = 25123, Color = new Color(), EngineType = EngineType.Disel, Horsepower = 255, TransmissionType = TransmissionType.Automatic, ManufactureDate = DateTime.Now, Category = new Category(), City = new City(), User = new ApplicationUser(), PhoneNumber = "0897456321", Description = "random descr", Eurostandard = Eurostandard.Five, Condition = Condition.New, VehicleCategory = new VehicleCategory(), }; var post2 = new Post() { Id = 2, Name = "random name", Price = 53222, Currency = Currency.LV, Mileage = 25123, Color = new Color(), EngineType = EngineType.Disel, Horsepower = 255, TransmissionType = TransmissionType.Automatic, ManufactureDate = DateTime.Now, Category = new Category(), City = new City(), User = new ApplicationUser(), PhoneNumber = "0897456321", Description = "random descr", Eurostandard = Eurostandard.Five, Condition = Condition.New, VehicleCategory = new VehicleCategory(), }; await dbContext.Posts.AddAsync(post1); await dbContext.Posts.AddAsync(post2); await dbContext.SaveChangesAsync(); var result = postsService.GetLatest <PostDetailsViewModel>(1); Assert.Single(result); }