private void Btn_delete(object sender, RoutedEventArgs e) { try { Package selectedPackage = (Package)packageDatagrid.SelectedItems[0]; PLC.DeletePackageById(selectedPackage.Id); LoadSearch(); packageDatagrid.ItemsSource = packageList; CalculateTotals(); packageDatagrid.Items.Refresh(); } catch (Exception exception) { MessageBoxResult result = MessageBox.Show("Der opstod et problem med at slette pakken. \n\n" + exception, "Error!"); } }
public void CanDeletePackagesById() { //Since we know the list only contains 21 packages, and all Ids are unique, we know that all Ids are numbers from 1-21 Random rnd = new Random(); int randomId = rnd.Next(1, 21); bool packageExists = false; _PackageListController.DeletePackageById(randomId); packageList = _PackageListController.ReturnPackageList(); foreach (Package package in packageList) { if (Convert.ToInt32(package.Id) == randomId) { packageExists = true; } } Assert.IsFalse(packageExists); }