public void AppTaskLanguage_CRUD_Test() { foreach (CultureInfo culture in AllowableCulture) { ChangeCulture(culture); using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { AppTaskLanguageService appTaskLanguageService = new AppTaskLanguageService(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] } AppTaskLanguage appTaskLanguage = GetFilledRandomAppTaskLanguage(""); // ------------------------------- // ------------------------------- // CRUD testing // ------------------------------- // ------------------------------- count = appTaskLanguageService.GetAppTaskLanguageList().Count(); Assert.AreEqual(count, (from c in dbTestDB.AppTaskLanguages select c).Count()); appTaskLanguageService.Add(appTaskLanguage); if (appTaskLanguage.HasErrors) { Assert.AreEqual("", appTaskLanguage.ValidationResults.FirstOrDefault().ErrorMessage); } Assert.AreEqual(true, appTaskLanguageService.GetAppTaskLanguageList().Where(c => c == appTaskLanguage).Any()); appTaskLanguageService.Update(appTaskLanguage); if (appTaskLanguage.HasErrors) { Assert.AreEqual("", appTaskLanguage.ValidationResults.FirstOrDefault().ErrorMessage); } Assert.AreEqual(count + 1, appTaskLanguageService.GetAppTaskLanguageList().Count()); appTaskLanguageService.Delete(appTaskLanguage); if (appTaskLanguage.HasErrors) { Assert.AreEqual("", appTaskLanguage.ValidationResults.FirstOrDefault().ErrorMessage); } Assert.AreEqual(count, appTaskLanguageService.GetAppTaskLanguageList().Count()); } } }
public IHttpActionResult Put([FromBody] AppTaskLanguage appTaskLanguage, [FromUri] string lang = "en") { using (CSSPDBContext db = new CSSPDBContext(DatabaseType)) { AppTaskLanguageService appTaskLanguageService = new AppTaskLanguageService(new Query() { Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en) }, db, ContactID); if (!appTaskLanguageService.Update(appTaskLanguage)) { return(BadRequest(String.Join("|||", appTaskLanguage.ValidationResults))); } else { appTaskLanguage.ValidationResults = null; return(Ok(appTaskLanguage)); } } }
public void AppTaskLanguage_Properties_Test() { foreach (CultureInfo culture in AllowableCulture) { ChangeCulture(culture); using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { AppTaskLanguageService appTaskLanguageService = new AppTaskLanguageService(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 = appTaskLanguageService.GetAppTaskLanguageList().Count(); AppTaskLanguage appTaskLanguage = GetFilledRandomAppTaskLanguage(""); // ------------------------------- // ------------------------------- // Properties testing // ------------------------------- // ------------------------------- // ----------------------------------- // [Key] // Is NOT Nullable // appTaskLanguage.AppTaskLanguageID (Int32) // ----------------------------------- appTaskLanguage = null; appTaskLanguage = GetFilledRandomAppTaskLanguage(""); appTaskLanguage.AppTaskLanguageID = 0; appTaskLanguageService.Update(appTaskLanguage); Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "AppTaskLanguageID"), appTaskLanguage.ValidationResults.FirstOrDefault().ErrorMessage); appTaskLanguage = null; appTaskLanguage = GetFilledRandomAppTaskLanguage(""); appTaskLanguage.AppTaskLanguageID = 10000000; appTaskLanguageService.Update(appTaskLanguage); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "AppTaskLanguage", "AppTaskLanguageID", appTaskLanguage.AppTaskLanguageID.ToString()), appTaskLanguage.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [CSSPExist(ExistTypeName = "AppTask", ExistPlurial = "s", ExistFieldID = "AppTaskID", AllowableTVtypeList = )] // appTaskLanguage.AppTaskID (Int32) // ----------------------------------- appTaskLanguage = null; appTaskLanguage = GetFilledRandomAppTaskLanguage(""); appTaskLanguage.AppTaskID = 0; appTaskLanguageService.Add(appTaskLanguage); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "AppTask", "AppTaskID", appTaskLanguage.AppTaskID.ToString()), appTaskLanguage.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [CSSPEnumType] // appTaskLanguage.Language (LanguageEnum) // ----------------------------------- appTaskLanguage = null; appTaskLanguage = GetFilledRandomAppTaskLanguage(""); appTaskLanguage.Language = (LanguageEnum)1000000; appTaskLanguageService.Add(appTaskLanguage); Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "Language"), appTaskLanguage.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is Nullable // [StringLength(250))] // appTaskLanguage.StatusText (String) // ----------------------------------- appTaskLanguage = null; appTaskLanguage = GetFilledRandomAppTaskLanguage(""); appTaskLanguage.StatusText = GetRandomString("", 251); Assert.AreEqual(false, appTaskLanguageService.Add(appTaskLanguage)); Assert.AreEqual(string.Format(CSSPServicesRes._MaxLengthIs_, "StatusText", "250"), appTaskLanguage.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, appTaskLanguageService.GetAppTaskLanguageList().Count()); // ----------------------------------- // Is Nullable // [StringLength(250))] // appTaskLanguage.ErrorText (String) // ----------------------------------- appTaskLanguage = null; appTaskLanguage = GetFilledRandomAppTaskLanguage(""); appTaskLanguage.ErrorText = GetRandomString("", 251); Assert.AreEqual(false, appTaskLanguageService.Add(appTaskLanguage)); Assert.AreEqual(string.Format(CSSPServicesRes._MaxLengthIs_, "ErrorText", "250"), appTaskLanguage.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, appTaskLanguageService.GetAppTaskLanguageList().Count()); // ----------------------------------- // Is NOT Nullable // [CSSPEnumType] // appTaskLanguage.TranslationStatus (TranslationStatusEnum) // ----------------------------------- appTaskLanguage = null; appTaskLanguage = GetFilledRandomAppTaskLanguage(""); appTaskLanguage.TranslationStatus = (TranslationStatusEnum)1000000; appTaskLanguageService.Add(appTaskLanguage); Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "TranslationStatus"), appTaskLanguage.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [CSSPAfter(Year = 1980)] // appTaskLanguage.LastUpdateDate_UTC (DateTime) // ----------------------------------- appTaskLanguage = null; appTaskLanguage = GetFilledRandomAppTaskLanguage(""); appTaskLanguage.LastUpdateDate_UTC = new DateTime(); appTaskLanguageService.Add(appTaskLanguage); Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "LastUpdateDate_UTC"), appTaskLanguage.ValidationResults.FirstOrDefault().ErrorMessage); appTaskLanguage = null; appTaskLanguage = GetFilledRandomAppTaskLanguage(""); appTaskLanguage.LastUpdateDate_UTC = new DateTime(1979, 1, 1); appTaskLanguageService.Add(appTaskLanguage); Assert.AreEqual(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "LastUpdateDate_UTC", "1980"), appTaskLanguage.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [CSSPExist(ExistTypeName = "TVItem", ExistPlurial = "s", ExistFieldID = "TVItemID", AllowableTVtypeList = Contact)] // appTaskLanguage.LastUpdateContactTVItemID (Int32) // ----------------------------------- appTaskLanguage = null; appTaskLanguage = GetFilledRandomAppTaskLanguage(""); appTaskLanguage.LastUpdateContactTVItemID = 0; appTaskLanguageService.Add(appTaskLanguage); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "LastUpdateContactTVItemID", appTaskLanguage.LastUpdateContactTVItemID.ToString()), appTaskLanguage.ValidationResults.FirstOrDefault().ErrorMessage); appTaskLanguage = null; appTaskLanguage = GetFilledRandomAppTaskLanguage(""); appTaskLanguage.LastUpdateContactTVItemID = 1; appTaskLanguageService.Add(appTaskLanguage); Assert.AreEqual(string.Format(CSSPServicesRes._IsNotOfType_, "LastUpdateContactTVItemID", "Contact"), appTaskLanguage.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [NotMapped] // appTaskLanguage.HasErrors (Boolean) // ----------------------------------- // No testing requied // ----------------------------------- // Is NOT Nullable // [NotMapped] // appTaskLanguage.ValidationResults (IEnumerable`1) // ----------------------------------- // No testing requied } } }