Ejemplo n.º 1
0
        private async void DeleteBrandButton_Click(object sender, RoutedEventArgs e)
        {
            if (BrandDataGrid.SelectedItem is Brand br)
            {
                var id = br.Id;
                await _brandService.DeleteAsync(id);

                BrandDataGrid.ItemsSource = await _brandService.GetAllAsync();
            }
        }
        public async Task DeleteAsyncShould_DeleteBrandFromDatabaseById()
        {
            var options = new DbContextOptionsBuilder <TechAndToolsDbContext>()
                          .UseInMemoryDatabase(databaseName: "DeleteAsyncShould_DeleteBrandFromDatabaseById")
                          .Options;

            TechAndToolsDbContext context = new TechAndToolsDbContext(options);

            await SeedData(context);

            IBrandService brandService = new BrandService(context);

            Brand brandFromDb = context.Brands.First();

            bool result = await brandService.DeleteAsync(brandFromDb.Id);

            Assert.True(result);
        }