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