public void TideSite_CRUD_Test() { foreach (CultureInfo culture in AllowableCulture) { ChangeCulture(culture); using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { TideSiteService tideSiteService = new TideSiteService(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] } TideSite tideSite = GetFilledRandomTideSite(""); // ------------------------------- // ------------------------------- // CRUD testing // ------------------------------- // ------------------------------- count = tideSiteService.GetTideSiteList().Count(); Assert.AreEqual(count, (from c in dbTestDB.TideSites select c).Count()); tideSiteService.Add(tideSite); if (tideSite.HasErrors) { Assert.AreEqual("", tideSite.ValidationResults.FirstOrDefault().ErrorMessage); } Assert.AreEqual(true, tideSiteService.GetTideSiteList().Where(c => c == tideSite).Any()); tideSiteService.Update(tideSite); if (tideSite.HasErrors) { Assert.AreEqual("", tideSite.ValidationResults.FirstOrDefault().ErrorMessage); } Assert.AreEqual(count + 1, tideSiteService.GetTideSiteList().Count()); tideSiteService.Delete(tideSite); if (tideSite.HasErrors) { Assert.AreEqual("", tideSite.ValidationResults.FirstOrDefault().ErrorMessage); } Assert.AreEqual(count, tideSiteService.GetTideSiteList().Count()); } } }
public IHttpActionResult Delete([FromBody] TideSite tideSite, [FromUri] string lang = "en") { using (CSSPDBContext db = new CSSPDBContext(DatabaseType)) { TideSiteService tideSiteService = new TideSiteService(new Query() { Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en) }, db, ContactID); if (!tideSiteService.Delete(tideSite)) { return(BadRequest(String.Join("|||", tideSite.ValidationResults))); } else { tideSite.ValidationResults = null; return(Ok(tideSite)); } } }