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