public void MWQMLookupMPN_Controller_Put_Test() { foreach (LanguageEnum LanguageRequest in AllowableLanguages) { foreach (int ContactID in new List <int>() { AdminContactID }) //, TestEmailValidatedContactID, TestEmailNotValidatedContactID }) { MWQMLookupMPNController mwqmLookupMPNController = new MWQMLookupMPNController(DatabaseTypeEnum.SqlServerTestDB); Assert.IsNotNull(mwqmLookupMPNController); Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, mwqmLookupMPNController.DatabaseType); MWQMLookupMPN mwqmLookupMPNLast = new MWQMLookupMPN(); using (CSSPDBContext db = new CSSPDBContext(DatabaseType)) { Query query = new Query(); query.Language = LanguageRequest; MWQMLookupMPNService mwqmLookupMPNService = new MWQMLookupMPNService(query, db, ContactID); mwqmLookupMPNLast = (from c in db.MWQMLookupMPNs select c).FirstOrDefault(); } // ok with MWQMLookupMPN info IHttpActionResult jsonRet = mwqmLookupMPNController.GetMWQMLookupMPNWithID(mwqmLookupMPNLast.MWQMLookupMPNID); Assert.IsNotNull(jsonRet); OkNegotiatedContentResult <MWQMLookupMPN> Ret = jsonRet as OkNegotiatedContentResult <MWQMLookupMPN>; MWQMLookupMPN mwqmLookupMPNRet = Ret.Content; Assert.AreEqual(mwqmLookupMPNLast.MWQMLookupMPNID, mwqmLookupMPNRet.MWQMLookupMPNID); BadRequestErrorMessageResult badRequest = jsonRet as BadRequestErrorMessageResult; Assert.IsNull(badRequest); // Put to return success IHttpActionResult jsonRet2 = mwqmLookupMPNController.Put(mwqmLookupMPNRet, LanguageRequest.ToString()); Assert.IsNotNull(jsonRet2); OkNegotiatedContentResult <MWQMLookupMPN> mwqmLookupMPNRet2 = jsonRet2 as OkNegotiatedContentResult <MWQMLookupMPN>; Assert.IsNotNull(mwqmLookupMPNRet2); BadRequestErrorMessageResult badRequest2 = jsonRet2 as BadRequestErrorMessageResult; Assert.IsNull(badRequest2); // Put to return CSSPError because MWQMLookupMPNID of 0 does not exist mwqmLookupMPNRet.MWQMLookupMPNID = 0; IHttpActionResult jsonRet3 = mwqmLookupMPNController.Put(mwqmLookupMPNRet, LanguageRequest.ToString()); Assert.IsNotNull(jsonRet3); OkNegotiatedContentResult <MWQMLookupMPN> mwqmLookupMPNRet3 = jsonRet3 as OkNegotiatedContentResult <MWQMLookupMPN>; Assert.IsNull(mwqmLookupMPNRet3); BadRequestErrorMessageResult badRequest3 = jsonRet3 as BadRequestErrorMessageResult; Assert.IsNotNull(badRequest3); } } }
public IHttpActionResult GetMWQMLookupMPNList([FromUri] string lang = "en", [FromUri] int skip = 0, [FromUri] int take = 200, [FromUri] string asc = "", [FromUri] string desc = "", [FromUri] string where = "", [FromUri] string extra = "") { using (CSSPDBContext db = new CSSPDBContext(DatabaseType)) { MWQMLookupMPNService mwqmLookupMPNService = new MWQMLookupMPNService(new Query() { Lang = lang }, db, ContactID);
public void MWQMLookupMPN_CRUD_Test() { foreach (CultureInfo culture in AllowableCulture) { ChangeCulture(culture); using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { MWQMLookupMPNService mwqmLookupMPNService = new MWQMLookupMPNService(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] } MWQMLookupMPN mwqmLookupMPN = GetFilledRandomMWQMLookupMPN(""); // ------------------------------- // ------------------------------- // CRUD testing // ------------------------------- // ------------------------------- count = mwqmLookupMPNService.GetMWQMLookupMPNList().Count(); Assert.AreEqual(count, (from c in dbTestDB.MWQMLookupMPNs select c).Count()); mwqmLookupMPNService.Add(mwqmLookupMPN); if (mwqmLookupMPN.HasErrors) { Assert.AreEqual("", mwqmLookupMPN.ValidationResults.FirstOrDefault().ErrorMessage); } Assert.AreEqual(true, mwqmLookupMPNService.GetMWQMLookupMPNList().Where(c => c == mwqmLookupMPN).Any()); mwqmLookupMPNService.Update(mwqmLookupMPN); if (mwqmLookupMPN.HasErrors) { Assert.AreEqual("", mwqmLookupMPN.ValidationResults.FirstOrDefault().ErrorMessage); } Assert.AreEqual(count + 1, mwqmLookupMPNService.GetMWQMLookupMPNList().Count()); mwqmLookupMPNService.Delete(mwqmLookupMPN); if (mwqmLookupMPN.HasErrors) { Assert.AreEqual("", mwqmLookupMPN.ValidationResults.FirstOrDefault().ErrorMessage); } Assert.AreEqual(count, mwqmLookupMPNService.GetMWQMLookupMPNList().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); mwqmLookupMPNService = new MWQMLookupMPNService((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); mwqmLookupMPNModelNew = new MWQMLookupMPNModel(); mwqmLookupMPN = new MWQMLookupMPN(); }
public IHttpActionResult GetMWQMLookupMPNWithID([FromUri] int MWQMLookupMPNID, [FromUri] string lang = "en", [FromUri] string extra = "") { using (CSSPDBContext db = new CSSPDBContext(DatabaseType)) { MWQMLookupMPNService mwqmLookupMPNService = new MWQMLookupMPNService(new Query() { Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en) }, db, ContactID); mwqmLookupMPNService.Query = mwqmLookupMPNService.FillQuery(typeof(MWQMLookupMPN), lang, 0, 1, "", "", extra); if (mwqmLookupMPNService.Query.Extra == "A") { MWQMLookupMPNExtraA mwqmLookupMPNExtraA = new MWQMLookupMPNExtraA(); mwqmLookupMPNExtraA = mwqmLookupMPNService.GetMWQMLookupMPNExtraAWithMWQMLookupMPNID(MWQMLookupMPNID); if (mwqmLookupMPNExtraA == null) { return(NotFound()); } return(Ok(mwqmLookupMPNExtraA)); } else if (mwqmLookupMPNService.Query.Extra == "B") { MWQMLookupMPNExtraB mwqmLookupMPNExtraB = new MWQMLookupMPNExtraB(); mwqmLookupMPNExtraB = mwqmLookupMPNService.GetMWQMLookupMPNExtraBWithMWQMLookupMPNID(MWQMLookupMPNID); if (mwqmLookupMPNExtraB == null) { return(NotFound()); } return(Ok(mwqmLookupMPNExtraB)); } else { MWQMLookupMPN mwqmLookupMPN = new MWQMLookupMPN(); mwqmLookupMPN = mwqmLookupMPNService.GetMWQMLookupMPNWithMWQMLookupMPNID(MWQMLookupMPNID); if (mwqmLookupMPN == null) { return(NotFound()); } return(Ok(mwqmLookupMPN)); } } }
public void MWQMLookupMPN_Controller_GetMWQMLookupMPNWithID_Test() { foreach (LanguageEnum LanguageRequest in AllowableLanguages) { foreach (int ContactID in new List <int>() { AdminContactID }) //, TestEmailValidatedContactID, TestEmailNotValidatedContactID }) { MWQMLookupMPNController mwqmLookupMPNController = new MWQMLookupMPNController(DatabaseTypeEnum.SqlServerTestDB); Assert.IsNotNull(mwqmLookupMPNController); Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, mwqmLookupMPNController.DatabaseType); MWQMLookupMPN mwqmLookupMPNFirst = new MWQMLookupMPN(); using (CSSPDBContext db = new CSSPDBContext(DatabaseType)) { MWQMLookupMPNService mwqmLookupMPNService = new MWQMLookupMPNService(new Query(), db, ContactID); mwqmLookupMPNFirst = (from c in db.MWQMLookupMPNs select c).FirstOrDefault(); } // ok with MWQMLookupMPN info IHttpActionResult jsonRet = mwqmLookupMPNController.GetMWQMLookupMPNWithID(mwqmLookupMPNFirst.MWQMLookupMPNID); Assert.IsNotNull(jsonRet); OkNegotiatedContentResult <MWQMLookupMPN> Ret = jsonRet as OkNegotiatedContentResult <MWQMLookupMPN>; MWQMLookupMPN mwqmLookupMPNRet = Ret.Content; Assert.AreEqual(mwqmLookupMPNFirst.MWQMLookupMPNID, mwqmLookupMPNRet.MWQMLookupMPNID); BadRequestErrorMessageResult badRequest = jsonRet as BadRequestErrorMessageResult; Assert.IsNull(badRequest); // Not Found IHttpActionResult jsonRet2 = mwqmLookupMPNController.GetMWQMLookupMPNWithID(0); Assert.IsNotNull(jsonRet2); OkNegotiatedContentResult <MWQMLookupMPN> mwqmLookupMPNRet2 = jsonRet2 as OkNegotiatedContentResult <MWQMLookupMPN>; Assert.IsNull(mwqmLookupMPNRet2); NotFoundResult notFoundRequest = jsonRet2 as NotFoundResult; Assert.IsNotNull(notFoundRequest); } } }
public IHttpActionResult Delete([FromBody] MWQMLookupMPN mwqmLookupMPN, [FromUri] string lang = "en") { using (CSSPDBContext db = new CSSPDBContext(DatabaseType)) { MWQMLookupMPNService mwqmLookupMPNService = new MWQMLookupMPNService(new Query() { Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en) }, db, ContactID); if (!mwqmLookupMPNService.Delete(mwqmLookupMPN)) { return(BadRequest(String.Join("|||", mwqmLookupMPN.ValidationResults))); } else { mwqmLookupMPN.ValidationResults = null; return(Ok(mwqmLookupMPN)); } } }
public void GetMWQMLookupMPNList_Test() { foreach (CultureInfo culture in AllowableCulture) { ChangeCulture(culture); using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { MWQMLookupMPNService mwqmLookupMPNService = new MWQMLookupMPNService(new Query() { Lang = culture.TwoLetterISOLanguageName }, dbTestDB, ContactID); MWQMLookupMPN mwqmLookupMPN = (from c in dbTestDB.MWQMLookupMPNs select c).FirstOrDefault(); Assert.IsNotNull(mwqmLookupMPN); List <MWQMLookupMPN> mwqmLookupMPNDirectQueryList = new List <MWQMLookupMPN>(); mwqmLookupMPNDirectQueryList = (from c in dbTestDB.MWQMLookupMPNs select c).Take(200).ToList(); foreach (string extra in new List <string>() { null, "A", "B", "C", "D", "E" }) { mwqmLookupMPNService.Query.Extra = extra; if (string.IsNullOrWhiteSpace(extra)) { List <MWQMLookupMPN> mwqmLookupMPNList = new List <MWQMLookupMPN>(); mwqmLookupMPNList = mwqmLookupMPNService.GetMWQMLookupMPNList().ToList(); CheckMWQMLookupMPNFields(mwqmLookupMPNList); } else { //Assert.AreEqual(true, false); } } } } }
public void GetMWQMLookupMPNList_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" }) { MWQMLookupMPNService mwqmLookupMPNService = new MWQMLookupMPNService(new Query() { Lang = culture.TwoLetterISOLanguageName }, dbTestDB, ContactID); mwqmLookupMPNService.Query = mwqmLookupMPNService.FillQuery(typeof(MWQMLookupMPN), culture.TwoLetterISOLanguageName, 0, 10000, "", "", "MWQMLookupMPNID,GT,2|MWQMLookupMPNID,LT,5", extra); List <MWQMLookupMPN> mwqmLookupMPNDirectQueryList = new List <MWQMLookupMPN>(); mwqmLookupMPNDirectQueryList = (from c in dbTestDB.MWQMLookupMPNs select c).Where(c => c.MWQMLookupMPNID > 2 && c.MWQMLookupMPNID < 5).ToList(); if (string.IsNullOrWhiteSpace(extra)) { List <MWQMLookupMPN> mwqmLookupMPNList = new List <MWQMLookupMPN>(); mwqmLookupMPNList = mwqmLookupMPNService.GetMWQMLookupMPNList().ToList(); CheckMWQMLookupMPNFields(mwqmLookupMPNList); Assert.AreEqual(mwqmLookupMPNDirectQueryList[0].MWQMLookupMPNID, mwqmLookupMPNList[0].MWQMLookupMPNID); } else { //Assert.AreEqual(true, false); } } } } }
public void MWQMLookupMPN_Properties_Test() { foreach (CultureInfo culture in AllowableCulture) { ChangeCulture(culture); using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { MWQMLookupMPNService mwqmLookupMPNService = new MWQMLookupMPNService(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 = mwqmLookupMPNService.GetMWQMLookupMPNList().Count(); MWQMLookupMPN mwqmLookupMPN = GetFilledRandomMWQMLookupMPN(""); // ------------------------------- // ------------------------------- // Properties testing // ------------------------------- // ------------------------------- // ----------------------------------- // [Key] // Is NOT Nullable // mwqmLookupMPN.MWQMLookupMPNID (Int32) // ----------------------------------- mwqmLookupMPN = null; mwqmLookupMPN = GetFilledRandomMWQMLookupMPN(""); mwqmLookupMPN.MWQMLookupMPNID = 0; mwqmLookupMPNService.Update(mwqmLookupMPN); Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "MWQMLookupMPNID"), mwqmLookupMPN.ValidationResults.FirstOrDefault().ErrorMessage); mwqmLookupMPN = null; mwqmLookupMPN = GetFilledRandomMWQMLookupMPN(""); mwqmLookupMPN.MWQMLookupMPNID = 10000000; mwqmLookupMPNService.Update(mwqmLookupMPN); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "MWQMLookupMPN", "MWQMLookupMPNID", mwqmLookupMPN.MWQMLookupMPNID.ToString()), mwqmLookupMPN.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [Range(0, 5)] // mwqmLookupMPN.Tubes10 (Int32) // ----------------------------------- mwqmLookupMPN = null; mwqmLookupMPN = GetFilledRandomMWQMLookupMPN(""); mwqmLookupMPN.Tubes10 = -1; Assert.AreEqual(false, mwqmLookupMPNService.Add(mwqmLookupMPN)); Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "Tubes10", "0", "5"), mwqmLookupMPN.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, mwqmLookupMPNService.GetMWQMLookupMPNList().Count()); mwqmLookupMPN = null; mwqmLookupMPN = GetFilledRandomMWQMLookupMPN(""); mwqmLookupMPN.Tubes10 = 6; Assert.AreEqual(false, mwqmLookupMPNService.Add(mwqmLookupMPN)); Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "Tubes10", "0", "5"), mwqmLookupMPN.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, mwqmLookupMPNService.GetMWQMLookupMPNList().Count()); // ----------------------------------- // Is NOT Nullable // [Range(0, 5)] // mwqmLookupMPN.Tubes1 (Int32) // ----------------------------------- mwqmLookupMPN = null; mwqmLookupMPN = GetFilledRandomMWQMLookupMPN(""); mwqmLookupMPN.Tubes1 = -1; Assert.AreEqual(false, mwqmLookupMPNService.Add(mwqmLookupMPN)); Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "Tubes1", "0", "5"), mwqmLookupMPN.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, mwqmLookupMPNService.GetMWQMLookupMPNList().Count()); mwqmLookupMPN = null; mwqmLookupMPN = GetFilledRandomMWQMLookupMPN(""); mwqmLookupMPN.Tubes1 = 6; Assert.AreEqual(false, mwqmLookupMPNService.Add(mwqmLookupMPN)); Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "Tubes1", "0", "5"), mwqmLookupMPN.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, mwqmLookupMPNService.GetMWQMLookupMPNList().Count()); // ----------------------------------- // Is NOT Nullable // [Range(0, 5)] // mwqmLookupMPN.Tubes01 (Int32) // ----------------------------------- mwqmLookupMPN = null; mwqmLookupMPN = GetFilledRandomMWQMLookupMPN(""); mwqmLookupMPN.Tubes01 = -1; Assert.AreEqual(false, mwqmLookupMPNService.Add(mwqmLookupMPN)); Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "Tubes01", "0", "5"), mwqmLookupMPN.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, mwqmLookupMPNService.GetMWQMLookupMPNList().Count()); mwqmLookupMPN = null; mwqmLookupMPN = GetFilledRandomMWQMLookupMPN(""); mwqmLookupMPN.Tubes01 = 6; Assert.AreEqual(false, mwqmLookupMPNService.Add(mwqmLookupMPN)); Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "Tubes01", "0", "5"), mwqmLookupMPN.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, mwqmLookupMPNService.GetMWQMLookupMPNList().Count()); // ----------------------------------- // Is NOT Nullable // [Range(1, 10000)] // mwqmLookupMPN.MPN_100ml (Int32) // ----------------------------------- mwqmLookupMPN = null; mwqmLookupMPN = GetFilledRandomMWQMLookupMPN(""); mwqmLookupMPN.MPN_100ml = 0; Assert.AreEqual(false, mwqmLookupMPNService.Add(mwqmLookupMPN)); Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "MPN_100ml", "1", "10000"), mwqmLookupMPN.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, mwqmLookupMPNService.GetMWQMLookupMPNList().Count()); mwqmLookupMPN = null; mwqmLookupMPN = GetFilledRandomMWQMLookupMPN(""); mwqmLookupMPN.MPN_100ml = 10001; Assert.AreEqual(false, mwqmLookupMPNService.Add(mwqmLookupMPN)); Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "MPN_100ml", "1", "10000"), mwqmLookupMPN.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, mwqmLookupMPNService.GetMWQMLookupMPNList().Count()); // ----------------------------------- // Is NOT Nullable // [CSSPAfter(Year = 1980)] // mwqmLookupMPN.LastUpdateDate_UTC (DateTime) // ----------------------------------- mwqmLookupMPN = null; mwqmLookupMPN = GetFilledRandomMWQMLookupMPN(""); mwqmLookupMPN.LastUpdateDate_UTC = new DateTime(); mwqmLookupMPNService.Add(mwqmLookupMPN); Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "LastUpdateDate_UTC"), mwqmLookupMPN.ValidationResults.FirstOrDefault().ErrorMessage); mwqmLookupMPN = null; mwqmLookupMPN = GetFilledRandomMWQMLookupMPN(""); mwqmLookupMPN.LastUpdateDate_UTC = new DateTime(1979, 1, 1); mwqmLookupMPNService.Add(mwqmLookupMPN); Assert.AreEqual(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "LastUpdateDate_UTC", "1980"), mwqmLookupMPN.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [CSSPExist(ExistTypeName = "TVItem", ExistPlurial = "s", ExistFieldID = "TVItemID", AllowableTVtypeList = Contact)] // mwqmLookupMPN.LastUpdateContactTVItemID (Int32) // ----------------------------------- mwqmLookupMPN = null; mwqmLookupMPN = GetFilledRandomMWQMLookupMPN(""); mwqmLookupMPN.LastUpdateContactTVItemID = 0; mwqmLookupMPNService.Add(mwqmLookupMPN); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "LastUpdateContactTVItemID", mwqmLookupMPN.LastUpdateContactTVItemID.ToString()), mwqmLookupMPN.ValidationResults.FirstOrDefault().ErrorMessage); mwqmLookupMPN = null; mwqmLookupMPN = GetFilledRandomMWQMLookupMPN(""); mwqmLookupMPN.LastUpdateContactTVItemID = 1; mwqmLookupMPNService.Add(mwqmLookupMPN); Assert.AreEqual(string.Format(CSSPServicesRes._IsNotOfType_, "LastUpdateContactTVItemID", "Contact"), mwqmLookupMPN.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [NotMapped] // mwqmLookupMPN.HasErrors (Boolean) // ----------------------------------- // No testing requied // ----------------------------------- // Is NOT Nullable // [NotMapped] // mwqmLookupMPN.ValidationResults (IEnumerable`1) // ----------------------------------- // No testing requied } } }
public void MWQMLookupMPN_Controller_GetMWQMLookupMPNList_Test() { foreach (LanguageEnum LanguageRequest in AllowableLanguages) { foreach (int ContactID in new List <int>() { AdminContactID }) //, TestEmailValidatedContactID, TestEmailNotValidatedContactID }) { MWQMLookupMPNController mwqmLookupMPNController = new MWQMLookupMPNController(DatabaseTypeEnum.SqlServerTestDB); Assert.IsNotNull(mwqmLookupMPNController); Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, mwqmLookupMPNController.DatabaseType); MWQMLookupMPN mwqmLookupMPNFirst = new MWQMLookupMPN(); int count = -1; Query query = new Query(); using (CSSPDBContext db = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { MWQMLookupMPNService mwqmLookupMPNService = new MWQMLookupMPNService(query, db, ContactID); mwqmLookupMPNFirst = (from c in db.MWQMLookupMPNs select c).FirstOrDefault(); count = (from c in db.MWQMLookupMPNs select c).Count(); count = (query.Take > count ? count : query.Take); } // ok with MWQMLookupMPN info IHttpActionResult jsonRet = mwqmLookupMPNController.GetMWQMLookupMPNList(); Assert.IsNotNull(jsonRet); OkNegotiatedContentResult <List <MWQMLookupMPN> > ret = jsonRet as OkNegotiatedContentResult <List <MWQMLookupMPN> >; Assert.AreEqual(mwqmLookupMPNFirst.MWQMLookupMPNID, ret.Content[0].MWQMLookupMPNID); Assert.AreEqual((count > query.Take ? query.Take : count), ret.Content.Count); List <MWQMLookupMPN> mwqmLookupMPNList = new List <MWQMLookupMPN>(); count = -1; query = new Query(); using (CSSPDBContext db = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { MWQMLookupMPNService mwqmLookupMPNService = new MWQMLookupMPNService(query, db, ContactID); mwqmLookupMPNList = (from c in db.MWQMLookupMPNs select c).OrderBy(c => c.MWQMLookupMPNID).Skip(0).Take(2).ToList(); count = (from c in db.MWQMLookupMPNs select c).Count(); } if (count > 0) { query.Skip = 0; query.Take = 5; count = (query.Take > count ? query.Take : count); // ok with MWQMLookupMPN info jsonRet = mwqmLookupMPNController.GetMWQMLookupMPNList(query.Language.ToString(), query.Skip, query.Take); Assert.IsNotNull(jsonRet); ret = jsonRet as OkNegotiatedContentResult <List <MWQMLookupMPN> >; Assert.AreEqual(mwqmLookupMPNList[0].MWQMLookupMPNID, ret.Content[0].MWQMLookupMPNID); 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 MWQMLookupMPN info IHttpActionResult jsonRet2 = mwqmLookupMPNController.GetMWQMLookupMPNList(query.Language.ToString(), query.Skip, query.Take); Assert.IsNotNull(jsonRet2); OkNegotiatedContentResult <List <MWQMLookupMPN> > ret2 = jsonRet2 as OkNegotiatedContentResult <List <MWQMLookupMPN> >; Assert.AreEqual(mwqmLookupMPNList[1].MWQMLookupMPNID, ret2.Content[0].MWQMLookupMPNID); Assert.AreEqual((count > query.Take ? query.Take : count), ret2.Content.Count); } } } } }
public void MWQMLookupMPN_Controller_Delete_Test() { foreach (LanguageEnum LanguageRequest in AllowableLanguages) { foreach (int ContactID in new List <int>() { AdminContactID }) //, TestEmailValidatedContactID, TestEmailNotValidatedContactID }) { MWQMLookupMPNController mwqmLookupMPNController = new MWQMLookupMPNController(DatabaseTypeEnum.SqlServerTestDB); Assert.IsNotNull(mwqmLookupMPNController); Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, mwqmLookupMPNController.DatabaseType); MWQMLookupMPN mwqmLookupMPNLast = new MWQMLookupMPN(); using (CSSPDBContext db = new CSSPDBContext(DatabaseType)) { Query query = new Query(); query.Language = LanguageRequest; query.Asc = ""; query.Desc = ""; MWQMLookupMPNService mwqmLookupMPNService = new MWQMLookupMPNService(query, db, ContactID); mwqmLookupMPNLast = (from c in db.MWQMLookupMPNs select c).FirstOrDefault(); } // ok with MWQMLookupMPN info IHttpActionResult jsonRet = mwqmLookupMPNController.GetMWQMLookupMPNWithID(mwqmLookupMPNLast.MWQMLookupMPNID); Assert.IsNotNull(jsonRet); OkNegotiatedContentResult <MWQMLookupMPN> Ret = jsonRet as OkNegotiatedContentResult <MWQMLookupMPN>; MWQMLookupMPN mwqmLookupMPNRet = Ret.Content; Assert.AreEqual(mwqmLookupMPNLast.MWQMLookupMPNID, mwqmLookupMPNRet.MWQMLookupMPNID); BadRequestErrorMessageResult badRequest = jsonRet as BadRequestErrorMessageResult; Assert.IsNull(badRequest); // Post to return newly added MWQMLookupMPN mwqmLookupMPNRet.MWQMLookupMPNID = 0; mwqmLookupMPNRet.Tubes01 = 1; mwqmLookupMPNRet.Tubes1 = 1; mwqmLookupMPNRet.Tubes10 = 1; mwqmLookupMPNRet.MPN_100ml = 6; mwqmLookupMPNController.Request = new System.Net.Http.HttpRequestMessage(); mwqmLookupMPNController.Request.RequestUri = new System.Uri("http://localhost:5000/api/mwqmLookupMPN"); IHttpActionResult jsonRet3 = mwqmLookupMPNController.Post(mwqmLookupMPNRet, LanguageRequest.ToString()); Assert.IsNotNull(jsonRet3); CreatedNegotiatedContentResult <MWQMLookupMPN> mwqmLookupMPNRet3 = jsonRet3 as CreatedNegotiatedContentResult <MWQMLookupMPN>; Assert.IsNotNull(mwqmLookupMPNRet3); MWQMLookupMPN mwqmLookupMPN = mwqmLookupMPNRet3.Content; BadRequestErrorMessageResult badRequest3 = jsonRet3 as BadRequestErrorMessageResult; Assert.IsNull(badRequest3); // Delete to return success IHttpActionResult jsonRet2 = mwqmLookupMPNController.Delete(mwqmLookupMPNRet, LanguageRequest.ToString()); Assert.IsNotNull(jsonRet2); OkNegotiatedContentResult <MWQMLookupMPN> mwqmLookupMPNRet2 = jsonRet2 as OkNegotiatedContentResult <MWQMLookupMPN>; Assert.IsNotNull(mwqmLookupMPNRet2); BadRequestErrorMessageResult badRequest2 = jsonRet2 as BadRequestErrorMessageResult; Assert.IsNull(badRequest2); // Delete to return CSSPError because MWQMLookupMPNID of 0 does not exist mwqmLookupMPNRet.MWQMLookupMPNID = 0; IHttpActionResult jsonRet4 = mwqmLookupMPNController.Delete(mwqmLookupMPNRet, LanguageRequest.ToString()); Assert.IsNotNull(jsonRet4); OkNegotiatedContentResult <MWQMLookupMPN> mwqmLookupMPNRet4 = jsonRet4 as OkNegotiatedContentResult <MWQMLookupMPN>; Assert.IsNull(mwqmLookupMPNRet4); BadRequestErrorMessageResult badRequest4 = jsonRet4 as BadRequestErrorMessageResult; Assert.IsNotNull(badRequest4); } } }
public IHttpActionResult GetMWQMLookupMPNList([FromUri] string lang = "en", [FromUri] int skip = 0, [FromUri] int take = 200, [FromUri] string asc = "", [FromUri] string desc = "", [FromUri] string where = "", [FromUri] string extra = "") { using (CSSPDBContext db = new CSSPDBContext(DatabaseType)) { MWQMLookupMPNService mwqmLookupMPNService = new MWQMLookupMPNService(new Query() { Lang = lang }, db, ContactID); if (extra == "A") // QueryString contains [extra=A] { mwqmLookupMPNService.Query = mwqmLookupMPNService.FillQuery(typeof(MWQMLookupMPNExtraA), lang, skip, take, asc, desc, where, extra); if (mwqmLookupMPNService.Query.HasErrors) { return(Ok(new List <MWQMLookupMPNExtraA>() { new MWQMLookupMPNExtraA() { HasErrors = mwqmLookupMPNService.Query.HasErrors, ValidationResults = mwqmLookupMPNService.Query.ValidationResults, }, }.ToList())); } else { return(Ok(mwqmLookupMPNService.GetMWQMLookupMPNExtraAList().ToList())); } } else if (extra == "B") // QueryString contains [extra=B] { mwqmLookupMPNService.Query = mwqmLookupMPNService.FillQuery(typeof(MWQMLookupMPNExtraB), lang, skip, take, asc, desc, where, extra); if (mwqmLookupMPNService.Query.HasErrors) { return(Ok(new List <MWQMLookupMPNExtraB>() { new MWQMLookupMPNExtraB() { HasErrors = mwqmLookupMPNService.Query.HasErrors, ValidationResults = mwqmLookupMPNService.Query.ValidationResults, }, }.ToList())); } else { return(Ok(mwqmLookupMPNService.GetMWQMLookupMPNExtraBList().ToList())); } } else // QueryString has no parameter [extra] or extra is empty { mwqmLookupMPNService.Query = mwqmLookupMPNService.FillQuery(typeof(MWQMLookupMPN), lang, skip, take, asc, desc, where, extra); if (mwqmLookupMPNService.Query.HasErrors) { return(Ok(new List <MWQMLookupMPN>() { new MWQMLookupMPN() { HasErrors = mwqmLookupMPNService.Query.HasErrors, ValidationResults = mwqmLookupMPNService.Query.ValidationResults, }, }.ToList())); } else { return(Ok(mwqmLookupMPNService.GetMWQMLookupMPNList().ToList())); } } } }