public async Task CreateShouldIncreaseCountOnEmptyCollection() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: "MyTestDb1") .Options; var dbContext = new ApplicationDbContext(options); var repository = new EfDeletableEntityRepository <Vehicle>(dbContext); var service = new VehiclesService(repository); var newVehicle = new Vehicle(); Assert.Equal(0, service.GetAll().Count); await service.Create(newVehicle); Assert.Equal(1, service.GetAll().Count); }
public void GetAllShouldReturnEmptyListOnEmptyRepository() { var repository = new Mock <IDeletableEntityRepository <Vehicle> >(); repository.Setup(r => r.All()).Returns(new List <Vehicle>().AsQueryable()); var service = new VehiclesService(repository.Object); Assert.Equal(0, service.GetAll().Count); }
public async Task DeleteShouldDoNothingOnEmptyCollection() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: "MyTestDb3") .Options; var dbContext = new ApplicationDbContext(options); var repository = new EfDeletableEntityRepository <Vehicle>(dbContext); var service = new VehiclesService(repository); int randomId = 1; await service.Delete(randomId); Assert.Equal(0, service.GetAll().Count); }
public async Task EditShouldDoNothingOnEmptyCollection() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: "MyTestDb6") .Options; var dbContext = new ApplicationDbContext(options); var repository = new EfDeletableEntityRepository <Vehicle>(dbContext); var service = new VehiclesService(repository); var inputModel = new VehicleEditViewModel { Id = 1, }; await service.Edit(inputModel); Assert.Equal(0, service.GetAll().Count); }
public async Task DeleteShouldDoNothingWithNonExistingId() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: "MyTestDb4") .Options; var dbContext = new ApplicationDbContext(options); dbContext.Vehicles.Add(new Vehicle { Id = 1 }); await dbContext.SaveChangesAsync(); var repository = new EfDeletableEntityRepository <Vehicle>(dbContext); var service = new VehiclesService(repository); int nonExistingId = 2; await service.Delete(nonExistingId); Assert.Equal(1, service.GetAll().Count); }
private void ShowList() { lstAutomoviles.DataSource = null; lstAutomoviles.DataSource = service.GetAll(); }