public void SalespersonControllerTest_Post_Delete() { Task.Run(async() => { var person = new Salesperson() { Name = "Kyle", LastName = "Matthews" }; var p = await controller.GetAllAsync(); int countOld = p.Count(); await controller.PersistAsync(person); p = await controller.GetAllAsync(); int countNew = p.Count(); Assert.AreNotEqual(countOld, countNew); int id = p.ToList().SingleOrDefault(x => { return(x.Name.Equals(person.Name) && x.LastName.Equals(person.LastName)); }).Id; await controller.DeleteAsync(id); p = await controller.GetAllAsync(); countNew = p.Count(); Assert.AreEqual(countOld, countNew); }).GetAwaiter().GetResult(); }
private async void AddNewSalesperson_Click(object sender, RoutedEventArgs e) { if (ValidateFields()) { MessageBoxResult result = MessageBox.Show($"Do you want to create a new salesperson?\n{NewPersonName.Text} {NewSalespersonLastName.Text}", "New salesperson creation", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result.Equals(MessageBoxResult.Yes)) { Salesperson salesperson = new Salesperson() { Name = NewPersonName.Text, LastName = NewSalespersonLastName.Text }; try { await controller.PersistAsync(salesperson); } catch (ApiException ex) { MessageBox.Show(ex.Message, "API Error", MessageBoxButton.OK, MessageBoxImage.Error); } finally { clearForms(); LoadSalespeople(); } } else { clearForms(); } } else { MessageBox.Show("One or more fields are empty!", "Operation halted", MessageBoxButton.OK, MessageBoxImage.Warning); } }