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