public void Classification_CRUD_Test() { foreach (CultureInfo culture in AllowableCulture) { ChangeCulture(culture); using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { ClassificationService classificationService = new ClassificationService(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] } Classification classification = GetFilledRandomClassification(""); // ------------------------------- // ------------------------------- // CRUD testing // ------------------------------- // ------------------------------- count = classificationService.GetClassificationList().Count(); Assert.AreEqual(count, (from c in dbTestDB.Classifications select c).Count()); classificationService.Add(classification); if (classification.HasErrors) { Assert.AreEqual("", classification.ValidationResults.FirstOrDefault().ErrorMessage); } Assert.AreEqual(true, classificationService.GetClassificationList().Where(c => c == classification).Any()); classificationService.Update(classification); if (classification.HasErrors) { Assert.AreEqual("", classification.ValidationResults.FirstOrDefault().ErrorMessage); } Assert.AreEqual(count + 1, classificationService.GetClassificationList().Count()); classificationService.Delete(classification); if (classification.HasErrors) { Assert.AreEqual("", classification.ValidationResults.FirstOrDefault().ErrorMessage); } Assert.AreEqual(count, classificationService.GetClassificationList().Count()); } } }
public IHttpActionResult Post([FromBody] Classification classification, [FromUri] string lang = "en") { using (CSSPDBContext db = new CSSPDBContext(DatabaseType)) { ClassificationService classificationService = new ClassificationService(new Query() { Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en) }, db, ContactID); if (!classificationService.Add(classification)) { return(BadRequest(String.Join("|||", classification.ValidationResults))); } else { classification.ValidationResults = null; return(Created <Classification>(new Uri(Request.RequestUri, classification.ClassificationID.ToString()), classification)); } } }
public void Classification_Properties_Test() { foreach (CultureInfo culture in AllowableCulture) { ChangeCulture(culture); using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { ClassificationService classificationService = new ClassificationService(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 = classificationService.GetClassificationList().Count(); Classification classification = GetFilledRandomClassification(""); // ------------------------------- // ------------------------------- // Properties testing // ------------------------------- // ------------------------------- // ----------------------------------- // [Key] // Is NOT Nullable // classification.ClassificationID (Int32) // ----------------------------------- classification = null; classification = GetFilledRandomClassification(""); classification.ClassificationID = 0; classificationService.Update(classification); Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "ClassificationID"), classification.ValidationResults.FirstOrDefault().ErrorMessage); classification = null; classification = GetFilledRandomClassification(""); classification.ClassificationID = 10000000; classificationService.Update(classification); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "Classification", "ClassificationID", classification.ClassificationID.ToString()), classification.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [CSSPExist(ExistTypeName = "TVItem", ExistPlurial = "s", ExistFieldID = "TVItemID", AllowableTVtypeList = Classification)] // classification.ClassificationTVItemID (Int32) // ----------------------------------- classification = null; classification = GetFilledRandomClassification(""); classification.ClassificationTVItemID = 0; classificationService.Add(classification); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "ClassificationTVItemID", classification.ClassificationTVItemID.ToString()), classification.ValidationResults.FirstOrDefault().ErrorMessage); classification = null; classification = GetFilledRandomClassification(""); classification.ClassificationTVItemID = 1; classificationService.Add(classification); Assert.AreEqual(string.Format(CSSPServicesRes._IsNotOfType_, "ClassificationTVItemID", "Classification"), classification.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [CSSPEnumType] // classification.ClassificationType (ClassificationTypeEnum) // ----------------------------------- classification = null; classification = GetFilledRandomClassification(""); classification.ClassificationType = (ClassificationTypeEnum)1000000; classificationService.Add(classification); Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "ClassificationType"), classification.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [Range(0, 10000)] // classification.Ordinal (Int32) // ----------------------------------- classification = null; classification = GetFilledRandomClassification(""); classification.Ordinal = -1; Assert.AreEqual(false, classificationService.Add(classification)); Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "Ordinal", "0", "10000"), classification.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, classificationService.GetClassificationList().Count()); classification = null; classification = GetFilledRandomClassification(""); classification.Ordinal = 10001; Assert.AreEqual(false, classificationService.Add(classification)); Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "Ordinal", "0", "10000"), classification.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, classificationService.GetClassificationList().Count()); // ----------------------------------- // Is NOT Nullable // [CSSPAfter(Year = 1980)] // classification.LastUpdateDate_UTC (DateTime) // ----------------------------------- classification = null; classification = GetFilledRandomClassification(""); classification.LastUpdateDate_UTC = new DateTime(); classificationService.Add(classification); Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "LastUpdateDate_UTC"), classification.ValidationResults.FirstOrDefault().ErrorMessage); classification = null; classification = GetFilledRandomClassification(""); classification.LastUpdateDate_UTC = new DateTime(1979, 1, 1); classificationService.Add(classification); Assert.AreEqual(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "LastUpdateDate_UTC", "1980"), classification.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [CSSPExist(ExistTypeName = "TVItem", ExistPlurial = "s", ExistFieldID = "TVItemID", AllowableTVtypeList = Contact)] // classification.LastUpdateContactTVItemID (Int32) // ----------------------------------- classification = null; classification = GetFilledRandomClassification(""); classification.LastUpdateContactTVItemID = 0; classificationService.Add(classification); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "LastUpdateContactTVItemID", classification.LastUpdateContactTVItemID.ToString()), classification.ValidationResults.FirstOrDefault().ErrorMessage); classification = null; classification = GetFilledRandomClassification(""); classification.LastUpdateContactTVItemID = 1; classificationService.Add(classification); Assert.AreEqual(string.Format(CSSPServicesRes._IsNotOfType_, "LastUpdateContactTVItemID", "Contact"), classification.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [NotMapped] // classification.HasErrors (Boolean) // ----------------------------------- // No testing requied // ----------------------------------- // Is NOT Nullable // [NotMapped] // classification.ValidationResults (IEnumerable`1) // ----------------------------------- // No testing requied } } }