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