public void TVFileLanguage_CRUD_Test() { foreach (CultureInfo culture in AllowableCulture) { ChangeCulture(culture); using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { TVFileLanguageService tvFileLanguageService = new TVFileLanguageService(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] } TVFileLanguage tvFileLanguage = GetFilledRandomTVFileLanguage(""); // ------------------------------- // ------------------------------- // CRUD testing // ------------------------------- // ------------------------------- count = tvFileLanguageService.GetTVFileLanguageList().Count(); Assert.AreEqual(count, (from c in dbTestDB.TVFileLanguages select c).Count()); tvFileLanguageService.Add(tvFileLanguage); if (tvFileLanguage.HasErrors) { Assert.AreEqual("", tvFileLanguage.ValidationResults.FirstOrDefault().ErrorMessage); } Assert.AreEqual(true, tvFileLanguageService.GetTVFileLanguageList().Where(c => c == tvFileLanguage).Any()); tvFileLanguageService.Update(tvFileLanguage); if (tvFileLanguage.HasErrors) { Assert.AreEqual("", tvFileLanguage.ValidationResults.FirstOrDefault().ErrorMessage); } Assert.AreEqual(count + 1, tvFileLanguageService.GetTVFileLanguageList().Count()); tvFileLanguageService.Delete(tvFileLanguage); if (tvFileLanguage.HasErrors) { Assert.AreEqual("", tvFileLanguage.ValidationResults.FirstOrDefault().ErrorMessage); } Assert.AreEqual(count, tvFileLanguageService.GetTVFileLanguageList().Count()); } } }
public IHttpActionResult Put([FromBody] TVFileLanguage tvFileLanguage, [FromUri] string lang = "en") { using (CSSPDBContext db = new CSSPDBContext(DatabaseType)) { TVFileLanguageService tvFileLanguageService = new TVFileLanguageService(new Query() { Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en) }, db, ContactID); if (!tvFileLanguageService.Update(tvFileLanguage)) { return(BadRequest(String.Join("|||", tvFileLanguage.ValidationResults))); } else { tvFileLanguage.ValidationResults = null; return(Ok(tvFileLanguage)); } } }
public void TVFileLanguage_Properties_Test() { foreach (CultureInfo culture in AllowableCulture) { ChangeCulture(culture); using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { TVFileLanguageService tvFileLanguageService = new TVFileLanguageService(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 = tvFileLanguageService.GetTVFileLanguageList().Count(); TVFileLanguage tvFileLanguage = GetFilledRandomTVFileLanguage(""); // ------------------------------- // ------------------------------- // Properties testing // ------------------------------- // ------------------------------- // ----------------------------------- // [Key] // Is NOT Nullable // tvFileLanguage.TVFileLanguageID (Int32) // ----------------------------------- tvFileLanguage = null; tvFileLanguage = GetFilledRandomTVFileLanguage(""); tvFileLanguage.TVFileLanguageID = 0; tvFileLanguageService.Update(tvFileLanguage); Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "TVFileLanguageID"), tvFileLanguage.ValidationResults.FirstOrDefault().ErrorMessage); tvFileLanguage = null; tvFileLanguage = GetFilledRandomTVFileLanguage(""); tvFileLanguage.TVFileLanguageID = 10000000; tvFileLanguageService.Update(tvFileLanguage); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVFileLanguage", "TVFileLanguageID", tvFileLanguage.TVFileLanguageID.ToString()), tvFileLanguage.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [CSSPExist(ExistTypeName = "TVFile", ExistPlurial = "s", ExistFieldID = "TVFileID", AllowableTVtypeList = )] // tvFileLanguage.TVFileID (Int32) // ----------------------------------- tvFileLanguage = null; tvFileLanguage = GetFilledRandomTVFileLanguage(""); tvFileLanguage.TVFileID = 0; tvFileLanguageService.Add(tvFileLanguage); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVFile", "TVFileID", tvFileLanguage.TVFileID.ToString()), tvFileLanguage.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [CSSPEnumType] // tvFileLanguage.Language (LanguageEnum) // ----------------------------------- tvFileLanguage = null; tvFileLanguage = GetFilledRandomTVFileLanguage(""); tvFileLanguage.Language = (LanguageEnum)1000000; tvFileLanguageService.Add(tvFileLanguage); Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "Language"), tvFileLanguage.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is Nullable // tvFileLanguage.FileDescription (String) // ----------------------------------- // ----------------------------------- // Is NOT Nullable // [CSSPEnumType] // tvFileLanguage.TranslationStatus (TranslationStatusEnum) // ----------------------------------- tvFileLanguage = null; tvFileLanguage = GetFilledRandomTVFileLanguage(""); tvFileLanguage.TranslationStatus = (TranslationStatusEnum)1000000; tvFileLanguageService.Add(tvFileLanguage); Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "TranslationStatus"), tvFileLanguage.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [CSSPAfter(Year = 1980)] // tvFileLanguage.LastUpdateDate_UTC (DateTime) // ----------------------------------- tvFileLanguage = null; tvFileLanguage = GetFilledRandomTVFileLanguage(""); tvFileLanguage.LastUpdateDate_UTC = new DateTime(); tvFileLanguageService.Add(tvFileLanguage); Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "LastUpdateDate_UTC"), tvFileLanguage.ValidationResults.FirstOrDefault().ErrorMessage); tvFileLanguage = null; tvFileLanguage = GetFilledRandomTVFileLanguage(""); tvFileLanguage.LastUpdateDate_UTC = new DateTime(1979, 1, 1); tvFileLanguageService.Add(tvFileLanguage); Assert.AreEqual(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "LastUpdateDate_UTC", "1980"), tvFileLanguage.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [CSSPExist(ExistTypeName = "TVItem", ExistPlurial = "s", ExistFieldID = "TVItemID", AllowableTVtypeList = Contact)] // tvFileLanguage.LastUpdateContactTVItemID (Int32) // ----------------------------------- tvFileLanguage = null; tvFileLanguage = GetFilledRandomTVFileLanguage(""); tvFileLanguage.LastUpdateContactTVItemID = 0; tvFileLanguageService.Add(tvFileLanguage); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "LastUpdateContactTVItemID", tvFileLanguage.LastUpdateContactTVItemID.ToString()), tvFileLanguage.ValidationResults.FirstOrDefault().ErrorMessage); tvFileLanguage = null; tvFileLanguage = GetFilledRandomTVFileLanguage(""); tvFileLanguage.LastUpdateContactTVItemID = 1; tvFileLanguageService.Add(tvFileLanguage); Assert.AreEqual(string.Format(CSSPServicesRes._IsNotOfType_, "LastUpdateContactTVItemID", "Contact"), tvFileLanguage.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [NotMapped] // tvFileLanguage.HasErrors (Boolean) // ----------------------------------- // No testing requied // ----------------------------------- // Is NOT Nullable // [NotMapped] // tvFileLanguage.ValidationResults (IEnumerable`1) // ----------------------------------- // No testing requied } } }