private MWQMSiteStartEndDate GetFilledRandomMWQMSiteStartEndDate(string OmitPropName) { MWQMSiteStartEndDate mwqmSiteStartEndDate = new MWQMSiteStartEndDate(); if (OmitPropName != "MWQMSiteTVItemID") { mwqmSiteStartEndDate.MWQMSiteTVItemID = 44; } if (OmitPropName != "StartDate") { mwqmSiteStartEndDate.StartDate = new DateTime(2005, 3, 6); } if (OmitPropName != "EndDate") { mwqmSiteStartEndDate.EndDate = new DateTime(2005, 3, 7); } if (OmitPropName != "LastUpdateDate_UTC") { mwqmSiteStartEndDate.LastUpdateDate_UTC = new DateTime(2005, 3, 6); } if (OmitPropName != "LastUpdateContactTVItemID") { mwqmSiteStartEndDate.LastUpdateContactTVItemID = 2; } return(mwqmSiteStartEndDate); }
public MWQMSiteStartEndDate GetMWQMSiteStartEndDateWithMWQMSiteStartEndDateIDDB(int MWQMSiteStartEndDateID) { MWQMSiteStartEndDate mwqmSiteStartEndDate = (from c in db.MWQMSiteStartEndDates where c.MWQMSiteStartEndDateID == MWQMSiteStartEndDateID select c).FirstOrDefault <MWQMSiteStartEndDate>(); return(mwqmSiteStartEndDate); }
public MWQMSiteStartEndDateModel PostAddMWQMSiteStartEndDateDB(MWQMSiteStartEndDateModel mwqmSiteStartEndDateModel) { string retStr = MWQMSiteStartEndDateModelOK(mwqmSiteStartEndDateModel); if (!string.IsNullOrWhiteSpace(retStr)) { return(ReturnError(retStr)); } ContactOK contactOK = IsContactOK(); if (!string.IsNullOrEmpty(contactOK.Error)) { return(ReturnError(contactOK.Error)); } TVItemModel tvItemModelExist = _TVItemService.GetTVItemModelWithTVItemIDDB(mwqmSiteStartEndDateModel.MWQMSiteTVItemID); if (!string.IsNullOrWhiteSpace(tvItemModelExist.Error)) { return(ReturnError(tvItemModelExist.Error)); } MWQMSiteStartEndDateModel MWQMSiteStartEndDateModelExist = GetMWQMSiteStartEndDateExistDB(mwqmSiteStartEndDateModel); if (string.IsNullOrWhiteSpace(MWQMSiteStartEndDateModelExist.Error)) { return(ReturnError(string.Format(ServiceRes._AlreadyExists, ServiceRes.MWQMSiteStartEndDate))); } MWQMSiteStartEndDate mwqmSiteStartEndDateNew = new MWQMSiteStartEndDate(); retStr = FillMWQMSiteStartEndDate(mwqmSiteStartEndDateNew, mwqmSiteStartEndDateModel, contactOK); if (!string.IsNullOrWhiteSpace(retStr)) { return(ReturnError(retStr)); } using (TransactionScope ts = new TransactionScope()) { db.MWQMSiteStartEndDates.Add(mwqmSiteStartEndDateNew); retStr = DoAddChanges(); if (!string.IsNullOrWhiteSpace(retStr)) { return(ReturnError(retStr)); } LogModel logModel = _LogService.PostAddLogForObj("MWQMSiteStartEndDates", mwqmSiteStartEndDateNew.MWQMSiteStartEndDateID, LogCommandEnum.Add, mwqmSiteStartEndDateNew); if (!string.IsNullOrWhiteSpace(logModel.Error)) { return(ReturnError(logModel.Error)); } ts.Complete(); } return(GetMWQMSiteStartEndDateModelWithMWQMSiteStartEndDateIDDB(mwqmSiteStartEndDateNew.MWQMSiteStartEndDateID)); }
public void MWQMSiteStartEndDate_Controller_Put_Test() { foreach (LanguageEnum LanguageRequest in AllowableLanguages) { foreach (int ContactID in new List <int>() { AdminContactID }) //, TestEmailValidatedContactID, TestEmailNotValidatedContactID }) { MWQMSiteStartEndDateController mwqmSiteStartEndDateController = new MWQMSiteStartEndDateController(DatabaseTypeEnum.SqlServerTestDB); Assert.IsNotNull(mwqmSiteStartEndDateController); Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, mwqmSiteStartEndDateController.DatabaseType); MWQMSiteStartEndDate mwqmSiteStartEndDateLast = new MWQMSiteStartEndDate(); using (CSSPDBContext db = new CSSPDBContext(DatabaseType)) { Query query = new Query(); query.Language = LanguageRequest; MWQMSiteStartEndDateService mwqmSiteStartEndDateService = new MWQMSiteStartEndDateService(query, db, ContactID); mwqmSiteStartEndDateLast = (from c in db.MWQMSiteStartEndDates select c).FirstOrDefault(); } // ok with MWQMSiteStartEndDate info IHttpActionResult jsonRet = mwqmSiteStartEndDateController.GetMWQMSiteStartEndDateWithID(mwqmSiteStartEndDateLast.MWQMSiteStartEndDateID); Assert.IsNotNull(jsonRet); OkNegotiatedContentResult <MWQMSiteStartEndDate> Ret = jsonRet as OkNegotiatedContentResult <MWQMSiteStartEndDate>; MWQMSiteStartEndDate mwqmSiteStartEndDateRet = Ret.Content; Assert.AreEqual(mwqmSiteStartEndDateLast.MWQMSiteStartEndDateID, mwqmSiteStartEndDateRet.MWQMSiteStartEndDateID); BadRequestErrorMessageResult badRequest = jsonRet as BadRequestErrorMessageResult; Assert.IsNull(badRequest); // Put to return success IHttpActionResult jsonRet2 = mwqmSiteStartEndDateController.Put(mwqmSiteStartEndDateRet, LanguageRequest.ToString()); Assert.IsNotNull(jsonRet2); OkNegotiatedContentResult <MWQMSiteStartEndDate> mwqmSiteStartEndDateRet2 = jsonRet2 as OkNegotiatedContentResult <MWQMSiteStartEndDate>; Assert.IsNotNull(mwqmSiteStartEndDateRet2); BadRequestErrorMessageResult badRequest2 = jsonRet2 as BadRequestErrorMessageResult; Assert.IsNull(badRequest2); // Put to return CSSPError because MWQMSiteStartEndDateID of 0 does not exist mwqmSiteStartEndDateRet.MWQMSiteStartEndDateID = 0; IHttpActionResult jsonRet3 = mwqmSiteStartEndDateController.Put(mwqmSiteStartEndDateRet, LanguageRequest.ToString()); Assert.IsNotNull(jsonRet3); OkNegotiatedContentResult <MWQMSiteStartEndDate> mwqmSiteStartEndDateRet3 = jsonRet3 as OkNegotiatedContentResult <MWQMSiteStartEndDate>; Assert.IsNull(mwqmSiteStartEndDateRet3); BadRequestErrorMessageResult badRequest3 = jsonRet3 as BadRequestErrorMessageResult; Assert.IsNotNull(badRequest3); } } }
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 void SetupTest(ContactModel contactModelToDo, CultureInfo culture) { Thread.CurrentThread.CurrentCulture = culture; Thread.CurrentThread.CurrentUICulture = culture; contactModel = contactModelToDo; user = new GenericPrincipal(new GenericIdentity(contactModel.LoginEmail, "Forms"), null); mwqmSiteStartEndDateService = new MWQMSiteStartEndDateService((culture.TwoLetterISOLanguageName == "fr" ? LanguageEnum.fr : LanguageEnum.en), user); testDBService = new TestDBService((culture.TwoLetterISOLanguageName == "fr" ? LanguageEnum.fr : LanguageEnum.en), user, TableName, Plurial); randomService = new RandomService((culture.TwoLetterISOLanguageName == "fr" ? LanguageEnum.fr : LanguageEnum.en), user); mwqmSiteStartEndDateModelNew = new MWQMSiteStartEndDateModel(); mwqmSiteStartEndDate = new MWQMSiteStartEndDate(); }
public IHttpActionResult GetMWQMSiteStartEndDateWithID([FromUri] int MWQMSiteStartEndDateID, [FromUri] string lang = "en", [FromUri] string extra = "") { using (CSSPDBContext db = new CSSPDBContext(DatabaseType)) { MWQMSiteStartEndDateService mwqmSiteStartEndDateService = new MWQMSiteStartEndDateService(new Query() { Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en) }, db, ContactID); mwqmSiteStartEndDateService.Query = mwqmSiteStartEndDateService.FillQuery(typeof(MWQMSiteStartEndDate), lang, 0, 1, "", "", extra); if (mwqmSiteStartEndDateService.Query.Extra == "A") { MWQMSiteStartEndDateExtraA mwqmSiteStartEndDateExtraA = new MWQMSiteStartEndDateExtraA(); mwqmSiteStartEndDateExtraA = mwqmSiteStartEndDateService.GetMWQMSiteStartEndDateExtraAWithMWQMSiteStartEndDateID(MWQMSiteStartEndDateID); if (mwqmSiteStartEndDateExtraA == null) { return(NotFound()); } return(Ok(mwqmSiteStartEndDateExtraA)); } else if (mwqmSiteStartEndDateService.Query.Extra == "B") { MWQMSiteStartEndDateExtraB mwqmSiteStartEndDateExtraB = new MWQMSiteStartEndDateExtraB(); mwqmSiteStartEndDateExtraB = mwqmSiteStartEndDateService.GetMWQMSiteStartEndDateExtraBWithMWQMSiteStartEndDateID(MWQMSiteStartEndDateID); if (mwqmSiteStartEndDateExtraB == null) { return(NotFound()); } return(Ok(mwqmSiteStartEndDateExtraB)); } else { MWQMSiteStartEndDate mwqmSiteStartEndDate = new MWQMSiteStartEndDate(); mwqmSiteStartEndDate = mwqmSiteStartEndDateService.GetMWQMSiteStartEndDateWithMWQMSiteStartEndDateID(MWQMSiteStartEndDateID); if (mwqmSiteStartEndDate == null) { return(NotFound()); } return(Ok(mwqmSiteStartEndDate)); } } }
public MWQMSiteStartEndDateModel PostUpdateMWQMSiteStartEndDateDB(MWQMSiteStartEndDateModel mwqmSiteStartEndDateModel) { string retStr = MWQMSiteStartEndDateModelOK(mwqmSiteStartEndDateModel); if (!string.IsNullOrWhiteSpace(retStr)) { return(ReturnError(retStr)); } ContactOK contactOK = IsContactOK(); if (!string.IsNullOrEmpty(contactOK.Error)) { return(ReturnError(contactOK.Error)); } MWQMSiteStartEndDate mwqmSiteStartEndDateToUpdate = GetMWQMSiteStartEndDateWithMWQMSiteStartEndDateIDDB(mwqmSiteStartEndDateModel.MWQMSiteStartEndDateID); if (mwqmSiteStartEndDateToUpdate == null) { return(ReturnError(string.Format(ServiceRes.CouldNotFind_ToUpdate, ServiceRes.MWQMSiteStartEndDate))); } retStr = FillMWQMSiteStartEndDate(mwqmSiteStartEndDateToUpdate, mwqmSiteStartEndDateModel, contactOK); if (!string.IsNullOrWhiteSpace(retStr)) { return(ReturnError(retStr)); } using (TransactionScope ts = new TransactionScope()) { retStr = DoUpdateChanges(); if (!string.IsNullOrWhiteSpace(retStr)) { return(ReturnError(retStr)); } LogModel logModel = _LogService.PostAddLogForObj("MWQMSiteStartEndDates", mwqmSiteStartEndDateToUpdate.MWQMSiteStartEndDateID, LogCommandEnum.Change, mwqmSiteStartEndDateToUpdate); if (!string.IsNullOrWhiteSpace(logModel.Error)) { return(ReturnError(logModel.Error)); } ts.Complete(); } return(GetMWQMSiteStartEndDateModelWithMWQMSiteStartEndDateIDDB(mwqmSiteStartEndDateToUpdate.MWQMSiteStartEndDateID)); }
/// <summary> /// Updates an [MWQMSiteStartEndDate](CSSPModels.MWQMSiteStartEndDate.html) item in CSSPDB /// </summary> /// <param name="mwqmSiteStartEndDate">Is the MWQMSiteStartEndDate item the client want to add to CSSPDB. What's important here is the MWQMSiteStartEndDateID</param> /// <returns>true if MWQMSiteStartEndDate item was updated to CSSPDB, false if an error happened during the DB requested transtaction</returns> public bool Update(MWQMSiteStartEndDate mwqmSiteStartEndDate) { mwqmSiteStartEndDate.ValidationResults = Validate(new ValidationContext(mwqmSiteStartEndDate), ActionDBTypeEnum.Update); if (mwqmSiteStartEndDate.ValidationResults.Count() > 0) { return(false); } db.MWQMSiteStartEndDates.Update(mwqmSiteStartEndDate); if (!TryToSave(mwqmSiteStartEndDate)) { return(false); } return(true); }
/// <summary> /// Tries to execute the CSSPDB transaction (add/delete/update) on an [MWQMSiteStartEndDate](CSSPModels.MWQMSiteStartEndDate.html) item /// </summary> /// <param name="mwqmSiteStartEndDate">Is the MWQMSiteStartEndDate item the client want to add to CSSPDB. What's important here is the MWQMSiteStartEndDateID</param> /// <returns>true if MWQMSiteStartEndDate item was updated to CSSPDB, false if an error happened during the DB requested transtaction</returns> private bool TryToSave(MWQMSiteStartEndDate mwqmSiteStartEndDate) { try { db.SaveChanges(); } catch (DbUpdateException ex) { mwqmSiteStartEndDate.ValidationResults = new List <ValidationResult>() { new ValidationResult(ex.Message + (ex.InnerException != null ? " Inner: " + ex.InnerException.Message : "")) }.AsEnumerable(); return(false); } return(true); }
// Fill public string FillMWQMSiteStartEndDate(MWQMSiteStartEndDate mwqmSiteStartEndDate, MWQMSiteStartEndDateModel mwqmSiteStartEndDateModel, ContactOK contactOK) { mwqmSiteStartEndDate.DBCommand = (int)mwqmSiteStartEndDateModel.DBCommand; mwqmSiteStartEndDate.MWQMSiteTVItemID = mwqmSiteStartEndDateModel.MWQMSiteTVItemID; mwqmSiteStartEndDate.StartDate = mwqmSiteStartEndDateModel.StartDate; mwqmSiteStartEndDate.EndDate = mwqmSiteStartEndDateModel.EndDate; mwqmSiteStartEndDate.LastUpdateDate_UTC = DateTime.UtcNow; if (contactOK == null) { mwqmSiteStartEndDate.LastUpdateContactTVItemID = 2; } else { mwqmSiteStartEndDate.LastUpdateContactTVItemID = contactOK.ContactTVItemID; } return(""); }
public void MWQMSiteStartEndDate_Controller_GetMWQMSiteStartEndDateWithID_Test() { foreach (LanguageEnum LanguageRequest in AllowableLanguages) { foreach (int ContactID in new List <int>() { AdminContactID }) //, TestEmailValidatedContactID, TestEmailNotValidatedContactID }) { MWQMSiteStartEndDateController mwqmSiteStartEndDateController = new MWQMSiteStartEndDateController(DatabaseTypeEnum.SqlServerTestDB); Assert.IsNotNull(mwqmSiteStartEndDateController); Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, mwqmSiteStartEndDateController.DatabaseType); MWQMSiteStartEndDate mwqmSiteStartEndDateFirst = new MWQMSiteStartEndDate(); using (CSSPDBContext db = new CSSPDBContext(DatabaseType)) { MWQMSiteStartEndDateService mwqmSiteStartEndDateService = new MWQMSiteStartEndDateService(new Query(), db, ContactID); mwqmSiteStartEndDateFirst = (from c in db.MWQMSiteStartEndDates select c).FirstOrDefault(); } // ok with MWQMSiteStartEndDate info IHttpActionResult jsonRet = mwqmSiteStartEndDateController.GetMWQMSiteStartEndDateWithID(mwqmSiteStartEndDateFirst.MWQMSiteStartEndDateID); Assert.IsNotNull(jsonRet); OkNegotiatedContentResult <MWQMSiteStartEndDate> Ret = jsonRet as OkNegotiatedContentResult <MWQMSiteStartEndDate>; MWQMSiteStartEndDate mwqmSiteStartEndDateRet = Ret.Content; Assert.AreEqual(mwqmSiteStartEndDateFirst.MWQMSiteStartEndDateID, mwqmSiteStartEndDateRet.MWQMSiteStartEndDateID); BadRequestErrorMessageResult badRequest = jsonRet as BadRequestErrorMessageResult; Assert.IsNull(badRequest); // Not Found IHttpActionResult jsonRet2 = mwqmSiteStartEndDateController.GetMWQMSiteStartEndDateWithID(0); Assert.IsNotNull(jsonRet2); OkNegotiatedContentResult <MWQMSiteStartEndDate> mwqmSiteStartEndDateRet2 = jsonRet2 as OkNegotiatedContentResult <MWQMSiteStartEndDate>; Assert.IsNull(mwqmSiteStartEndDateRet2); NotFoundResult notFoundRequest = jsonRet2 as NotFoundResult; Assert.IsNotNull(notFoundRequest); } } }
public void MWQMSiteStartEndDateService_GetMWQMSiteStartEndDateWithMWQMSiteStartEndDateIDDB_Test() { foreach (CultureInfo culture in setupData.cultureListGood) { SetupTest(contactModelListGood[0], culture); using (TransactionScope ts = new TransactionScope()) { MWQMSiteStartEndDateModel mwqmSiteStartEndDateModelRet = AddMWQMSiteStartEndDateModel(); Assert.AreEqual("", mwqmSiteStartEndDateModelRet.Error); MWQMSiteStartEndDate mwqmSiteStartEndDateRet = mwqmSiteStartEndDateService.GetMWQMSiteStartEndDateWithMWQMSiteStartEndDateIDDB(mwqmSiteStartEndDateModelRet.MWQMSiteStartEndDateID); Assert.AreEqual(mwqmSiteStartEndDateModelRet.MWQMSiteStartEndDateID, mwqmSiteStartEndDateRet.MWQMSiteStartEndDateID); int MWQMSiteStartEndDateID = 0; MWQMSiteStartEndDate mwqmSiteStartEndDateRet2 = mwqmSiteStartEndDateService.GetMWQMSiteStartEndDateWithMWQMSiteStartEndDateIDDB(MWQMSiteStartEndDateID); Assert.IsNull(mwqmSiteStartEndDateRet2); } } }
public IHttpActionResult Delete([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.Delete(mwqmSiteStartEndDate)) { return(BadRequest(String.Join("|||", mwqmSiteStartEndDate.ValidationResults))); } else { mwqmSiteStartEndDate.ValidationResults = null; return(Ok(mwqmSiteStartEndDate)); } } }
public void GetMWQMSiteStartEndDateList_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); MWQMSiteStartEndDate mwqmSiteStartEndDate = (from c in dbTestDB.MWQMSiteStartEndDates select c).FirstOrDefault(); Assert.IsNotNull(mwqmSiteStartEndDate); List <MWQMSiteStartEndDate> mwqmSiteStartEndDateDirectQueryList = new List <MWQMSiteStartEndDate>(); mwqmSiteStartEndDateDirectQueryList = (from c in dbTestDB.MWQMSiteStartEndDates select c).Take(200).ToList(); foreach (string extra in new List <string>() { null, "A", "B", "C", "D", "E" }) { mwqmSiteStartEndDateService.Query.Extra = extra; if (string.IsNullOrWhiteSpace(extra)) { List <MWQMSiteStartEndDate> mwqmSiteStartEndDateList = new List <MWQMSiteStartEndDate>(); mwqmSiteStartEndDateList = mwqmSiteStartEndDateService.GetMWQMSiteStartEndDateList().ToList(); CheckMWQMSiteStartEndDateFields(mwqmSiteStartEndDateList); } else { //Assert.AreEqual(true, false); } } } } }
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 } } }
/// <summary> /// Validate function for all MWQMSiteStartEndDateService commands /// </summary> /// <param name="validationContext">System.ComponentModel.DataAnnotations.ValidationContext (Describes the context in which a validation check is performed.)</param> /// <param name="actionDBType">[ActionDBTypeEnum] (CSSPEnums.ActionDBTypeEnum.html) action type to validate</param> /// <returns>IEnumerable of ValidationResult (Where ValidationResult is a container for the results of a validation request.)</returns> private IEnumerable <ValidationResult> Validate(ValidationContext validationContext, ActionDBTypeEnum actionDBType) { string retStr = ""; Enums enums = new Enums(LanguageRequest); MWQMSiteStartEndDate mwqmSiteStartEndDate = validationContext.ObjectInstance as MWQMSiteStartEndDate; mwqmSiteStartEndDate.HasErrors = false; if (actionDBType == ActionDBTypeEnum.Update || actionDBType == ActionDBTypeEnum.Delete) { if (mwqmSiteStartEndDate.MWQMSiteStartEndDateID == 0) { mwqmSiteStartEndDate.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "MWQMSiteStartEndDateID"), new[] { "MWQMSiteStartEndDateID" })); } if (!(from c in db.MWQMSiteStartEndDates select c).Where(c => c.MWQMSiteStartEndDateID == mwqmSiteStartEndDate.MWQMSiteStartEndDateID).Any()) { mwqmSiteStartEndDate.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "MWQMSiteStartEndDate", "MWQMSiteStartEndDateID", mwqmSiteStartEndDate.MWQMSiteStartEndDateID.ToString()), new[] { "MWQMSiteStartEndDateID" })); } } TVItem TVItemMWQMSiteTVItemID = (from c in db.TVItems where c.TVItemID == mwqmSiteStartEndDate.MWQMSiteTVItemID select c).FirstOrDefault(); if (TVItemMWQMSiteTVItemID == null) { mwqmSiteStartEndDate.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "MWQMSiteTVItemID", mwqmSiteStartEndDate.MWQMSiteTVItemID.ToString()), new[] { "MWQMSiteTVItemID" })); } else { List <TVTypeEnum> AllowableTVTypes = new List <TVTypeEnum>() { TVTypeEnum.MWQMSite, }; if (!AllowableTVTypes.Contains(TVItemMWQMSiteTVItemID.TVType)) { mwqmSiteStartEndDate.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsNotOfType_, "MWQMSiteTVItemID", "MWQMSite"), new[] { "MWQMSiteTVItemID" })); } } if (mwqmSiteStartEndDate.StartDate.Year == 1) { mwqmSiteStartEndDate.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "StartDate"), new[] { "StartDate" })); } else { if (mwqmSiteStartEndDate.StartDate.Year < 1980) { mwqmSiteStartEndDate.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "StartDate", "1980"), new[] { "StartDate" })); } } if (mwqmSiteStartEndDate.EndDate != null && ((DateTime)mwqmSiteStartEndDate.EndDate).Year < 1980) { mwqmSiteStartEndDate.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "EndDate", "1980"), new[] { "EndDate" })); } if (mwqmSiteStartEndDate.StartDate > mwqmSiteStartEndDate.EndDate) { mwqmSiteStartEndDate.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._DateIsBiggerThan_, "EndDate", "MWQMSiteStartEndDateStartDate"), new[] { "EndDate" })); } if (mwqmSiteStartEndDate.LastUpdateDate_UTC.Year == 1) { mwqmSiteStartEndDate.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "LastUpdateDate_UTC"), new[] { "LastUpdateDate_UTC" })); } else { if (mwqmSiteStartEndDate.LastUpdateDate_UTC.Year < 1980) { mwqmSiteStartEndDate.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "LastUpdateDate_UTC", "1980"), new[] { "LastUpdateDate_UTC" })); } } TVItem TVItemLastUpdateContactTVItemID = (from c in db.TVItems where c.TVItemID == mwqmSiteStartEndDate.LastUpdateContactTVItemID select c).FirstOrDefault(); if (TVItemLastUpdateContactTVItemID == null) { mwqmSiteStartEndDate.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "LastUpdateContactTVItemID", mwqmSiteStartEndDate.LastUpdateContactTVItemID.ToString()), new[] { "LastUpdateContactTVItemID" })); } else { List <TVTypeEnum> AllowableTVTypes = new List <TVTypeEnum>() { TVTypeEnum.Contact, }; if (!AllowableTVTypes.Contains(TVItemLastUpdateContactTVItemID.TVType)) { mwqmSiteStartEndDate.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsNotOfType_, "LastUpdateContactTVItemID", "Contact"), new[] { "LastUpdateContactTVItemID" })); } } retStr = ""; // added to stop compiling CSSPError if (retStr != "") // will never be true { mwqmSiteStartEndDate.HasErrors = true; yield return(new ValidationResult("AAA", new[] { "AAA" })); } }
public MWQMSiteStartEndDateTest() { mWQMSiteStartEndDate = new MWQMSiteStartEndDate(); mWQMSiteStartEndDateExtraA = new MWQMSiteStartEndDateExtraA(); mWQMSiteStartEndDateExtraB = new MWQMSiteStartEndDateExtraB(); }
public void MWQMSiteStartEndDate_Controller_GetMWQMSiteStartEndDateList_Test() { foreach (LanguageEnum LanguageRequest in AllowableLanguages) { foreach (int ContactID in new List <int>() { AdminContactID }) //, TestEmailValidatedContactID, TestEmailNotValidatedContactID }) { MWQMSiteStartEndDateController mwqmSiteStartEndDateController = new MWQMSiteStartEndDateController(DatabaseTypeEnum.SqlServerTestDB); Assert.IsNotNull(mwqmSiteStartEndDateController); Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, mwqmSiteStartEndDateController.DatabaseType); MWQMSiteStartEndDate mwqmSiteStartEndDateFirst = new MWQMSiteStartEndDate(); int count = -1; Query query = new Query(); using (CSSPDBContext db = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { MWQMSiteStartEndDateService mwqmSiteStartEndDateService = new MWQMSiteStartEndDateService(query, db, ContactID); mwqmSiteStartEndDateFirst = (from c in db.MWQMSiteStartEndDates select c).FirstOrDefault(); count = (from c in db.MWQMSiteStartEndDates select c).Count(); count = (query.Take > count ? count : query.Take); } // ok with MWQMSiteStartEndDate info IHttpActionResult jsonRet = mwqmSiteStartEndDateController.GetMWQMSiteStartEndDateList(); Assert.IsNotNull(jsonRet); OkNegotiatedContentResult <List <MWQMSiteStartEndDate> > ret = jsonRet as OkNegotiatedContentResult <List <MWQMSiteStartEndDate> >; Assert.AreEqual(mwqmSiteStartEndDateFirst.MWQMSiteStartEndDateID, ret.Content[0].MWQMSiteStartEndDateID); Assert.AreEqual((count > query.Take ? query.Take : count), ret.Content.Count); List <MWQMSiteStartEndDate> mwqmSiteStartEndDateList = new List <MWQMSiteStartEndDate>(); count = -1; query = new Query(); using (CSSPDBContext db = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { MWQMSiteStartEndDateService mwqmSiteStartEndDateService = new MWQMSiteStartEndDateService(query, db, ContactID); mwqmSiteStartEndDateList = (from c in db.MWQMSiteStartEndDates select c).OrderBy(c => c.MWQMSiteStartEndDateID).Skip(0).Take(2).ToList(); count = (from c in db.MWQMSiteStartEndDates select c).Count(); } if (count > 0) { query.Skip = 0; query.Take = 5; count = (query.Take > count ? query.Take : count); // ok with MWQMSiteStartEndDate info jsonRet = mwqmSiteStartEndDateController.GetMWQMSiteStartEndDateList(query.Language.ToString(), query.Skip, query.Take); Assert.IsNotNull(jsonRet); ret = jsonRet as OkNegotiatedContentResult <List <MWQMSiteStartEndDate> >; Assert.AreEqual(mwqmSiteStartEndDateList[0].MWQMSiteStartEndDateID, ret.Content[0].MWQMSiteStartEndDateID); Assert.AreEqual((count > query.Take ? query.Take : count), ret.Content.Count); if (count > 1) { query.Skip = 1; query.Take = 5; count = (query.Take > count ? query.Take : count); // ok with MWQMSiteStartEndDate info IHttpActionResult jsonRet2 = mwqmSiteStartEndDateController.GetMWQMSiteStartEndDateList(query.Language.ToString(), query.Skip, query.Take); Assert.IsNotNull(jsonRet2); OkNegotiatedContentResult <List <MWQMSiteStartEndDate> > ret2 = jsonRet2 as OkNegotiatedContentResult <List <MWQMSiteStartEndDate> >; Assert.AreEqual(mwqmSiteStartEndDateList[1].MWQMSiteStartEndDateID, ret2.Content[0].MWQMSiteStartEndDateID); Assert.AreEqual((count > query.Take ? query.Take : count), ret2.Content.Count); } } } } }
public void MWQMSiteStartEndDate_Controller_Post_Test() { foreach (LanguageEnum LanguageRequest in AllowableLanguages) { foreach (int ContactID in new List <int>() { AdminContactID }) //, TestEmailValidatedContactID, TestEmailNotValidatedContactID }) { MWQMSiteStartEndDateController mwqmSiteStartEndDateController = new MWQMSiteStartEndDateController(DatabaseTypeEnum.SqlServerTestDB); Assert.IsNotNull(mwqmSiteStartEndDateController); Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, mwqmSiteStartEndDateController.DatabaseType); MWQMSiteStartEndDate mwqmSiteStartEndDateLast = new MWQMSiteStartEndDate(); using (CSSPDBContext db = new CSSPDBContext(DatabaseType)) { Query query = new Query(); query.Language = LanguageRequest; query.Asc = ""; query.Desc = ""; MWQMSiteStartEndDateService mwqmSiteStartEndDateService = new MWQMSiteStartEndDateService(query, db, ContactID); mwqmSiteStartEndDateLast = (from c in db.MWQMSiteStartEndDates select c).FirstOrDefault(); } // ok with MWQMSiteStartEndDate info IHttpActionResult jsonRet = mwqmSiteStartEndDateController.GetMWQMSiteStartEndDateWithID(mwqmSiteStartEndDateLast.MWQMSiteStartEndDateID); Assert.IsNotNull(jsonRet); OkNegotiatedContentResult <MWQMSiteStartEndDate> Ret = jsonRet as OkNegotiatedContentResult <MWQMSiteStartEndDate>; MWQMSiteStartEndDate mwqmSiteStartEndDateRet = Ret.Content; Assert.AreEqual(mwqmSiteStartEndDateLast.MWQMSiteStartEndDateID, mwqmSiteStartEndDateRet.MWQMSiteStartEndDateID); BadRequestErrorMessageResult badRequest = jsonRet as BadRequestErrorMessageResult; Assert.IsNull(badRequest); // Post to return CSSPError because MWQMSiteStartEndDateID exist IHttpActionResult jsonRet2 = mwqmSiteStartEndDateController.Post(mwqmSiteStartEndDateRet, LanguageRequest.ToString()); Assert.IsNotNull(jsonRet2); OkNegotiatedContentResult <MWQMSiteStartEndDate> mwqmSiteStartEndDateRet2 = jsonRet2 as OkNegotiatedContentResult <MWQMSiteStartEndDate>; Assert.IsNull(mwqmSiteStartEndDateRet2); BadRequestErrorMessageResult badRequest2 = jsonRet2 as BadRequestErrorMessageResult; Assert.IsNotNull(badRequest2); // Post to return newly added MWQMSiteStartEndDate mwqmSiteStartEndDateRet.MWQMSiteStartEndDateID = 0; mwqmSiteStartEndDateController.Request = new System.Net.Http.HttpRequestMessage(); mwqmSiteStartEndDateController.Request.RequestUri = new System.Uri("http://localhost:5000/api/mwqmSiteStartEndDate"); IHttpActionResult jsonRet3 = mwqmSiteStartEndDateController.Post(mwqmSiteStartEndDateRet, LanguageRequest.ToString()); Assert.IsNotNull(jsonRet3); CreatedNegotiatedContentResult <MWQMSiteStartEndDate> mwqmSiteStartEndDateRet3 = jsonRet3 as CreatedNegotiatedContentResult <MWQMSiteStartEndDate>; Assert.IsNotNull(mwqmSiteStartEndDateRet3); BadRequestErrorMessageResult badRequest3 = jsonRet3 as BadRequestErrorMessageResult; Assert.IsNull(badRequest3); IHttpActionResult jsonRet4 = mwqmSiteStartEndDateController.Delete(mwqmSiteStartEndDateRet, LanguageRequest.ToString()); Assert.IsNotNull(jsonRet4); OkNegotiatedContentResult <MWQMSiteStartEndDate> mwqmSiteStartEndDateRet4 = jsonRet4 as OkNegotiatedContentResult <MWQMSiteStartEndDate>; Assert.IsNotNull(mwqmSiteStartEndDateRet4); BadRequestErrorMessageResult badRequest4 = jsonRet4 as BadRequestErrorMessageResult; Assert.IsNull(badRequest4); } } }