public void PolSourceSite_CRUD_Test() { foreach (CultureInfo culture in AllowableCulture) { ChangeCulture(culture); using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { PolSourceSiteService polSourceSiteService = new PolSourceSiteService(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] } PolSourceSite polSourceSite = GetFilledRandomPolSourceSite(""); // ------------------------------- // ------------------------------- // CRUD testing // ------------------------------- // ------------------------------- count = polSourceSiteService.GetPolSourceSiteList().Count(); Assert.AreEqual(count, (from c in dbTestDB.PolSourceSites select c).Count()); polSourceSiteService.Add(polSourceSite); if (polSourceSite.HasErrors) { Assert.AreEqual("", polSourceSite.ValidationResults.FirstOrDefault().ErrorMessage); } Assert.AreEqual(true, polSourceSiteService.GetPolSourceSiteList().Where(c => c == polSourceSite).Any()); polSourceSiteService.Update(polSourceSite); if (polSourceSite.HasErrors) { Assert.AreEqual("", polSourceSite.ValidationResults.FirstOrDefault().ErrorMessage); } Assert.AreEqual(count + 1, polSourceSiteService.GetPolSourceSiteList().Count()); polSourceSiteService.Delete(polSourceSite); if (polSourceSite.HasErrors) { Assert.AreEqual("", polSourceSite.ValidationResults.FirstOrDefault().ErrorMessage); } Assert.AreEqual(count, polSourceSiteService.GetPolSourceSiteList().Count()); } } }
public IHttpActionResult Put([FromBody] PolSourceSite polSourceSite, [FromUri] string lang = "en") { using (CSSPDBContext db = new CSSPDBContext(DatabaseType)) { PolSourceSiteService polSourceSiteService = new PolSourceSiteService(new Query() { Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en) }, db, ContactID); if (!polSourceSiteService.Update(polSourceSite)) { return(BadRequest(String.Join("|||", polSourceSite.ValidationResults))); } else { polSourceSite.ValidationResults = null; return(Ok(polSourceSite)); } } }
public void PolSourceSite_Properties_Test() { foreach (CultureInfo culture in AllowableCulture) { ChangeCulture(culture); using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { PolSourceSiteService polSourceSiteService = new PolSourceSiteService(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 = polSourceSiteService.GetPolSourceSiteList().Count(); PolSourceSite polSourceSite = GetFilledRandomPolSourceSite(""); // ------------------------------- // ------------------------------- // Properties testing // ------------------------------- // ------------------------------- // ----------------------------------- // [Key] // Is NOT Nullable // polSourceSite.PolSourceSiteID (Int32) // ----------------------------------- polSourceSite = null; polSourceSite = GetFilledRandomPolSourceSite(""); polSourceSite.PolSourceSiteID = 0; polSourceSiteService.Update(polSourceSite); Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "PolSourceSiteID"), polSourceSite.ValidationResults.FirstOrDefault().ErrorMessage); polSourceSite = null; polSourceSite = GetFilledRandomPolSourceSite(""); polSourceSite.PolSourceSiteID = 10000000; polSourceSiteService.Update(polSourceSite); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "PolSourceSite", "PolSourceSiteID", polSourceSite.PolSourceSiteID.ToString()), polSourceSite.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [CSSPExist(ExistTypeName = "TVItem", ExistPlurial = "s", ExistFieldID = "TVItemID", AllowableTVtypeList = PolSourceSite)] // polSourceSite.PolSourceSiteTVItemID (Int32) // ----------------------------------- polSourceSite = null; polSourceSite = GetFilledRandomPolSourceSite(""); polSourceSite.PolSourceSiteTVItemID = 0; polSourceSiteService.Add(polSourceSite); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "PolSourceSiteTVItemID", polSourceSite.PolSourceSiteTVItemID.ToString()), polSourceSite.ValidationResults.FirstOrDefault().ErrorMessage); polSourceSite = null; polSourceSite = GetFilledRandomPolSourceSite(""); polSourceSite.PolSourceSiteTVItemID = 1; polSourceSiteService.Add(polSourceSite); Assert.AreEqual(string.Format(CSSPServicesRes._IsNotOfType_, "PolSourceSiteTVItemID", "PolSourceSite"), polSourceSite.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is Nullable // [StringLength(50))] // polSourceSite.Temp_Locator_CanDelete (String) // ----------------------------------- polSourceSite = null; polSourceSite = GetFilledRandomPolSourceSite(""); polSourceSite.Temp_Locator_CanDelete = GetRandomString("", 51); Assert.AreEqual(false, polSourceSiteService.Add(polSourceSite)); Assert.AreEqual(string.Format(CSSPServicesRes._MaxLengthIs_, "Temp_Locator_CanDelete", "50"), polSourceSite.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, polSourceSiteService.GetPolSourceSiteList().Count()); // ----------------------------------- // Is Nullable // [Range(0, 1000)] // polSourceSite.Oldsiteid (Int32) // ----------------------------------- polSourceSite = null; polSourceSite = GetFilledRandomPolSourceSite(""); polSourceSite.Oldsiteid = -1; Assert.AreEqual(false, polSourceSiteService.Add(polSourceSite)); Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "Oldsiteid", "0", "1000"), polSourceSite.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, polSourceSiteService.GetPolSourceSiteList().Count()); polSourceSite = null; polSourceSite = GetFilledRandomPolSourceSite(""); polSourceSite.Oldsiteid = 1001; Assert.AreEqual(false, polSourceSiteService.Add(polSourceSite)); Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "Oldsiteid", "0", "1000"), polSourceSite.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, polSourceSiteService.GetPolSourceSiteList().Count()); // ----------------------------------- // Is Nullable // [Range(0, 1000)] // polSourceSite.Site (Int32) // ----------------------------------- polSourceSite = null; polSourceSite = GetFilledRandomPolSourceSite(""); polSourceSite.Site = -1; Assert.AreEqual(false, polSourceSiteService.Add(polSourceSite)); Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "Site", "0", "1000"), polSourceSite.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, polSourceSiteService.GetPolSourceSiteList().Count()); polSourceSite = null; polSourceSite = GetFilledRandomPolSourceSite(""); polSourceSite.Site = 1001; Assert.AreEqual(false, polSourceSiteService.Add(polSourceSite)); Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "Site", "0", "1000"), polSourceSite.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, polSourceSiteService.GetPolSourceSiteList().Count()); // ----------------------------------- // Is Nullable // [Range(0, 1000)] // polSourceSite.SiteID (Int32) // ----------------------------------- polSourceSite = null; polSourceSite = GetFilledRandomPolSourceSite(""); polSourceSite.SiteID = -1; Assert.AreEqual(false, polSourceSiteService.Add(polSourceSite)); Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "SiteID", "0", "1000"), polSourceSite.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, polSourceSiteService.GetPolSourceSiteList().Count()); polSourceSite = null; polSourceSite = GetFilledRandomPolSourceSite(""); polSourceSite.SiteID = 1001; Assert.AreEqual(false, polSourceSiteService.Add(polSourceSite)); Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "SiteID", "0", "1000"), polSourceSite.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, polSourceSiteService.GetPolSourceSiteList().Count()); // ----------------------------------- // Is NOT Nullable // polSourceSite.IsPointSource (Boolean) // ----------------------------------- // ----------------------------------- // Is Nullable // [CSSPEnumType] // polSourceSite.InactiveReason (PolSourceInactiveReasonEnum) // ----------------------------------- polSourceSite = null; polSourceSite = GetFilledRandomPolSourceSite(""); polSourceSite.InactiveReason = (PolSourceInactiveReasonEnum)1000000; polSourceSiteService.Add(polSourceSite); Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "InactiveReason"), polSourceSite.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is Nullable // [CSSPExist(ExistTypeName = "TVItem", ExistPlurial = "s", ExistFieldID = "TVItemID", AllowableTVtypeList = Address)] // polSourceSite.CivicAddressTVItemID (Int32) // ----------------------------------- polSourceSite = null; polSourceSite = GetFilledRandomPolSourceSite(""); polSourceSite.CivicAddressTVItemID = 0; polSourceSiteService.Add(polSourceSite); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "CivicAddressTVItemID", polSourceSite.CivicAddressTVItemID.ToString()), polSourceSite.ValidationResults.FirstOrDefault().ErrorMessage); polSourceSite = null; polSourceSite = GetFilledRandomPolSourceSite(""); polSourceSite.CivicAddressTVItemID = 1; polSourceSiteService.Add(polSourceSite); Assert.AreEqual(string.Format(CSSPServicesRes._IsNotOfType_, "CivicAddressTVItemID", "Address"), polSourceSite.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [CSSPAfter(Year = 1980)] // polSourceSite.LastUpdateDate_UTC (DateTime) // ----------------------------------- polSourceSite = null; polSourceSite = GetFilledRandomPolSourceSite(""); polSourceSite.LastUpdateDate_UTC = new DateTime(); polSourceSiteService.Add(polSourceSite); Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "LastUpdateDate_UTC"), polSourceSite.ValidationResults.FirstOrDefault().ErrorMessage); polSourceSite = null; polSourceSite = GetFilledRandomPolSourceSite(""); polSourceSite.LastUpdateDate_UTC = new DateTime(1979, 1, 1); polSourceSiteService.Add(polSourceSite); Assert.AreEqual(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "LastUpdateDate_UTC", "1980"), polSourceSite.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [CSSPExist(ExistTypeName = "TVItem", ExistPlurial = "s", ExistFieldID = "TVItemID", AllowableTVtypeList = Contact)] // polSourceSite.LastUpdateContactTVItemID (Int32) // ----------------------------------- polSourceSite = null; polSourceSite = GetFilledRandomPolSourceSite(""); polSourceSite.LastUpdateContactTVItemID = 0; polSourceSiteService.Add(polSourceSite); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "LastUpdateContactTVItemID", polSourceSite.LastUpdateContactTVItemID.ToString()), polSourceSite.ValidationResults.FirstOrDefault().ErrorMessage); polSourceSite = null; polSourceSite = GetFilledRandomPolSourceSite(""); polSourceSite.LastUpdateContactTVItemID = 1; polSourceSiteService.Add(polSourceSite); Assert.AreEqual(string.Format(CSSPServicesRes._IsNotOfType_, "LastUpdateContactTVItemID", "Contact"), polSourceSite.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [NotMapped] // polSourceSite.HasErrors (Boolean) // ----------------------------------- // No testing requied // ----------------------------------- // Is NOT Nullable // [NotMapped] // polSourceSite.ValidationResults (IEnumerable`1) // ----------------------------------- // No testing requied } } }