public void DeleteCountryTest() { // Get a test user var user = GetTestUser(); // Create a record var model = createCountry(); var error = LookupService.InsertOrUpdateCountry(model, user, ""); Assert.IsTrue(!error.IsError, error.Message); // Check that it was written var result = db.FindCountry(model.Id); var test = LookupService.MapToModel(result); AreEqual(model, test); // Now delete it LookupService.DeleteCountry(model.Id); // And check that is was deleted result = db.FindCountry(model.Id); Assert.IsTrue(result == null, "Error: A non-NULL value was returned when a NULL value was expected - record delete failed"); }
public ActionResult Delete(int index, int id) { var model = new CountryListModel(); model.GridIndex = index; try { LookupService.DeleteCountry(id); } catch (Exception e1) { model.Error.SetError(e1); } return(Json(model, JsonRequestBehavior.AllowGet)); }
public void FindCountriesListModelTest() { var user = GetTestUser(); var model = LookupService.FindCountriesListModel(0, 1, PageSize, ""); var dbData = db.FindCountries(); int expected = dbData.Count(), actual = model.Items.Count(); Assert.IsTrue(actual == expected, $"Error: {actual} items were found when {expected} were expected"); // Check that all the items match foreach (var item in model.Items) { var dbItem = dbData.Where(m => m.Id == item.Id).FirstOrDefault(); Assert.IsTrue(dbItem != null, "Error: Model item not found in db item list"); var temp = LookupService.MapToModel(dbItem); AreEqual(item, temp); } // Add another item a make sure it is found var newItem = createCountry(); var error = LookupService.InsertOrUpdateCountry(newItem, user, ""); Assert.IsTrue(!error.IsError, $"Error: {error.Message}"); model = LookupService.FindCountriesListModel(0, 1, PageSize, ""); var testItem = model.Items.Where(i => i.Id == newItem.Id).FirstOrDefault(); Assert.IsTrue(testItem != null, "Error: A NULL value was returned when a non-NULL value was expected"); // Delete it and make sure it disappears LookupService.DeleteCountry(newItem.Id); model = LookupService.FindCountriesListModel(0, 1, PageSize, ""); testItem = model.Items.Where(i => i.Id == newItem.Id).FirstOrDefault(); Assert.IsTrue(testItem == null, "Error: A non-NULL value was returned when a NULL value was expected"); }