public void MWQMSiteStartEndDate_CRUD_Test() { foreach (CultureInfo culture in AllowableCulture) { ChangeCulture(culture); using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { MWQMSiteStartEndDateService mwqmSiteStartEndDateService = new MWQMSiteStartEndDateService(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] } MWQMSiteStartEndDate mwqmSiteStartEndDate = GetFilledRandomMWQMSiteStartEndDate(""); // ------------------------------- // ------------------------------- // CRUD testing // ------------------------------- // ------------------------------- count = mwqmSiteStartEndDateService.GetMWQMSiteStartEndDateList().Count(); Assert.AreEqual(count, (from c in dbTestDB.MWQMSiteStartEndDates select c).Count()); mwqmSiteStartEndDateService.Add(mwqmSiteStartEndDate); if (mwqmSiteStartEndDate.HasErrors) { Assert.AreEqual("", mwqmSiteStartEndDate.ValidationResults.FirstOrDefault().ErrorMessage); } Assert.AreEqual(true, mwqmSiteStartEndDateService.GetMWQMSiteStartEndDateList().Where(c => c == mwqmSiteStartEndDate).Any()); mwqmSiteStartEndDateService.Update(mwqmSiteStartEndDate); if (mwqmSiteStartEndDate.HasErrors) { Assert.AreEqual("", mwqmSiteStartEndDate.ValidationResults.FirstOrDefault().ErrorMessage); } Assert.AreEqual(count + 1, mwqmSiteStartEndDateService.GetMWQMSiteStartEndDateList().Count()); mwqmSiteStartEndDateService.Delete(mwqmSiteStartEndDate); if (mwqmSiteStartEndDate.HasErrors) { Assert.AreEqual("", mwqmSiteStartEndDate.ValidationResults.FirstOrDefault().ErrorMessage); } Assert.AreEqual(count, mwqmSiteStartEndDateService.GetMWQMSiteStartEndDateList().Count()); } } }
public IHttpActionResult Put([FromBody] MWQMSiteStartEndDate mwqmSiteStartEndDate, [FromUri] string lang = "en") { using (CSSPDBContext db = new CSSPDBContext(DatabaseType)) { MWQMSiteStartEndDateService mwqmSiteStartEndDateService = new MWQMSiteStartEndDateService(new Query() { Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en) }, db, ContactID); if (!mwqmSiteStartEndDateService.Update(mwqmSiteStartEndDate)) { return(BadRequest(String.Join("|||", mwqmSiteStartEndDate.ValidationResults))); } else { mwqmSiteStartEndDate.ValidationResults = null; return(Ok(mwqmSiteStartEndDate)); } } }
public void MWQMSiteStartEndDate_Properties_Test() { foreach (CultureInfo culture in AllowableCulture) { ChangeCulture(culture); using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { MWQMSiteStartEndDateService mwqmSiteStartEndDateService = new MWQMSiteStartEndDateService(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 = mwqmSiteStartEndDateService.GetMWQMSiteStartEndDateList().Count(); MWQMSiteStartEndDate mwqmSiteStartEndDate = GetFilledRandomMWQMSiteStartEndDate(""); // ------------------------------- // ------------------------------- // Properties testing // ------------------------------- // ------------------------------- // ----------------------------------- // [Key] // Is NOT Nullable // mwqmSiteStartEndDate.MWQMSiteStartEndDateID (Int32) // ----------------------------------- mwqmSiteStartEndDate = null; mwqmSiteStartEndDate = GetFilledRandomMWQMSiteStartEndDate(""); mwqmSiteStartEndDate.MWQMSiteStartEndDateID = 0; mwqmSiteStartEndDateService.Update(mwqmSiteStartEndDate); Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "MWQMSiteStartEndDateID"), mwqmSiteStartEndDate.ValidationResults.FirstOrDefault().ErrorMessage); mwqmSiteStartEndDate = null; mwqmSiteStartEndDate = GetFilledRandomMWQMSiteStartEndDate(""); mwqmSiteStartEndDate.MWQMSiteStartEndDateID = 10000000; mwqmSiteStartEndDateService.Update(mwqmSiteStartEndDate); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "MWQMSiteStartEndDate", "MWQMSiteStartEndDateID", mwqmSiteStartEndDate.MWQMSiteStartEndDateID.ToString()), mwqmSiteStartEndDate.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [CSSPExist(ExistTypeName = "TVItem", ExistPlurial = "s", ExistFieldID = "TVItemID", AllowableTVtypeList = MWQMSite)] // mwqmSiteStartEndDate.MWQMSiteTVItemID (Int32) // ----------------------------------- mwqmSiteStartEndDate = null; mwqmSiteStartEndDate = GetFilledRandomMWQMSiteStartEndDate(""); mwqmSiteStartEndDate.MWQMSiteTVItemID = 0; mwqmSiteStartEndDateService.Add(mwqmSiteStartEndDate); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "MWQMSiteTVItemID", mwqmSiteStartEndDate.MWQMSiteTVItemID.ToString()), mwqmSiteStartEndDate.ValidationResults.FirstOrDefault().ErrorMessage); mwqmSiteStartEndDate = null; mwqmSiteStartEndDate = GetFilledRandomMWQMSiteStartEndDate(""); mwqmSiteStartEndDate.MWQMSiteTVItemID = 1; mwqmSiteStartEndDateService.Add(mwqmSiteStartEndDate); Assert.AreEqual(string.Format(CSSPServicesRes._IsNotOfType_, "MWQMSiteTVItemID", "MWQMSite"), mwqmSiteStartEndDate.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [CSSPAfter(Year = 1980)] // mwqmSiteStartEndDate.StartDate (DateTime) // ----------------------------------- mwqmSiteStartEndDate = null; mwqmSiteStartEndDate = GetFilledRandomMWQMSiteStartEndDate(""); mwqmSiteStartEndDate.StartDate = new DateTime(); mwqmSiteStartEndDateService.Add(mwqmSiteStartEndDate); Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "StartDate"), mwqmSiteStartEndDate.ValidationResults.FirstOrDefault().ErrorMessage); mwqmSiteStartEndDate = null; mwqmSiteStartEndDate = GetFilledRandomMWQMSiteStartEndDate(""); mwqmSiteStartEndDate.StartDate = new DateTime(1979, 1, 1); mwqmSiteStartEndDateService.Add(mwqmSiteStartEndDate); Assert.AreEqual(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "StartDate", "1980"), mwqmSiteStartEndDate.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is Nullable // [CSSPAfter(Year = 1980)] // [CSSPBigger(OtherField = StartDate)] // mwqmSiteStartEndDate.EndDate (DateTime) // ----------------------------------- mwqmSiteStartEndDate = null; mwqmSiteStartEndDate = GetFilledRandomMWQMSiteStartEndDate(""); mwqmSiteStartEndDate.EndDate = new DateTime(1979, 1, 1); mwqmSiteStartEndDateService.Add(mwqmSiteStartEndDate); Assert.AreEqual(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "EndDate", "1980"), mwqmSiteStartEndDate.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [CSSPAfter(Year = 1980)] // mwqmSiteStartEndDate.LastUpdateDate_UTC (DateTime) // ----------------------------------- mwqmSiteStartEndDate = null; mwqmSiteStartEndDate = GetFilledRandomMWQMSiteStartEndDate(""); mwqmSiteStartEndDate.LastUpdateDate_UTC = new DateTime(); mwqmSiteStartEndDateService.Add(mwqmSiteStartEndDate); Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "LastUpdateDate_UTC"), mwqmSiteStartEndDate.ValidationResults.FirstOrDefault().ErrorMessage); mwqmSiteStartEndDate = null; mwqmSiteStartEndDate = GetFilledRandomMWQMSiteStartEndDate(""); mwqmSiteStartEndDate.LastUpdateDate_UTC = new DateTime(1979, 1, 1); mwqmSiteStartEndDateService.Add(mwqmSiteStartEndDate); Assert.AreEqual(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "LastUpdateDate_UTC", "1980"), mwqmSiteStartEndDate.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [CSSPExist(ExistTypeName = "TVItem", ExistPlurial = "s", ExistFieldID = "TVItemID", AllowableTVtypeList = Contact)] // mwqmSiteStartEndDate.LastUpdateContactTVItemID (Int32) // ----------------------------------- mwqmSiteStartEndDate = null; mwqmSiteStartEndDate = GetFilledRandomMWQMSiteStartEndDate(""); mwqmSiteStartEndDate.LastUpdateContactTVItemID = 0; mwqmSiteStartEndDateService.Add(mwqmSiteStartEndDate); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "LastUpdateContactTVItemID", mwqmSiteStartEndDate.LastUpdateContactTVItemID.ToString()), mwqmSiteStartEndDate.ValidationResults.FirstOrDefault().ErrorMessage); mwqmSiteStartEndDate = null; mwqmSiteStartEndDate = GetFilledRandomMWQMSiteStartEndDate(""); mwqmSiteStartEndDate.LastUpdateContactTVItemID = 1; mwqmSiteStartEndDateService.Add(mwqmSiteStartEndDate); Assert.AreEqual(string.Format(CSSPServicesRes._IsNotOfType_, "LastUpdateContactTVItemID", "Contact"), mwqmSiteStartEndDate.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [NotMapped] // mwqmSiteStartEndDate.HasErrors (Boolean) // ----------------------------------- // No testing requied // ----------------------------------- // Is NOT Nullable // [NotMapped] // mwqmSiteStartEndDate.ValidationResults (IEnumerable`1) // ----------------------------------- // No testing requied } } }