public void RatingCurveValue_CRUD_Test() { foreach (CultureInfo culture in AllowableCulture) { ChangeCulture(culture); using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { RatingCurveValueService ratingCurveValueService = new RatingCurveValueService(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] } RatingCurveValue ratingCurveValue = GetFilledRandomRatingCurveValue(""); // ------------------------------- // ------------------------------- // CRUD testing // ------------------------------- // ------------------------------- count = ratingCurveValueService.GetRatingCurveValueList().Count(); Assert.AreEqual(count, (from c in dbTestDB.RatingCurveValues select c).Count()); ratingCurveValueService.Add(ratingCurveValue); if (ratingCurveValue.HasErrors) { Assert.AreEqual("", ratingCurveValue.ValidationResults.FirstOrDefault().ErrorMessage); } Assert.AreEqual(true, ratingCurveValueService.GetRatingCurveValueList().Where(c => c == ratingCurveValue).Any()); ratingCurveValueService.Update(ratingCurveValue); if (ratingCurveValue.HasErrors) { Assert.AreEqual("", ratingCurveValue.ValidationResults.FirstOrDefault().ErrorMessage); } Assert.AreEqual(count + 1, ratingCurveValueService.GetRatingCurveValueList().Count()); ratingCurveValueService.Delete(ratingCurveValue); if (ratingCurveValue.HasErrors) { Assert.AreEqual("", ratingCurveValue.ValidationResults.FirstOrDefault().ErrorMessage); } Assert.AreEqual(count, ratingCurveValueService.GetRatingCurveValueList().Count()); } } }
public IHttpActionResult Put([FromBody] RatingCurveValue ratingCurveValue, [FromUri] string lang = "en") { using (CSSPDBContext db = new CSSPDBContext(DatabaseType)) { RatingCurveValueService ratingCurveValueService = new RatingCurveValueService(new Query() { Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en) }, db, ContactID); if (!ratingCurveValueService.Update(ratingCurveValue)) { return(BadRequest(String.Join("|||", ratingCurveValue.ValidationResults))); } else { ratingCurveValue.ValidationResults = null; return(Ok(ratingCurveValue)); } } }
public void RatingCurveValue_Properties_Test() { foreach (CultureInfo culture in AllowableCulture) { ChangeCulture(culture); using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { RatingCurveValueService ratingCurveValueService = new RatingCurveValueService(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] } count = ratingCurveValueService.GetRatingCurveValueList().Count(); RatingCurveValue ratingCurveValue = GetFilledRandomRatingCurveValue(""); // ------------------------------- // ------------------------------- // Properties testing // ------------------------------- // ------------------------------- // ----------------------------------- // [Key] // Is NOT Nullable // ratingCurveValue.RatingCurveValueID (Int32) // ----------------------------------- ratingCurveValue = null; ratingCurveValue = GetFilledRandomRatingCurveValue(""); ratingCurveValue.RatingCurveValueID = 0; ratingCurveValueService.Update(ratingCurveValue); Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "RatingCurveValueID"), ratingCurveValue.ValidationResults.FirstOrDefault().ErrorMessage); ratingCurveValue = null; ratingCurveValue = GetFilledRandomRatingCurveValue(""); ratingCurveValue.RatingCurveValueID = 10000000; ratingCurveValueService.Update(ratingCurveValue); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "RatingCurveValue", "RatingCurveValueID", ratingCurveValue.RatingCurveValueID.ToString()), ratingCurveValue.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [CSSPExist(ExistTypeName = "RatingCurve", ExistPlurial = "s", ExistFieldID = "RatingCurveID", AllowableTVtypeList = )] // ratingCurveValue.RatingCurveID (Int32) // ----------------------------------- ratingCurveValue = null; ratingCurveValue = GetFilledRandomRatingCurveValue(""); ratingCurveValue.RatingCurveID = 0; ratingCurveValueService.Add(ratingCurveValue); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "RatingCurve", "RatingCurveID", ratingCurveValue.RatingCurveID.ToString()), ratingCurveValue.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [Range(0, 1000)] // ratingCurveValue.StageValue_m (Double) // ----------------------------------- //CSSPError: Type not implemented [StageValue_m] //CSSPError: Type not implemented [StageValue_m] ratingCurveValue = null; ratingCurveValue = GetFilledRandomRatingCurveValue(""); ratingCurveValue.StageValue_m = -1.0D; Assert.AreEqual(false, ratingCurveValueService.Add(ratingCurveValue)); Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "StageValue_m", "0", "1000"), ratingCurveValue.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, ratingCurveValueService.GetRatingCurveValueList().Count()); ratingCurveValue = null; ratingCurveValue = GetFilledRandomRatingCurveValue(""); ratingCurveValue.StageValue_m = 1001.0D; Assert.AreEqual(false, ratingCurveValueService.Add(ratingCurveValue)); Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "StageValue_m", "0", "1000"), ratingCurveValue.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, ratingCurveValueService.GetRatingCurveValueList().Count()); // ----------------------------------- // Is NOT Nullable // [Range(0, 1000000)] // ratingCurveValue.DischargeValue_m3_s (Double) // ----------------------------------- //CSSPError: Type not implemented [DischargeValue_m3_s] //CSSPError: Type not implemented [DischargeValue_m3_s] ratingCurveValue = null; ratingCurveValue = GetFilledRandomRatingCurveValue(""); ratingCurveValue.DischargeValue_m3_s = -1.0D; Assert.AreEqual(false, ratingCurveValueService.Add(ratingCurveValue)); Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "DischargeValue_m3_s", "0", "1000000"), ratingCurveValue.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, ratingCurveValueService.GetRatingCurveValueList().Count()); ratingCurveValue = null; ratingCurveValue = GetFilledRandomRatingCurveValue(""); ratingCurveValue.DischargeValue_m3_s = 1000001.0D; Assert.AreEqual(false, ratingCurveValueService.Add(ratingCurveValue)); Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "DischargeValue_m3_s", "0", "1000000"), ratingCurveValue.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, ratingCurveValueService.GetRatingCurveValueList().Count()); // ----------------------------------- // Is NOT Nullable // [CSSPAfter(Year = 1980)] // ratingCurveValue.LastUpdateDate_UTC (DateTime) // ----------------------------------- ratingCurveValue = null; ratingCurveValue = GetFilledRandomRatingCurveValue(""); ratingCurveValue.LastUpdateDate_UTC = new DateTime(); ratingCurveValueService.Add(ratingCurveValue); Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "LastUpdateDate_UTC"), ratingCurveValue.ValidationResults.FirstOrDefault().ErrorMessage); ratingCurveValue = null; ratingCurveValue = GetFilledRandomRatingCurveValue(""); ratingCurveValue.LastUpdateDate_UTC = new DateTime(1979, 1, 1); ratingCurveValueService.Add(ratingCurveValue); Assert.AreEqual(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "LastUpdateDate_UTC", "1980"), ratingCurveValue.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [CSSPExist(ExistTypeName = "TVItem", ExistPlurial = "s", ExistFieldID = "TVItemID", AllowableTVtypeList = Contact)] // ratingCurveValue.LastUpdateContactTVItemID (Int32) // ----------------------------------- ratingCurveValue = null; ratingCurveValue = GetFilledRandomRatingCurveValue(""); ratingCurveValue.LastUpdateContactTVItemID = 0; ratingCurveValueService.Add(ratingCurveValue); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "LastUpdateContactTVItemID", ratingCurveValue.LastUpdateContactTVItemID.ToString()), ratingCurveValue.ValidationResults.FirstOrDefault().ErrorMessage); ratingCurveValue = null; ratingCurveValue = GetFilledRandomRatingCurveValue(""); ratingCurveValue.LastUpdateContactTVItemID = 1; ratingCurveValueService.Add(ratingCurveValue); Assert.AreEqual(string.Format(CSSPServicesRes._IsNotOfType_, "LastUpdateContactTVItemID", "Contact"), ratingCurveValue.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [NotMapped] // ratingCurveValue.HasErrors (Boolean) // ----------------------------------- // No testing requied // ----------------------------------- // Is NOT Nullable // [NotMapped] // ratingCurveValue.ValidationResults (IEnumerable`1) // ----------------------------------- // No testing requied } } }