public void SpillLanguage_CRUD_Test() { foreach (CultureInfo culture in AllowableCulture) { ChangeCulture(culture); using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { SpillLanguageService spillLanguageService = new SpillLanguageService(new Query() { Lang = culture.TwoLetterISOLanguageName }, dbTestDB, ContactID); int count = 0; if (count == 1) { // just so we don't get a warning during compile [The variable 'count' is assigned but its value is never used] } SpillLanguage spillLanguage = GetFilledRandomSpillLanguage(""); // ------------------------------- // ------------------------------- // CRUD testing // ------------------------------- // ------------------------------- count = spillLanguageService.GetSpillLanguageList().Count(); Assert.AreEqual(count, (from c in dbTestDB.SpillLanguages select c).Count()); spillLanguageService.Add(spillLanguage); if (spillLanguage.HasErrors) { Assert.AreEqual("", spillLanguage.ValidationResults.FirstOrDefault().ErrorMessage); } Assert.AreEqual(true, spillLanguageService.GetSpillLanguageList().Where(c => c == spillLanguage).Any()); spillLanguageService.Update(spillLanguage); if (spillLanguage.HasErrors) { Assert.AreEqual("", spillLanguage.ValidationResults.FirstOrDefault().ErrorMessage); } Assert.AreEqual(count + 1, spillLanguageService.GetSpillLanguageList().Count()); spillLanguageService.Delete(spillLanguage); if (spillLanguage.HasErrors) { Assert.AreEqual("", spillLanguage.ValidationResults.FirstOrDefault().ErrorMessage); } Assert.AreEqual(count, spillLanguageService.GetSpillLanguageList().Count()); } } }
public IHttpActionResult Delete([FromBody] SpillLanguage spillLanguage, [FromUri] string lang = "en") { using (CSSPDBContext db = new CSSPDBContext(DatabaseType)) { SpillLanguageService spillLanguageService = new SpillLanguageService(new Query() { Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en) }, db, ContactID); if (!spillLanguageService.Delete(spillLanguage)) { return(BadRequest(String.Join("|||", spillLanguage.ValidationResults))); } else { spillLanguage.ValidationResults = null; return(Ok(spillLanguage)); } } }