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