public async Task GetAllGenericShouldWork() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: "GetAllGenericShouldWork").Options; var dbContext = new ApplicationDbContext(options); dbContext.Makes.Add(new Make()); dbContext.Makes.Add(new Make()); dbContext.Makes.Add(new Make()); await dbContext.SaveChangesAsync(); var repository = new EfDeletableEntityRepository <Make>(dbContext); var service = new MakesService(repository); Assert.Equal(3, service.GetAll <Make>().Count()); }
public async Task GetAllShouldReturnAllMakes() { var options = new DbContextOptionsBuilder <NeedForCarsDbContext>() .UseInMemoryDatabase("GetAllDb") .Options; var context = new NeedForCarsDbContext(options); var makesService = new MakesService(context); await context.Makes.AddAsync(make1); await context.Makes.AddAsync(make2); await context.SaveChangesAsync(); var result = await makesService.GetAll().CountAsync(); Assert.Equal(2, result); }
public void GetAll_ReturnAllMakes_WhenValidMakeIsPassedAsParameter() { //Arrange var makesRepo = new Mock <IEfRepository <Make> >(); var list = new List <Make>(); var uow = new Mock <IUnitOfWork>(); list.Add(new Make() { Name = "test" }); makesRepo.Setup(u => u.All).Returns(list.AsQueryable); var sut = new MakesService(makesRepo.Object, uow.Object); // Act var name = "test"; var result = sut.GetAll().ToList(); //Assert Assert.AreEqual(name, result[0].Name); }