public void TVItemLanguage_CRUD_Test() { foreach (CultureInfo culture in AllowableCulture) { ChangeCulture(culture); using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { TVItemLanguageService tvItemLanguageService = new TVItemLanguageService(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] } TVItemLanguage tvItemLanguage = GetFilledRandomTVItemLanguage(""); // ------------------------------- // ------------------------------- // CRUD testing // ------------------------------- // ------------------------------- count = tvItemLanguageService.GetTVItemLanguageList().Count(); Assert.AreEqual(count, (from c in dbTestDB.TVItemLanguages select c).Count()); tvItemLanguageService.Add(tvItemLanguage); if (tvItemLanguage.HasErrors) { Assert.AreEqual("", tvItemLanguage.ValidationResults.FirstOrDefault().ErrorMessage); } Assert.AreEqual(true, tvItemLanguageService.GetTVItemLanguageList().Where(c => c == tvItemLanguage).Any()); tvItemLanguageService.Update(tvItemLanguage); if (tvItemLanguage.HasErrors) { Assert.AreEqual("", tvItemLanguage.ValidationResults.FirstOrDefault().ErrorMessage); } Assert.AreEqual(count + 1, tvItemLanguageService.GetTVItemLanguageList().Count()); tvItemLanguageService.Delete(tvItemLanguage); if (tvItemLanguage.HasErrors) { Assert.AreEqual("", tvItemLanguage.ValidationResults.FirstOrDefault().ErrorMessage); } Assert.AreEqual(count, tvItemLanguageService.GetTVItemLanguageList().Count()); } } }
public void GetTVItemLanguageList_Test() { foreach (CultureInfo culture in AllowableCulture) { ChangeCulture(culture); using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { TVItemLanguageService tvItemLanguageService = new TVItemLanguageService(new Query() { Lang = culture.TwoLetterISOLanguageName }, dbTestDB, ContactID); TVItemLanguage tvItemLanguage = (from c in dbTestDB.TVItemLanguages select c).FirstOrDefault(); Assert.IsNotNull(tvItemLanguage); List <TVItemLanguage> tvItemLanguageDirectQueryList = new List <TVItemLanguage>(); tvItemLanguageDirectQueryList = (from c in dbTestDB.TVItemLanguages select c).Take(200).ToList(); foreach (string extra in new List <string>() { null, "A", "B", "C", "D", "E" }) { tvItemLanguageService.Query.Extra = extra; if (string.IsNullOrWhiteSpace(extra)) { List <TVItemLanguage> tvItemLanguageList = new List <TVItemLanguage>(); tvItemLanguageList = tvItemLanguageService.GetTVItemLanguageList().ToList(); CheckTVItemLanguageFields(tvItemLanguageList); } else { //Assert.AreEqual(true, false); } } } } }
public void GetTVItemLanguageList_2Where_Test() { foreach (CultureInfo culture in AllowableCulture) { ChangeCulture(culture); using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { foreach (string extra in new List <string>() { null, "A", "B", "C", "D", "E" }) { TVItemLanguageService tvItemLanguageService = new TVItemLanguageService(new Query() { Lang = culture.TwoLetterISOLanguageName }, dbTestDB, ContactID); tvItemLanguageService.Query = tvItemLanguageService.FillQuery(typeof(TVItemLanguage), culture.TwoLetterISOLanguageName, 0, 10000, "", "", "TVItemLanguageID,GT,2|TVItemLanguageID,LT,5", extra); List <TVItemLanguage> tvItemLanguageDirectQueryList = new List <TVItemLanguage>(); tvItemLanguageDirectQueryList = (from c in dbTestDB.TVItemLanguages select c).Where(c => c.TVItemLanguageID > 2 && c.TVItemLanguageID < 5).ToList(); if (string.IsNullOrWhiteSpace(extra)) { List <TVItemLanguage> tvItemLanguageList = new List <TVItemLanguage>(); tvItemLanguageList = tvItemLanguageService.GetTVItemLanguageList().ToList(); CheckTVItemLanguageFields(tvItemLanguageList); Assert.AreEqual(tvItemLanguageDirectQueryList[0].TVItemLanguageID, tvItemLanguageList[0].TVItemLanguageID); } else { //Assert.AreEqual(true, false); } } } } }
public void TVItemLanguage_Properties_Test() { foreach (CultureInfo culture in AllowableCulture) { ChangeCulture(culture); using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { TVItemLanguageService tvItemLanguageService = new TVItemLanguageService(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 = tvItemLanguageService.GetTVItemLanguageList().Count(); TVItemLanguage tvItemLanguage = GetFilledRandomTVItemLanguage(""); // ------------------------------- // ------------------------------- // Properties testing // ------------------------------- // ------------------------------- // ----------------------------------- // [Key] // Is NOT Nullable // tvItemLanguage.TVItemLanguageID (Int32) // ----------------------------------- tvItemLanguage = null; tvItemLanguage = GetFilledRandomTVItemLanguage(""); tvItemLanguage.TVItemLanguageID = 0; tvItemLanguageService.Update(tvItemLanguage); Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "TVItemLanguageID"), tvItemLanguage.ValidationResults.FirstOrDefault().ErrorMessage); tvItemLanguage = null; tvItemLanguage = GetFilledRandomTVItemLanguage(""); tvItemLanguage.TVItemLanguageID = 10000000; tvItemLanguageService.Update(tvItemLanguage); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItemLanguage", "TVItemLanguageID", tvItemLanguage.TVItemLanguageID.ToString()), tvItemLanguage.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [CSSPExist(ExistTypeName = "TVItem", ExistPlurial = "s", ExistFieldID = "TVItemID", AllowableTVtypeList = Root,Address,Area,ClimateSite,Contact,Country,Email,HydrometricSite,Infrastructure,MikeBoundaryConditionWebTide,MikeBoundaryConditionMesh,MikeScenario,MikeSource,Municipality,MWQMSite,PolSourceSite,Province,Sector,Subsector,Tel,MWQMRun,Classification)] // tvItemLanguage.TVItemID (Int32) // ----------------------------------- tvItemLanguage = null; tvItemLanguage = GetFilledRandomTVItemLanguage(""); tvItemLanguage.TVItemID = 0; tvItemLanguageService.Add(tvItemLanguage); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "TVItemID", tvItemLanguage.TVItemID.ToString()), tvItemLanguage.ValidationResults.FirstOrDefault().ErrorMessage); tvItemLanguage = null; tvItemLanguage = GetFilledRandomTVItemLanguage(""); tvItemLanguage.TVItemID = 38; tvItemLanguageService.Add(tvItemLanguage); Assert.AreEqual(string.Format(CSSPServicesRes._IsNotOfType_, "TVItemID", "Root,Address,Area,ClimateSite,Contact,Country,Email,HydrometricSite,Infrastructure,MikeBoundaryConditionWebTide,MikeBoundaryConditionMesh,MikeScenario,MikeSource,Municipality,MWQMSite,PolSourceSite,Province,Sector,Subsector,Tel,MWQMRun,Classification"), tvItemLanguage.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [CSSPEnumType] // tvItemLanguage.Language (LanguageEnum) // ----------------------------------- tvItemLanguage = null; tvItemLanguage = GetFilledRandomTVItemLanguage(""); tvItemLanguage.Language = (LanguageEnum)1000000; tvItemLanguageService.Add(tvItemLanguage); Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "Language"), tvItemLanguage.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [StringLength(200))] // tvItemLanguage.TVText (String) // ----------------------------------- tvItemLanguage = null; tvItemLanguage = GetFilledRandomTVItemLanguage("TVText"); Assert.AreEqual(false, tvItemLanguageService.Add(tvItemLanguage)); Assert.AreEqual(1, tvItemLanguage.ValidationResults.Count()); Assert.IsTrue(tvItemLanguage.ValidationResults.Where(c => c.ErrorMessage == string.Format(CSSPServicesRes._IsRequired, "TVText")).Any()); Assert.AreEqual(null, tvItemLanguage.TVText); Assert.AreEqual(count, tvItemLanguageService.GetTVItemLanguageList().Count()); tvItemLanguage = null; tvItemLanguage = GetFilledRandomTVItemLanguage(""); tvItemLanguage.TVText = GetRandomString("", 201); Assert.AreEqual(false, tvItemLanguageService.Add(tvItemLanguage)); Assert.AreEqual(string.Format(CSSPServicesRes._MaxLengthIs_, "TVText", "200"), tvItemLanguage.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, tvItemLanguageService.GetTVItemLanguageList().Count()); // ----------------------------------- // Is NOT Nullable // [CSSPEnumType] // tvItemLanguage.TranslationStatus (TranslationStatusEnum) // ----------------------------------- tvItemLanguage = null; tvItemLanguage = GetFilledRandomTVItemLanguage(""); tvItemLanguage.TranslationStatus = (TranslationStatusEnum)1000000; tvItemLanguageService.Add(tvItemLanguage); Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "TranslationStatus"), tvItemLanguage.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [CSSPAfter(Year = 1980)] // tvItemLanguage.LastUpdateDate_UTC (DateTime) // ----------------------------------- tvItemLanguage = null; tvItemLanguage = GetFilledRandomTVItemLanguage(""); tvItemLanguage.LastUpdateDate_UTC = new DateTime(); tvItemLanguageService.Add(tvItemLanguage); Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "LastUpdateDate_UTC"), tvItemLanguage.ValidationResults.FirstOrDefault().ErrorMessage); tvItemLanguage = null; tvItemLanguage = GetFilledRandomTVItemLanguage(""); tvItemLanguage.LastUpdateDate_UTC = new DateTime(1979, 1, 1); tvItemLanguageService.Add(tvItemLanguage); Assert.AreEqual(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "LastUpdateDate_UTC", "1980"), tvItemLanguage.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [CSSPExist(ExistTypeName = "TVItem", ExistPlurial = "s", ExistFieldID = "TVItemID", AllowableTVtypeList = Contact)] // tvItemLanguage.LastUpdateContactTVItemID (Int32) // ----------------------------------- tvItemLanguage = null; tvItemLanguage = GetFilledRandomTVItemLanguage(""); tvItemLanguage.LastUpdateContactTVItemID = 0; tvItemLanguageService.Add(tvItemLanguage); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "LastUpdateContactTVItemID", tvItemLanguage.LastUpdateContactTVItemID.ToString()), tvItemLanguage.ValidationResults.FirstOrDefault().ErrorMessage); tvItemLanguage = null; tvItemLanguage = GetFilledRandomTVItemLanguage(""); tvItemLanguage.LastUpdateContactTVItemID = 1; tvItemLanguageService.Add(tvItemLanguage); Assert.AreEqual(string.Format(CSSPServicesRes._IsNotOfType_, "LastUpdateContactTVItemID", "Contact"), tvItemLanguage.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [NotMapped] // tvItemLanguage.HasErrors (Boolean) // ----------------------------------- // No testing requied // ----------------------------------- // Is NOT Nullable // [NotMapped] // tvItemLanguage.ValidationResults (IEnumerable`1) // ----------------------------------- // No testing requied } } }
public IHttpActionResult GetTVItemLanguageList([FromUri] string lang = "en", [FromUri] int skip = 0, [FromUri] int take = 200, [FromUri] string asc = "", [FromUri] string desc = "", [FromUri] string where = "", [FromUri] string extra = "") { using (CSSPDBContext db = new CSSPDBContext(DatabaseType)) { TVItemLanguageService tvItemLanguageService = new TVItemLanguageService(new Query() { Lang = lang }, db, ContactID); if (extra == "A") // QueryString contains [extra=A] { tvItemLanguageService.Query = tvItemLanguageService.FillQuery(typeof(TVItemLanguageExtraA), lang, skip, take, asc, desc, where, extra); if (tvItemLanguageService.Query.HasErrors) { return(Ok(new List <TVItemLanguageExtraA>() { new TVItemLanguageExtraA() { HasErrors = tvItemLanguageService.Query.HasErrors, ValidationResults = tvItemLanguageService.Query.ValidationResults, }, }.ToList())); } else { return(Ok(tvItemLanguageService.GetTVItemLanguageExtraAList().ToList())); } } else if (extra == "B") // QueryString contains [extra=B] { tvItemLanguageService.Query = tvItemLanguageService.FillQuery(typeof(TVItemLanguageExtraB), lang, skip, take, asc, desc, where, extra); if (tvItemLanguageService.Query.HasErrors) { return(Ok(new List <TVItemLanguageExtraB>() { new TVItemLanguageExtraB() { HasErrors = tvItemLanguageService.Query.HasErrors, ValidationResults = tvItemLanguageService.Query.ValidationResults, }, }.ToList())); } else { return(Ok(tvItemLanguageService.GetTVItemLanguageExtraBList().ToList())); } } else // QueryString has no parameter [extra] or extra is empty { tvItemLanguageService.Query = tvItemLanguageService.FillQuery(typeof(TVItemLanguage), lang, skip, take, asc, desc, where, extra); if (tvItemLanguageService.Query.HasErrors) { return(Ok(new List <TVItemLanguage>() { new TVItemLanguage() { HasErrors = tvItemLanguageService.Query.HasErrors, ValidationResults = tvItemLanguageService.Query.ValidationResults, }, }.ToList())); } else { return(Ok(tvItemLanguageService.GetTVItemLanguageList().ToList())); } } } }