public void MWQMRunLanguage_CRUD_Test() { foreach (CultureInfo culture in AllowableCulture) { ChangeCulture(culture); using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { MWQMRunLanguageService mwqmRunLanguageService = new MWQMRunLanguageService(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] } MWQMRunLanguage mwqmRunLanguage = GetFilledRandomMWQMRunLanguage(""); // ------------------------------- // ------------------------------- // CRUD testing // ------------------------------- // ------------------------------- count = mwqmRunLanguageService.GetMWQMRunLanguageList().Count(); Assert.AreEqual(count, (from c in dbTestDB.MWQMRunLanguages select c).Count()); mwqmRunLanguageService.Add(mwqmRunLanguage); if (mwqmRunLanguage.HasErrors) { Assert.AreEqual("", mwqmRunLanguage.ValidationResults.FirstOrDefault().ErrorMessage); } Assert.AreEqual(true, mwqmRunLanguageService.GetMWQMRunLanguageList().Where(c => c == mwqmRunLanguage).Any()); mwqmRunLanguageService.Update(mwqmRunLanguage); if (mwqmRunLanguage.HasErrors) { Assert.AreEqual("", mwqmRunLanguage.ValidationResults.FirstOrDefault().ErrorMessage); } Assert.AreEqual(count + 1, mwqmRunLanguageService.GetMWQMRunLanguageList().Count()); mwqmRunLanguageService.Delete(mwqmRunLanguage); if (mwqmRunLanguage.HasErrors) { Assert.AreEqual("", mwqmRunLanguage.ValidationResults.FirstOrDefault().ErrorMessage); } Assert.AreEqual(count, mwqmRunLanguageService.GetMWQMRunLanguageList().Count()); } } }
public void GetMWQMRunLanguageList_Test() { foreach (CultureInfo culture in AllowableCulture) { ChangeCulture(culture); using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { MWQMRunLanguageService mwqmRunLanguageService = new MWQMRunLanguageService(new Query() { Lang = culture.TwoLetterISOLanguageName }, dbTestDB, ContactID); MWQMRunLanguage mwqmRunLanguage = (from c in dbTestDB.MWQMRunLanguages select c).FirstOrDefault(); Assert.IsNotNull(mwqmRunLanguage); List <MWQMRunLanguage> mwqmRunLanguageDirectQueryList = new List <MWQMRunLanguage>(); mwqmRunLanguageDirectQueryList = (from c in dbTestDB.MWQMRunLanguages select c).Take(200).ToList(); foreach (string extra in new List <string>() { null, "A", "B", "C", "D", "E" }) { mwqmRunLanguageService.Query.Extra = extra; if (string.IsNullOrWhiteSpace(extra)) { List <MWQMRunLanguage> mwqmRunLanguageList = new List <MWQMRunLanguage>(); mwqmRunLanguageList = mwqmRunLanguageService.GetMWQMRunLanguageList().ToList(); CheckMWQMRunLanguageFields(mwqmRunLanguageList); } else { //Assert.AreEqual(true, false); } } } } }
public void GetMWQMRunLanguageList_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" }) { MWQMRunLanguageService mwqmRunLanguageService = new MWQMRunLanguageService(new Query() { Lang = culture.TwoLetterISOLanguageName }, dbTestDB, ContactID); mwqmRunLanguageService.Query = mwqmRunLanguageService.FillQuery(typeof(MWQMRunLanguage), culture.TwoLetterISOLanguageName, 0, 10000, "", "", "MWQMRunLanguageID,GT,2|MWQMRunLanguageID,LT,5", extra); List <MWQMRunLanguage> mwqmRunLanguageDirectQueryList = new List <MWQMRunLanguage>(); mwqmRunLanguageDirectQueryList = (from c in dbTestDB.MWQMRunLanguages select c).Where(c => c.MWQMRunLanguageID > 2 && c.MWQMRunLanguageID < 5).ToList(); if (string.IsNullOrWhiteSpace(extra)) { List <MWQMRunLanguage> mwqmRunLanguageList = new List <MWQMRunLanguage>(); mwqmRunLanguageList = mwqmRunLanguageService.GetMWQMRunLanguageList().ToList(); CheckMWQMRunLanguageFields(mwqmRunLanguageList); Assert.AreEqual(mwqmRunLanguageDirectQueryList[0].MWQMRunLanguageID, mwqmRunLanguageList[0].MWQMRunLanguageID); } else { //Assert.AreEqual(true, false); } } } } }
public IHttpActionResult GetMWQMRunLanguageList([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)) { MWQMRunLanguageService mwqmRunLanguageService = new MWQMRunLanguageService(new Query() { Lang = lang }, db, ContactID); if (extra == "A") // QueryString contains [extra=A] { mwqmRunLanguageService.Query = mwqmRunLanguageService.FillQuery(typeof(MWQMRunLanguageExtraA), lang, skip, take, asc, desc, where, extra); if (mwqmRunLanguageService.Query.HasErrors) { return(Ok(new List <MWQMRunLanguageExtraA>() { new MWQMRunLanguageExtraA() { HasErrors = mwqmRunLanguageService.Query.HasErrors, ValidationResults = mwqmRunLanguageService.Query.ValidationResults, }, }.ToList())); } else { return(Ok(mwqmRunLanguageService.GetMWQMRunLanguageExtraAList().ToList())); } } else if (extra == "B") // QueryString contains [extra=B] { mwqmRunLanguageService.Query = mwqmRunLanguageService.FillQuery(typeof(MWQMRunLanguageExtraB), lang, skip, take, asc, desc, where, extra); if (mwqmRunLanguageService.Query.HasErrors) { return(Ok(new List <MWQMRunLanguageExtraB>() { new MWQMRunLanguageExtraB() { HasErrors = mwqmRunLanguageService.Query.HasErrors, ValidationResults = mwqmRunLanguageService.Query.ValidationResults, }, }.ToList())); } else { return(Ok(mwqmRunLanguageService.GetMWQMRunLanguageExtraBList().ToList())); } } else // QueryString has no parameter [extra] or extra is empty { mwqmRunLanguageService.Query = mwqmRunLanguageService.FillQuery(typeof(MWQMRunLanguage), lang, skip, take, asc, desc, where, extra); if (mwqmRunLanguageService.Query.HasErrors) { return(Ok(new List <MWQMRunLanguage>() { new MWQMRunLanguage() { HasErrors = mwqmRunLanguageService.Query.HasErrors, ValidationResults = mwqmRunLanguageService.Query.ValidationResults, }, }.ToList())); } else { return(Ok(mwqmRunLanguageService.GetMWQMRunLanguageList().ToList())); } } } }
public void MWQMRunLanguage_Properties_Test() { foreach (CultureInfo culture in AllowableCulture) { ChangeCulture(culture); using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { MWQMRunLanguageService mwqmRunLanguageService = new MWQMRunLanguageService(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 = mwqmRunLanguageService.GetMWQMRunLanguageList().Count(); MWQMRunLanguage mwqmRunLanguage = GetFilledRandomMWQMRunLanguage(""); // ------------------------------- // ------------------------------- // Properties testing // ------------------------------- // ------------------------------- // ----------------------------------- // [Key] // Is NOT Nullable // mwqmRunLanguage.MWQMRunLanguageID (Int32) // ----------------------------------- mwqmRunLanguage = null; mwqmRunLanguage = GetFilledRandomMWQMRunLanguage(""); mwqmRunLanguage.MWQMRunLanguageID = 0; mwqmRunLanguageService.Update(mwqmRunLanguage); Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "MWQMRunLanguageID"), mwqmRunLanguage.ValidationResults.FirstOrDefault().ErrorMessage); mwqmRunLanguage = null; mwqmRunLanguage = GetFilledRandomMWQMRunLanguage(""); mwqmRunLanguage.MWQMRunLanguageID = 10000000; mwqmRunLanguageService.Update(mwqmRunLanguage); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "MWQMRunLanguage", "MWQMRunLanguageID", mwqmRunLanguage.MWQMRunLanguageID.ToString()), mwqmRunLanguage.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [CSSPExist(ExistTypeName = "MWQMRun", ExistPlurial = "s", ExistFieldID = "MWQMRunID", AllowableTVtypeList = )] // mwqmRunLanguage.MWQMRunID (Int32) // ----------------------------------- mwqmRunLanguage = null; mwqmRunLanguage = GetFilledRandomMWQMRunLanguage(""); mwqmRunLanguage.MWQMRunID = 0; mwqmRunLanguageService.Add(mwqmRunLanguage); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "MWQMRun", "MWQMRunID", mwqmRunLanguage.MWQMRunID.ToString()), mwqmRunLanguage.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [CSSPEnumType] // mwqmRunLanguage.Language (LanguageEnum) // ----------------------------------- mwqmRunLanguage = null; mwqmRunLanguage = GetFilledRandomMWQMRunLanguage(""); mwqmRunLanguage.Language = (LanguageEnum)1000000; mwqmRunLanguageService.Add(mwqmRunLanguage); Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "Language"), mwqmRunLanguage.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // mwqmRunLanguage.RunComment (String) // ----------------------------------- mwqmRunLanguage = null; mwqmRunLanguage = GetFilledRandomMWQMRunLanguage("RunComment"); Assert.AreEqual(false, mwqmRunLanguageService.Add(mwqmRunLanguage)); Assert.AreEqual(1, mwqmRunLanguage.ValidationResults.Count()); Assert.IsTrue(mwqmRunLanguage.ValidationResults.Where(c => c.ErrorMessage == string.Format(CSSPServicesRes._IsRequired, "RunComment")).Any()); Assert.AreEqual(null, mwqmRunLanguage.RunComment); Assert.AreEqual(count, mwqmRunLanguageService.GetMWQMRunLanguageList().Count()); // ----------------------------------- // Is NOT Nullable // [CSSPEnumType] // mwqmRunLanguage.TranslationStatusRunComment (TranslationStatusEnum) // ----------------------------------- mwqmRunLanguage = null; mwqmRunLanguage = GetFilledRandomMWQMRunLanguage(""); mwqmRunLanguage.TranslationStatusRunComment = (TranslationStatusEnum)1000000; mwqmRunLanguageService.Add(mwqmRunLanguage); Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "TranslationStatusRunComment"), mwqmRunLanguage.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // mwqmRunLanguage.RunWeatherComment (String) // ----------------------------------- mwqmRunLanguage = null; mwqmRunLanguage = GetFilledRandomMWQMRunLanguage("RunWeatherComment"); Assert.AreEqual(false, mwqmRunLanguageService.Add(mwqmRunLanguage)); Assert.AreEqual(1, mwqmRunLanguage.ValidationResults.Count()); Assert.IsTrue(mwqmRunLanguage.ValidationResults.Where(c => c.ErrorMessage == string.Format(CSSPServicesRes._IsRequired, "RunWeatherComment")).Any()); Assert.AreEqual(null, mwqmRunLanguage.RunWeatherComment); Assert.AreEqual(count, mwqmRunLanguageService.GetMWQMRunLanguageList().Count()); // ----------------------------------- // Is NOT Nullable // [CSSPEnumType] // mwqmRunLanguage.TranslationStatusRunWeatherComment (TranslationStatusEnum) // ----------------------------------- mwqmRunLanguage = null; mwqmRunLanguage = GetFilledRandomMWQMRunLanguage(""); mwqmRunLanguage.TranslationStatusRunWeatherComment = (TranslationStatusEnum)1000000; mwqmRunLanguageService.Add(mwqmRunLanguage); Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "TranslationStatusRunWeatherComment"), mwqmRunLanguage.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [CSSPAfter(Year = 1980)] // mwqmRunLanguage.LastUpdateDate_UTC (DateTime) // ----------------------------------- mwqmRunLanguage = null; mwqmRunLanguage = GetFilledRandomMWQMRunLanguage(""); mwqmRunLanguage.LastUpdateDate_UTC = new DateTime(); mwqmRunLanguageService.Add(mwqmRunLanguage); Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "LastUpdateDate_UTC"), mwqmRunLanguage.ValidationResults.FirstOrDefault().ErrorMessage); mwqmRunLanguage = null; mwqmRunLanguage = GetFilledRandomMWQMRunLanguage(""); mwqmRunLanguage.LastUpdateDate_UTC = new DateTime(1979, 1, 1); mwqmRunLanguageService.Add(mwqmRunLanguage); Assert.AreEqual(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "LastUpdateDate_UTC", "1980"), mwqmRunLanguage.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [CSSPExist(ExistTypeName = "TVItem", ExistPlurial = "s", ExistFieldID = "TVItemID", AllowableTVtypeList = Contact)] // mwqmRunLanguage.LastUpdateContactTVItemID (Int32) // ----------------------------------- mwqmRunLanguage = null; mwqmRunLanguage = GetFilledRandomMWQMRunLanguage(""); mwqmRunLanguage.LastUpdateContactTVItemID = 0; mwqmRunLanguageService.Add(mwqmRunLanguage); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "LastUpdateContactTVItemID", mwqmRunLanguage.LastUpdateContactTVItemID.ToString()), mwqmRunLanguage.ValidationResults.FirstOrDefault().ErrorMessage); mwqmRunLanguage = null; mwqmRunLanguage = GetFilledRandomMWQMRunLanguage(""); mwqmRunLanguage.LastUpdateContactTVItemID = 1; mwqmRunLanguageService.Add(mwqmRunLanguage); Assert.AreEqual(string.Format(CSSPServicesRes._IsNotOfType_, "LastUpdateContactTVItemID", "Contact"), mwqmRunLanguage.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [NotMapped] // mwqmRunLanguage.HasErrors (Boolean) // ----------------------------------- // No testing requied // ----------------------------------- // Is NOT Nullable // [NotMapped] // mwqmRunLanguage.ValidationResults (IEnumerable`1) // ----------------------------------- // No testing requied } } }