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