private void btnBorrar_Click(object sender, EventArgs e)
 {
     if (lstAutomoviles.SelectedIndex != -1)
     {
         Vehicle selected = (Vehicle)lstAutomoviles.SelectedItem;
         service.Delete(selected);
         ShowList();
     }
 }
示例#2
0
        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);
        }
示例#3
0
        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);
        }