public void AppErrLog_CRUD_Test() { foreach (CultureInfo culture in AllowableCulture) { ChangeCulture(culture); using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { AppErrLogService appErrLogService = new AppErrLogService(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] } AppErrLog appErrLog = GetFilledRandomAppErrLog(""); // ------------------------------- // ------------------------------- // CRUD testing // ------------------------------- // ------------------------------- count = appErrLogService.GetAppErrLogList().Count(); Assert.AreEqual(count, (from c in dbTestDB.AppErrLogs select c).Count()); appErrLogService.Add(appErrLog); if (appErrLog.HasErrors) { Assert.AreEqual("", appErrLog.ValidationResults.FirstOrDefault().ErrorMessage); } Assert.AreEqual(true, appErrLogService.GetAppErrLogList().Where(c => c == appErrLog).Any()); appErrLogService.Update(appErrLog); if (appErrLog.HasErrors) { Assert.AreEqual("", appErrLog.ValidationResults.FirstOrDefault().ErrorMessage); } Assert.AreEqual(count + 1, appErrLogService.GetAppErrLogList().Count()); appErrLogService.Delete(appErrLog); if (appErrLog.HasErrors) { Assert.AreEqual("", appErrLog.ValidationResults.FirstOrDefault().ErrorMessage); } Assert.AreEqual(count, appErrLogService.GetAppErrLogList().Count()); } } }
public void GetAppErrLogList_Test() { foreach (CultureInfo culture in AllowableCulture) { ChangeCulture(culture); using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { AppErrLogService appErrLogService = new AppErrLogService(new Query() { Lang = culture.TwoLetterISOLanguageName }, dbTestDB, ContactID); AppErrLog appErrLog = (from c in dbTestDB.AppErrLogs select c).FirstOrDefault(); Assert.IsNotNull(appErrLog); List <AppErrLog> appErrLogDirectQueryList = new List <AppErrLog>(); appErrLogDirectQueryList = (from c in dbTestDB.AppErrLogs select c).Take(200).ToList(); foreach (string extra in new List <string>() { null, "A", "B", "C", "D", "E" }) { appErrLogService.Query.Extra = extra; if (string.IsNullOrWhiteSpace(extra)) { List <AppErrLog> appErrLogList = new List <AppErrLog>(); appErrLogList = appErrLogService.GetAppErrLogList().ToList(); CheckAppErrLogFields(appErrLogList); } else { //Assert.AreEqual(true, false); } } } } }
public void GetAppErrLogList_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" }) { AppErrLogService appErrLogService = new AppErrLogService(new Query() { Lang = culture.TwoLetterISOLanguageName }, dbTestDB, ContactID); appErrLogService.Query = appErrLogService.FillQuery(typeof(AppErrLog), culture.TwoLetterISOLanguageName, 0, 10000, "", "", "AppErrLogID,GT,2|AppErrLogID,LT,5", extra); List <AppErrLog> appErrLogDirectQueryList = new List <AppErrLog>(); appErrLogDirectQueryList = (from c in dbTestDB.AppErrLogs select c).Where(c => c.AppErrLogID > 2 && c.AppErrLogID < 5).ToList(); if (string.IsNullOrWhiteSpace(extra)) { List <AppErrLog> appErrLogList = new List <AppErrLog>(); appErrLogList = appErrLogService.GetAppErrLogList().ToList(); CheckAppErrLogFields(appErrLogList); Assert.AreEqual(appErrLogDirectQueryList[0].AppErrLogID, appErrLogList[0].AppErrLogID); } else { //Assert.AreEqual(true, false); } } } } }
public void AppErrLog_Properties_Test() { foreach (CultureInfo culture in AllowableCulture) { ChangeCulture(culture); using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { AppErrLogService appErrLogService = new AppErrLogService(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 = appErrLogService.GetAppErrLogList().Count(); AppErrLog appErrLog = GetFilledRandomAppErrLog(""); // ------------------------------- // ------------------------------- // Properties testing // ------------------------------- // ------------------------------- // ----------------------------------- // [Key] // Is NOT Nullable // appErrLog.AppErrLogID (Int32) // ----------------------------------- appErrLog = null; appErrLog = GetFilledRandomAppErrLog(""); appErrLog.AppErrLogID = 0; appErrLogService.Update(appErrLog); Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "AppErrLogID"), appErrLog.ValidationResults.FirstOrDefault().ErrorMessage); appErrLog = null; appErrLog = GetFilledRandomAppErrLog(""); appErrLog.AppErrLogID = 10000000; appErrLogService.Update(appErrLog); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "AppErrLog", "AppErrLogID", appErrLog.AppErrLogID.ToString()), appErrLog.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [StringLength(100))] // appErrLog.Tag (String) // ----------------------------------- appErrLog = null; appErrLog = GetFilledRandomAppErrLog("Tag"); Assert.AreEqual(false, appErrLogService.Add(appErrLog)); Assert.AreEqual(1, appErrLog.ValidationResults.Count()); Assert.IsTrue(appErrLog.ValidationResults.Where(c => c.ErrorMessage == string.Format(CSSPServicesRes._IsRequired, "Tag")).Any()); Assert.AreEqual(null, appErrLog.Tag); Assert.AreEqual(count, appErrLogService.GetAppErrLogList().Count()); appErrLog = null; appErrLog = GetFilledRandomAppErrLog(""); appErrLog.Tag = GetRandomString("", 101); Assert.AreEqual(false, appErrLogService.Add(appErrLog)); Assert.AreEqual(string.Format(CSSPServicesRes._MaxLengthIs_, "Tag", "100"), appErrLog.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, appErrLogService.GetAppErrLogList().Count()); // ----------------------------------- // Is NOT Nullable // [Range(1, -1)] // appErrLog.LineNumber (Int32) // ----------------------------------- appErrLog = null; appErrLog = GetFilledRandomAppErrLog(""); appErrLog.LineNumber = 0; Assert.AreEqual(false, appErrLogService.Add(appErrLog)); Assert.AreEqual(string.Format(CSSPServicesRes._MinValueIs_, "LineNumber", "1"), appErrLog.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, appErrLogService.GetAppErrLogList().Count()); // ----------------------------------- // Is NOT Nullable // appErrLog.Source (String) // ----------------------------------- appErrLog = null; appErrLog = GetFilledRandomAppErrLog("Source"); Assert.AreEqual(false, appErrLogService.Add(appErrLog)); Assert.AreEqual(1, appErrLog.ValidationResults.Count()); Assert.IsTrue(appErrLog.ValidationResults.Where(c => c.ErrorMessage == string.Format(CSSPServicesRes._IsRequired, "Source")).Any()); Assert.AreEqual(null, appErrLog.Source); Assert.AreEqual(count, appErrLogService.GetAppErrLogList().Count()); // ----------------------------------- // Is NOT Nullable // appErrLog.Message (String) // ----------------------------------- appErrLog = null; appErrLog = GetFilledRandomAppErrLog("Message"); Assert.AreEqual(false, appErrLogService.Add(appErrLog)); Assert.AreEqual(1, appErrLog.ValidationResults.Count()); Assert.IsTrue(appErrLog.ValidationResults.Where(c => c.ErrorMessage == string.Format(CSSPServicesRes._IsRequired, "Message")).Any()); Assert.AreEqual(null, appErrLog.Message); Assert.AreEqual(count, appErrLogService.GetAppErrLogList().Count()); // ----------------------------------- // Is NOT Nullable // [CSSPAfter(Year = 1980)] // appErrLog.DateTime_UTC (DateTime) // ----------------------------------- appErrLog = null; appErrLog = GetFilledRandomAppErrLog(""); appErrLog.DateTime_UTC = new DateTime(); appErrLogService.Add(appErrLog); Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "DateTime_UTC"), appErrLog.ValidationResults.FirstOrDefault().ErrorMessage); appErrLog = null; appErrLog = GetFilledRandomAppErrLog(""); appErrLog.DateTime_UTC = new DateTime(1979, 1, 1); appErrLogService.Add(appErrLog); Assert.AreEqual(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "DateTime_UTC", "1980"), appErrLog.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [CSSPAfter(Year = 1980)] // appErrLog.LastUpdateDate_UTC (DateTime) // ----------------------------------- appErrLog = null; appErrLog = GetFilledRandomAppErrLog(""); appErrLog.LastUpdateDate_UTC = new DateTime(); appErrLogService.Add(appErrLog); Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "LastUpdateDate_UTC"), appErrLog.ValidationResults.FirstOrDefault().ErrorMessage); appErrLog = null; appErrLog = GetFilledRandomAppErrLog(""); appErrLog.LastUpdateDate_UTC = new DateTime(1979, 1, 1); appErrLogService.Add(appErrLog); Assert.AreEqual(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "LastUpdateDate_UTC", "1980"), appErrLog.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [CSSPExist(ExistTypeName = "TVItem", ExistPlurial = "s", ExistFieldID = "TVItemID", AllowableTVtypeList = Contact)] // appErrLog.LastUpdateContactTVItemID (Int32) // ----------------------------------- appErrLog = null; appErrLog = GetFilledRandomAppErrLog(""); appErrLog.LastUpdateContactTVItemID = 0; appErrLogService.Add(appErrLog); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "LastUpdateContactTVItemID", appErrLog.LastUpdateContactTVItemID.ToString()), appErrLog.ValidationResults.FirstOrDefault().ErrorMessage); appErrLog = null; appErrLog = GetFilledRandomAppErrLog(""); appErrLog.LastUpdateContactTVItemID = 1; appErrLogService.Add(appErrLog); Assert.AreEqual(string.Format(CSSPServicesRes._IsNotOfType_, "LastUpdateContactTVItemID", "Contact"), appErrLog.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [NotMapped] // appErrLog.HasErrors (Boolean) // ----------------------------------- // No testing requied // ----------------------------------- // Is NOT Nullable // [NotMapped] // appErrLog.ValidationResults (IEnumerable`1) // ----------------------------------- // No testing requied } } }
public IHttpActionResult GetAppErrLogList([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)) { AppErrLogService appErrLogService = new AppErrLogService(new Query() { Lang = lang }, db, ContactID); if (extra == "A") // QueryString contains [extra=A] { appErrLogService.Query = appErrLogService.FillQuery(typeof(AppErrLogExtraA), lang, skip, take, asc, desc, where, extra); if (appErrLogService.Query.HasErrors) { return(Ok(new List <AppErrLogExtraA>() { new AppErrLogExtraA() { HasErrors = appErrLogService.Query.HasErrors, ValidationResults = appErrLogService.Query.ValidationResults, }, }.ToList())); } else { return(Ok(appErrLogService.GetAppErrLogExtraAList().ToList())); } } else if (extra == "B") // QueryString contains [extra=B] { appErrLogService.Query = appErrLogService.FillQuery(typeof(AppErrLogExtraB), lang, skip, take, asc, desc, where, extra); if (appErrLogService.Query.HasErrors) { return(Ok(new List <AppErrLogExtraB>() { new AppErrLogExtraB() { HasErrors = appErrLogService.Query.HasErrors, ValidationResults = appErrLogService.Query.ValidationResults, }, }.ToList())); } else { return(Ok(appErrLogService.GetAppErrLogExtraBList().ToList())); } } else if (extra == "C") // QueryString contains [extra=C] { appErrLogService.Query = appErrLogService.FillQuery(typeof(AppErrLogExtraC), lang, skip, take, asc, desc, where, extra); if (appErrLogService.Query.HasErrors) { return(Ok(new List <AppErrLogExtraC>() { new AppErrLogExtraC() { HasErrors = appErrLogService.Query.HasErrors, ValidationResults = appErrLogService.Query.ValidationResults, }, }.ToList())); } else { return(Ok(appErrLogService.GetAppErrLogExtraCList().ToList())); } } else if (extra == "D") // QueryString contains [extra=D] { appErrLogService.Query = appErrLogService.FillQuery(typeof(AppErrLogExtraD), lang, skip, take, asc, desc, where, extra); if (appErrLogService.Query.HasErrors) { return(Ok(new List <AppErrLogExtraD>() { new AppErrLogExtraD() { HasErrors = appErrLogService.Query.HasErrors, ValidationResults = appErrLogService.Query.ValidationResults, }, }.ToList())); } else { return(Ok(appErrLogService.GetAppErrLogExtraDList().ToList())); } } else // QueryString has no parameter [extra] or extra is empty { appErrLogService.Query = appErrLogService.FillQuery(typeof(AppErrLog), lang, skip, take, asc, desc, where, extra); if (appErrLogService.Query.HasErrors) { return(Ok(new List <AppErrLog>() { new AppErrLog() { HasErrors = appErrLogService.Query.HasErrors, ValidationResults = appErrLogService.Query.ValidationResults, }, }.ToList())); } else { return(Ok(appErrLogService.GetAppErrLogList().ToList())); } } } }