public void SamplingPlanSubsectorSite_CRUD_Test() { foreach (CultureInfo culture in AllowableCulture) { ChangeCulture(culture); using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { SamplingPlanSubsectorSiteService samplingPlanSubsectorSiteService = new SamplingPlanSubsectorSiteService(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] } SamplingPlanSubsectorSite samplingPlanSubsectorSite = GetFilledRandomSamplingPlanSubsectorSite(""); // ------------------------------- // ------------------------------- // CRUD testing // ------------------------------- // ------------------------------- count = samplingPlanSubsectorSiteService.GetSamplingPlanSubsectorSiteList().Count(); Assert.AreEqual(count, (from c in dbTestDB.SamplingPlanSubsectorSites select c).Count()); samplingPlanSubsectorSiteService.Add(samplingPlanSubsectorSite); if (samplingPlanSubsectorSite.HasErrors) { Assert.AreEqual("", samplingPlanSubsectorSite.ValidationResults.FirstOrDefault().ErrorMessage); } Assert.AreEqual(true, samplingPlanSubsectorSiteService.GetSamplingPlanSubsectorSiteList().Where(c => c == samplingPlanSubsectorSite).Any()); samplingPlanSubsectorSiteService.Update(samplingPlanSubsectorSite); if (samplingPlanSubsectorSite.HasErrors) { Assert.AreEqual("", samplingPlanSubsectorSite.ValidationResults.FirstOrDefault().ErrorMessage); } Assert.AreEqual(count + 1, samplingPlanSubsectorSiteService.GetSamplingPlanSubsectorSiteList().Count()); samplingPlanSubsectorSiteService.Delete(samplingPlanSubsectorSite); if (samplingPlanSubsectorSite.HasErrors) { Assert.AreEqual("", samplingPlanSubsectorSite.ValidationResults.FirstOrDefault().ErrorMessage); } Assert.AreEqual(count, samplingPlanSubsectorSiteService.GetSamplingPlanSubsectorSiteList().Count()); } } }
public IHttpActionResult Post([FromBody] SamplingPlanSubsectorSite samplingPlanSubsectorSite, [FromUri] string lang = "en") { using (CSSPDBContext db = new CSSPDBContext(DatabaseType)) { SamplingPlanSubsectorSiteService samplingPlanSubsectorSiteService = new SamplingPlanSubsectorSiteService(new Query() { Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en) }, db, ContactID); if (!samplingPlanSubsectorSiteService.Add(samplingPlanSubsectorSite)) { return(BadRequest(String.Join("|||", samplingPlanSubsectorSite.ValidationResults))); } else { samplingPlanSubsectorSite.ValidationResults = null; return(Created <SamplingPlanSubsectorSite>(new Uri(Request.RequestUri, samplingPlanSubsectorSite.SamplingPlanSubsectorSiteID.ToString()), samplingPlanSubsectorSite)); } } }
public void SamplingPlanSubsectorSite_Properties_Test() { foreach (CultureInfo culture in AllowableCulture) { ChangeCulture(culture); using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { SamplingPlanSubsectorSiteService samplingPlanSubsectorSiteService = new SamplingPlanSubsectorSiteService(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 = samplingPlanSubsectorSiteService.GetSamplingPlanSubsectorSiteList().Count(); SamplingPlanSubsectorSite samplingPlanSubsectorSite = GetFilledRandomSamplingPlanSubsectorSite(""); // ------------------------------- // ------------------------------- // Properties testing // ------------------------------- // ------------------------------- // ----------------------------------- // [Key] // Is NOT Nullable // samplingPlanSubsectorSite.SamplingPlanSubsectorSiteID (Int32) // ----------------------------------- samplingPlanSubsectorSite = null; samplingPlanSubsectorSite = GetFilledRandomSamplingPlanSubsectorSite(""); samplingPlanSubsectorSite.SamplingPlanSubsectorSiteID = 0; samplingPlanSubsectorSiteService.Update(samplingPlanSubsectorSite); Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "SamplingPlanSubsectorSiteID"), samplingPlanSubsectorSite.ValidationResults.FirstOrDefault().ErrorMessage); samplingPlanSubsectorSite = null; samplingPlanSubsectorSite = GetFilledRandomSamplingPlanSubsectorSite(""); samplingPlanSubsectorSite.SamplingPlanSubsectorSiteID = 10000000; samplingPlanSubsectorSiteService.Update(samplingPlanSubsectorSite); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "SamplingPlanSubsectorSite", "SamplingPlanSubsectorSiteID", samplingPlanSubsectorSite.SamplingPlanSubsectorSiteID.ToString()), samplingPlanSubsectorSite.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [CSSPExist(ExistTypeName = "SamplingPlanSubsector", ExistPlurial = "s", ExistFieldID = "SamplingPlanSubsectorID", AllowableTVtypeList = )] // samplingPlanSubsectorSite.SamplingPlanSubsectorID (Int32) // ----------------------------------- samplingPlanSubsectorSite = null; samplingPlanSubsectorSite = GetFilledRandomSamplingPlanSubsectorSite(""); samplingPlanSubsectorSite.SamplingPlanSubsectorID = 0; samplingPlanSubsectorSiteService.Add(samplingPlanSubsectorSite); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "SamplingPlanSubsector", "SamplingPlanSubsectorID", samplingPlanSubsectorSite.SamplingPlanSubsectorID.ToString()), samplingPlanSubsectorSite.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [CSSPExist(ExistTypeName = "TVItem", ExistPlurial = "s", ExistFieldID = "TVItemID", AllowableTVtypeList = MWQMSite)] // samplingPlanSubsectorSite.MWQMSiteTVItemID (Int32) // ----------------------------------- samplingPlanSubsectorSite = null; samplingPlanSubsectorSite = GetFilledRandomSamplingPlanSubsectorSite(""); samplingPlanSubsectorSite.MWQMSiteTVItemID = 0; samplingPlanSubsectorSiteService.Add(samplingPlanSubsectorSite); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "MWQMSiteTVItemID", samplingPlanSubsectorSite.MWQMSiteTVItemID.ToString()), samplingPlanSubsectorSite.ValidationResults.FirstOrDefault().ErrorMessage); samplingPlanSubsectorSite = null; samplingPlanSubsectorSite = GetFilledRandomSamplingPlanSubsectorSite(""); samplingPlanSubsectorSite.MWQMSiteTVItemID = 1; samplingPlanSubsectorSiteService.Add(samplingPlanSubsectorSite); Assert.AreEqual(string.Format(CSSPServicesRes._IsNotOfType_, "MWQMSiteTVItemID", "MWQMSite"), samplingPlanSubsectorSite.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // samplingPlanSubsectorSite.IsDuplicate (Boolean) // ----------------------------------- // ----------------------------------- // Is NOT Nullable // [CSSPAfter(Year = 1980)] // samplingPlanSubsectorSite.LastUpdateDate_UTC (DateTime) // ----------------------------------- samplingPlanSubsectorSite = null; samplingPlanSubsectorSite = GetFilledRandomSamplingPlanSubsectorSite(""); samplingPlanSubsectorSite.LastUpdateDate_UTC = new DateTime(); samplingPlanSubsectorSiteService.Add(samplingPlanSubsectorSite); Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "LastUpdateDate_UTC"), samplingPlanSubsectorSite.ValidationResults.FirstOrDefault().ErrorMessage); samplingPlanSubsectorSite = null; samplingPlanSubsectorSite = GetFilledRandomSamplingPlanSubsectorSite(""); samplingPlanSubsectorSite.LastUpdateDate_UTC = new DateTime(1979, 1, 1); samplingPlanSubsectorSiteService.Add(samplingPlanSubsectorSite); Assert.AreEqual(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "LastUpdateDate_UTC", "1980"), samplingPlanSubsectorSite.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [CSSPExist(ExistTypeName = "TVItem", ExistPlurial = "s", ExistFieldID = "TVItemID", AllowableTVtypeList = Contact)] // samplingPlanSubsectorSite.LastUpdateContactTVItemID (Int32) // ----------------------------------- samplingPlanSubsectorSite = null; samplingPlanSubsectorSite = GetFilledRandomSamplingPlanSubsectorSite(""); samplingPlanSubsectorSite.LastUpdateContactTVItemID = 0; samplingPlanSubsectorSiteService.Add(samplingPlanSubsectorSite); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "LastUpdateContactTVItemID", samplingPlanSubsectorSite.LastUpdateContactTVItemID.ToString()), samplingPlanSubsectorSite.ValidationResults.FirstOrDefault().ErrorMessage); samplingPlanSubsectorSite = null; samplingPlanSubsectorSite = GetFilledRandomSamplingPlanSubsectorSite(""); samplingPlanSubsectorSite.LastUpdateContactTVItemID = 1; samplingPlanSubsectorSiteService.Add(samplingPlanSubsectorSite); Assert.AreEqual(string.Format(CSSPServicesRes._IsNotOfType_, "LastUpdateContactTVItemID", "Contact"), samplingPlanSubsectorSite.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [NotMapped] // samplingPlanSubsectorSite.HasErrors (Boolean) // ----------------------------------- // No testing requied // ----------------------------------- // Is NOT Nullable // [NotMapped] // samplingPlanSubsectorSite.ValidationResults (IEnumerable`1) // ----------------------------------- // No testing requied } } }