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