public void RatingCurve_CRUD_Test() { foreach (CultureInfo culture in AllowableCulture) { ChangeCulture(culture); using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { RatingCurveService ratingCurveService = new RatingCurveService(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] } RatingCurve ratingCurve = GetFilledRandomRatingCurve(""); // ------------------------------- // ------------------------------- // CRUD testing // ------------------------------- // ------------------------------- count = ratingCurveService.GetRatingCurveList().Count(); Assert.AreEqual(count, (from c in dbTestDB.RatingCurves select c).Count()); ratingCurveService.Add(ratingCurve); if (ratingCurve.HasErrors) { Assert.AreEqual("", ratingCurve.ValidationResults.FirstOrDefault().ErrorMessage); } Assert.AreEqual(true, ratingCurveService.GetRatingCurveList().Where(c => c == ratingCurve).Any()); ratingCurveService.Update(ratingCurve); if (ratingCurve.HasErrors) { Assert.AreEqual("", ratingCurve.ValidationResults.FirstOrDefault().ErrorMessage); } Assert.AreEqual(count + 1, ratingCurveService.GetRatingCurveList().Count()); ratingCurveService.Delete(ratingCurve); if (ratingCurve.HasErrors) { Assert.AreEqual("", ratingCurve.ValidationResults.FirstOrDefault().ErrorMessage); } Assert.AreEqual(count, ratingCurveService.GetRatingCurveList().Count()); } } }
public IHttpActionResult Put([FromBody] RatingCurve ratingCurve, [FromUri] string lang = "en") { using (CSSPDBContext db = new CSSPDBContext(DatabaseType)) { RatingCurveService ratingCurveService = new RatingCurveService(new Query() { Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en) }, db, ContactID); if (!ratingCurveService.Update(ratingCurve)) { return(BadRequest(String.Join("|||", ratingCurve.ValidationResults))); } else { ratingCurve.ValidationResults = null; return(Ok(ratingCurve)); } } }
public void RatingCurve_Properties_Test() { foreach (CultureInfo culture in AllowableCulture) { ChangeCulture(culture); using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { RatingCurveService ratingCurveService = new RatingCurveService(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 = ratingCurveService.GetRatingCurveList().Count(); RatingCurve ratingCurve = GetFilledRandomRatingCurve(""); // ------------------------------- // ------------------------------- // Properties testing // ------------------------------- // ------------------------------- // ----------------------------------- // [Key] // Is NOT Nullable // ratingCurve.RatingCurveID (Int32) // ----------------------------------- ratingCurve = null; ratingCurve = GetFilledRandomRatingCurve(""); ratingCurve.RatingCurveID = 0; ratingCurveService.Update(ratingCurve); Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "RatingCurveID"), ratingCurve.ValidationResults.FirstOrDefault().ErrorMessage); ratingCurve = null; ratingCurve = GetFilledRandomRatingCurve(""); ratingCurve.RatingCurveID = 10000000; ratingCurveService.Update(ratingCurve); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "RatingCurve", "RatingCurveID", ratingCurve.RatingCurveID.ToString()), ratingCurve.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [CSSPExist(ExistTypeName = "HydrometricSite", ExistPlurial = "s", ExistFieldID = "HydrometricSiteID", AllowableTVtypeList = )] // ratingCurve.HydrometricSiteID (Int32) // ----------------------------------- ratingCurve = null; ratingCurve = GetFilledRandomRatingCurve(""); ratingCurve.HydrometricSiteID = 0; ratingCurveService.Add(ratingCurve); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "HydrometricSite", "HydrometricSiteID", ratingCurve.HydrometricSiteID.ToString()), ratingCurve.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [StringLength(50))] // ratingCurve.RatingCurveNumber (String) // ----------------------------------- ratingCurve = null; ratingCurve = GetFilledRandomRatingCurve("RatingCurveNumber"); Assert.AreEqual(false, ratingCurveService.Add(ratingCurve)); Assert.AreEqual(1, ratingCurve.ValidationResults.Count()); Assert.IsTrue(ratingCurve.ValidationResults.Where(c => c.ErrorMessage == string.Format(CSSPServicesRes._IsRequired, "RatingCurveNumber")).Any()); Assert.AreEqual(null, ratingCurve.RatingCurveNumber); Assert.AreEqual(count, ratingCurveService.GetRatingCurveList().Count()); ratingCurve = null; ratingCurve = GetFilledRandomRatingCurve(""); ratingCurve.RatingCurveNumber = GetRandomString("", 51); Assert.AreEqual(false, ratingCurveService.Add(ratingCurve)); Assert.AreEqual(string.Format(CSSPServicesRes._MaxLengthIs_, "RatingCurveNumber", "50"), ratingCurve.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, ratingCurveService.GetRatingCurveList().Count()); // ----------------------------------- // Is NOT Nullable // [CSSPAfter(Year = 1980)] // ratingCurve.LastUpdateDate_UTC (DateTime) // ----------------------------------- ratingCurve = null; ratingCurve = GetFilledRandomRatingCurve(""); ratingCurve.LastUpdateDate_UTC = new DateTime(); ratingCurveService.Add(ratingCurve); Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "LastUpdateDate_UTC"), ratingCurve.ValidationResults.FirstOrDefault().ErrorMessage); ratingCurve = null; ratingCurve = GetFilledRandomRatingCurve(""); ratingCurve.LastUpdateDate_UTC = new DateTime(1979, 1, 1); ratingCurveService.Add(ratingCurve); Assert.AreEqual(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "LastUpdateDate_UTC", "1980"), ratingCurve.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [CSSPExist(ExistTypeName = "TVItem", ExistPlurial = "s", ExistFieldID = "TVItemID", AllowableTVtypeList = Contact)] // ratingCurve.LastUpdateContactTVItemID (Int32) // ----------------------------------- ratingCurve = null; ratingCurve = GetFilledRandomRatingCurve(""); ratingCurve.LastUpdateContactTVItemID = 0; ratingCurveService.Add(ratingCurve); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "LastUpdateContactTVItemID", ratingCurve.LastUpdateContactTVItemID.ToString()), ratingCurve.ValidationResults.FirstOrDefault().ErrorMessage); ratingCurve = null; ratingCurve = GetFilledRandomRatingCurve(""); ratingCurve.LastUpdateContactTVItemID = 1; ratingCurveService.Add(ratingCurve); Assert.AreEqual(string.Format(CSSPServicesRes._IsNotOfType_, "LastUpdateContactTVItemID", "Contact"), ratingCurve.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [NotMapped] // ratingCurve.HasErrors (Boolean) // ----------------------------------- // No testing requied // ----------------------------------- // Is NOT Nullable // [NotMapped] // ratingCurve.ValidationResults (IEnumerable`1) // ----------------------------------- // No testing requied } } }