public void PolSourceSiteEffect_CRUD_Test() { foreach (CultureInfo culture in AllowableCulture) { ChangeCulture(culture); using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { PolSourceSiteEffectService polSourceSiteEffectService = new PolSourceSiteEffectService(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] } PolSourceSiteEffect polSourceSiteEffect = GetFilledRandomPolSourceSiteEffect(""); // ------------------------------- // ------------------------------- // CRUD testing // ------------------------------- // ------------------------------- count = polSourceSiteEffectService.GetPolSourceSiteEffectList().Count(); Assert.AreEqual(count, (from c in dbTestDB.PolSourceSiteEffects select c).Count()); polSourceSiteEffectService.Add(polSourceSiteEffect); if (polSourceSiteEffect.HasErrors) { Assert.AreEqual("", polSourceSiteEffect.ValidationResults.FirstOrDefault().ErrorMessage); } Assert.AreEqual(true, polSourceSiteEffectService.GetPolSourceSiteEffectList().Where(c => c == polSourceSiteEffect).Any()); polSourceSiteEffectService.Update(polSourceSiteEffect); if (polSourceSiteEffect.HasErrors) { Assert.AreEqual("", polSourceSiteEffect.ValidationResults.FirstOrDefault().ErrorMessage); } Assert.AreEqual(count + 1, polSourceSiteEffectService.GetPolSourceSiteEffectList().Count()); polSourceSiteEffectService.Delete(polSourceSiteEffect); if (polSourceSiteEffect.HasErrors) { Assert.AreEqual("", polSourceSiteEffect.ValidationResults.FirstOrDefault().ErrorMessage); } Assert.AreEqual(count, polSourceSiteEffectService.GetPolSourceSiteEffectList().Count()); } } }
public void GetPolSourceSiteEffectList_Test() { foreach (CultureInfo culture in AllowableCulture) { ChangeCulture(culture); using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { PolSourceSiteEffectService polSourceSiteEffectService = new PolSourceSiteEffectService(new Query() { Lang = culture.TwoLetterISOLanguageName }, dbTestDB, ContactID); PolSourceSiteEffect polSourceSiteEffect = (from c in dbTestDB.PolSourceSiteEffects select c).FirstOrDefault(); Assert.IsNotNull(polSourceSiteEffect); List <PolSourceSiteEffect> polSourceSiteEffectDirectQueryList = new List <PolSourceSiteEffect>(); polSourceSiteEffectDirectQueryList = (from c in dbTestDB.PolSourceSiteEffects select c).Take(200).ToList(); foreach (string extra in new List <string>() { null, "A", "B", "C", "D", "E" }) { polSourceSiteEffectService.Query.Extra = extra; if (string.IsNullOrWhiteSpace(extra)) { List <PolSourceSiteEffect> polSourceSiteEffectList = new List <PolSourceSiteEffect>(); polSourceSiteEffectList = polSourceSiteEffectService.GetPolSourceSiteEffectList().ToList(); CheckPolSourceSiteEffectFields(polSourceSiteEffectList); } else { //Assert.AreEqual(true, false); } } } } }
public void GetPolSourceSiteEffectList_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" }) { PolSourceSiteEffectService polSourceSiteEffectService = new PolSourceSiteEffectService(new Query() { Lang = culture.TwoLetterISOLanguageName }, dbTestDB, ContactID); polSourceSiteEffectService.Query = polSourceSiteEffectService.FillQuery(typeof(PolSourceSiteEffect), culture.TwoLetterISOLanguageName, 0, 10000, "", "", "PolSourceSiteEffectID,GT,2|PolSourceSiteEffectID,LT,5", extra); List <PolSourceSiteEffect> polSourceSiteEffectDirectQueryList = new List <PolSourceSiteEffect>(); polSourceSiteEffectDirectQueryList = (from c in dbTestDB.PolSourceSiteEffects select c).Where(c => c.PolSourceSiteEffectID > 2 && c.PolSourceSiteEffectID < 5).ToList(); if (string.IsNullOrWhiteSpace(extra)) { List <PolSourceSiteEffect> polSourceSiteEffectList = new List <PolSourceSiteEffect>(); polSourceSiteEffectList = polSourceSiteEffectService.GetPolSourceSiteEffectList().ToList(); CheckPolSourceSiteEffectFields(polSourceSiteEffectList); Assert.AreEqual(polSourceSiteEffectDirectQueryList[0].PolSourceSiteEffectID, polSourceSiteEffectList[0].PolSourceSiteEffectID); } else { //Assert.AreEqual(true, false); } } } } }
public void GetPolSourceSiteEffectList_Skip_Take_2Desc_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" }) { PolSourceSiteEffectService polSourceSiteEffectService = new PolSourceSiteEffectService(new Query() { Lang = culture.TwoLetterISOLanguageName }, dbTestDB, ContactID); polSourceSiteEffectService.Query = polSourceSiteEffectService.FillQuery(typeof(PolSourceSiteEffect), culture.TwoLetterISOLanguageName, 1, 1, "", "PolSourceSiteEffectID,PolSourceSiteOrInfrastructureTVItemID", "", extra); List <PolSourceSiteEffect> polSourceSiteEffectDirectQueryList = new List <PolSourceSiteEffect>(); polSourceSiteEffectDirectQueryList = (from c in dbTestDB.PolSourceSiteEffects select c).OrderByDescending(c => c.PolSourceSiteEffectID).ThenByDescending(c => c.PolSourceSiteOrInfrastructureTVItemID).Skip(1).Take(1).ToList(); if (string.IsNullOrWhiteSpace(extra)) { List <PolSourceSiteEffect> polSourceSiteEffectList = new List <PolSourceSiteEffect>(); polSourceSiteEffectList = polSourceSiteEffectService.GetPolSourceSiteEffectList().ToList(); CheckPolSourceSiteEffectFields(polSourceSiteEffectList); Assert.AreEqual(polSourceSiteEffectDirectQueryList[0].PolSourceSiteEffectID, polSourceSiteEffectList[0].PolSourceSiteEffectID); } else { //Assert.AreEqual(true, false); } } } } }
public void PolSourceSiteEffect_Properties_Test() { foreach (CultureInfo culture in AllowableCulture) { ChangeCulture(culture); using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { PolSourceSiteEffectService polSourceSiteEffectService = new PolSourceSiteEffectService(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 = polSourceSiteEffectService.GetPolSourceSiteEffectList().Count(); PolSourceSiteEffect polSourceSiteEffect = GetFilledRandomPolSourceSiteEffect(""); // ------------------------------- // ------------------------------- // Properties testing // ------------------------------- // ------------------------------- // ----------------------------------- // [Key] // Is NOT Nullable // polSourceSiteEffect.PolSourceSiteEffectID (Int32) // ----------------------------------- polSourceSiteEffect = null; polSourceSiteEffect = GetFilledRandomPolSourceSiteEffect(""); polSourceSiteEffect.PolSourceSiteEffectID = 0; polSourceSiteEffectService.Update(polSourceSiteEffect); Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "PolSourceSiteEffectID"), polSourceSiteEffect.ValidationResults.FirstOrDefault().ErrorMessage); polSourceSiteEffect = null; polSourceSiteEffect = GetFilledRandomPolSourceSiteEffect(""); polSourceSiteEffect.PolSourceSiteEffectID = 10000000; polSourceSiteEffectService.Update(polSourceSiteEffect); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "PolSourceSiteEffect", "PolSourceSiteEffectID", polSourceSiteEffect.PolSourceSiteEffectID.ToString()), polSourceSiteEffect.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [CSSPExist(ExistTypeName = "TVItem", ExistPlurial = "s", ExistFieldID = "TVItemID", AllowableTVtypeList = Infrastructure,PolSourceSite)] // polSourceSiteEffect.PolSourceSiteOrInfrastructureTVItemID (Int32) // ----------------------------------- polSourceSiteEffect = null; polSourceSiteEffect = GetFilledRandomPolSourceSiteEffect(""); polSourceSiteEffect.PolSourceSiteOrInfrastructureTVItemID = 0; polSourceSiteEffectService.Add(polSourceSiteEffect); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "PolSourceSiteOrInfrastructureTVItemID", polSourceSiteEffect.PolSourceSiteOrInfrastructureTVItemID.ToString()), polSourceSiteEffect.ValidationResults.FirstOrDefault().ErrorMessage); polSourceSiteEffect = null; polSourceSiteEffect = GetFilledRandomPolSourceSiteEffect(""); polSourceSiteEffect.PolSourceSiteOrInfrastructureTVItemID = 1; polSourceSiteEffectService.Add(polSourceSiteEffect); Assert.AreEqual(string.Format(CSSPServicesRes._IsNotOfType_, "PolSourceSiteOrInfrastructureTVItemID", "Infrastructure,PolSourceSite"), polSourceSiteEffect.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [CSSPExist(ExistTypeName = "TVItem", ExistPlurial = "s", ExistFieldID = "TVItemID", AllowableTVtypeList = MWQMSite)] // polSourceSiteEffect.MWQMSiteTVItemID (Int32) // ----------------------------------- polSourceSiteEffect = null; polSourceSiteEffect = GetFilledRandomPolSourceSiteEffect(""); polSourceSiteEffect.MWQMSiteTVItemID = 0; polSourceSiteEffectService.Add(polSourceSiteEffect); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "MWQMSiteTVItemID", polSourceSiteEffect.MWQMSiteTVItemID.ToString()), polSourceSiteEffect.ValidationResults.FirstOrDefault().ErrorMessage); polSourceSiteEffect = null; polSourceSiteEffect = GetFilledRandomPolSourceSiteEffect(""); polSourceSiteEffect.MWQMSiteTVItemID = 1; polSourceSiteEffectService.Add(polSourceSiteEffect); Assert.AreEqual(string.Format(CSSPServicesRes._IsNotOfType_, "MWQMSiteTVItemID", "MWQMSite"), polSourceSiteEffect.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is Nullable // [StringLength(250))] // polSourceSiteEffect.PolSourceSiteEffectTermIDs (String) // ----------------------------------- polSourceSiteEffect = null; polSourceSiteEffect = GetFilledRandomPolSourceSiteEffect(""); polSourceSiteEffect.PolSourceSiteEffectTermIDs = GetRandomString("", 251); Assert.AreEqual(false, polSourceSiteEffectService.Add(polSourceSiteEffect)); Assert.AreEqual(string.Format(CSSPServicesRes._MaxLengthIs_, "PolSourceSiteEffectTermIDs", "250"), polSourceSiteEffect.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, polSourceSiteEffectService.GetPolSourceSiteEffectList().Count()); // ----------------------------------- // Is Nullable // polSourceSiteEffect.Comments (String) // ----------------------------------- // ----------------------------------- // Is Nullable // [CSSPExist(ExistTypeName = "TVItem", ExistPlurial = "s", ExistFieldID = "TVItemID", AllowableTVtypeList = File)] // polSourceSiteEffect.AnalysisDocumentTVItemID (Int32) // ----------------------------------- polSourceSiteEffect = null; polSourceSiteEffect = GetFilledRandomPolSourceSiteEffect(""); polSourceSiteEffect.AnalysisDocumentTVItemID = 0; polSourceSiteEffectService.Add(polSourceSiteEffect); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "AnalysisDocumentTVItemID", polSourceSiteEffect.AnalysisDocumentTVItemID.ToString()), polSourceSiteEffect.ValidationResults.FirstOrDefault().ErrorMessage); polSourceSiteEffect = null; polSourceSiteEffect = GetFilledRandomPolSourceSiteEffect(""); polSourceSiteEffect.AnalysisDocumentTVItemID = 1; polSourceSiteEffectService.Add(polSourceSiteEffect); Assert.AreEqual(string.Format(CSSPServicesRes._IsNotOfType_, "AnalysisDocumentTVItemID", "File"), polSourceSiteEffect.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [CSSPAfter(Year = 1980)] // polSourceSiteEffect.LastUpdateDate_UTC (DateTime) // ----------------------------------- polSourceSiteEffect = null; polSourceSiteEffect = GetFilledRandomPolSourceSiteEffect(""); polSourceSiteEffect.LastUpdateDate_UTC = new DateTime(); polSourceSiteEffectService.Add(polSourceSiteEffect); Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "LastUpdateDate_UTC"), polSourceSiteEffect.ValidationResults.FirstOrDefault().ErrorMessage); polSourceSiteEffect = null; polSourceSiteEffect = GetFilledRandomPolSourceSiteEffect(""); polSourceSiteEffect.LastUpdateDate_UTC = new DateTime(1979, 1, 1); polSourceSiteEffectService.Add(polSourceSiteEffect); Assert.AreEqual(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "LastUpdateDate_UTC", "1980"), polSourceSiteEffect.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [CSSPExist(ExistTypeName = "TVItem", ExistPlurial = "s", ExistFieldID = "TVItemID", AllowableTVtypeList = Contact)] // polSourceSiteEffect.LastUpdateContactTVItemID (Int32) // ----------------------------------- polSourceSiteEffect = null; polSourceSiteEffect = GetFilledRandomPolSourceSiteEffect(""); polSourceSiteEffect.LastUpdateContactTVItemID = 0; polSourceSiteEffectService.Add(polSourceSiteEffect); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "LastUpdateContactTVItemID", polSourceSiteEffect.LastUpdateContactTVItemID.ToString()), polSourceSiteEffect.ValidationResults.FirstOrDefault().ErrorMessage); polSourceSiteEffect = null; polSourceSiteEffect = GetFilledRandomPolSourceSiteEffect(""); polSourceSiteEffect.LastUpdateContactTVItemID = 1; polSourceSiteEffectService.Add(polSourceSiteEffect); Assert.AreEqual(string.Format(CSSPServicesRes._IsNotOfType_, "LastUpdateContactTVItemID", "Contact"), polSourceSiteEffect.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [NotMapped] // polSourceSiteEffect.HasErrors (Boolean) // ----------------------------------- // No testing requied // ----------------------------------- // Is NOT Nullable // [NotMapped] // polSourceSiteEffect.ValidationResults (IEnumerable`1) // ----------------------------------- // No testing requied } } }