public void GetContactShortcutList_Skip_Take_Asc_Where_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" }) { ContactShortcutService contactShortcutService = new ContactShortcutService(new Query() { Lang = culture.TwoLetterISOLanguageName }, dbTestDB, ContactID); contactShortcutService.Query = contactShortcutService.FillQuery(typeof(ContactShortcut), culture.TwoLetterISOLanguageName, 0, 1, "ContactShortcutID", "", "ContactShortcutID,EQ,4", ""); List <ContactShortcut> contactShortcutDirectQueryList = new List <ContactShortcut>(); contactShortcutDirectQueryList = (from c in dbTestDB.ContactShortcuts select c).Where(c => c.ContactShortcutID == 4).OrderBy(c => c.ContactShortcutID).Skip(0).Take(1).ToList(); if (string.IsNullOrWhiteSpace(extra)) { List <ContactShortcut> contactShortcutList = new List <ContactShortcut>(); contactShortcutList = contactShortcutService.GetContactShortcutList().ToList(); CheckContactShortcutFields(contactShortcutList); Assert.AreEqual(contactShortcutDirectQueryList[0].ContactShortcutID, contactShortcutList[0].ContactShortcutID); } else { //Assert.AreEqual(true, false); } } } } }
public void ContactShortcut_Controller_GetContactShortcutList_Test() { foreach (LanguageEnum LanguageRequest in AllowableLanguages) { foreach (int ContactID in new List <int>() { AdminContactID }) //, TestEmailValidatedContactID, TestEmailNotValidatedContactID }) { ContactShortcutController contactShortcutController = new ContactShortcutController(DatabaseTypeEnum.SqlServerTestDB); Assert.IsNotNull(contactShortcutController); Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, contactShortcutController.DatabaseType); ContactShortcut contactShortcutFirst = new ContactShortcut(); int count = -1; Query query = new Query(); using (CSSPDBContext db = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { ContactShortcutService contactShortcutService = new ContactShortcutService(query, db, ContactID); contactShortcutFirst = (from c in db.ContactShortcuts select c).FirstOrDefault(); count = (from c in db.ContactShortcuts select c).Count(); count = (query.Take > count ? count : query.Take); } // ok with ContactShortcut info IHttpActionResult jsonRet = contactShortcutController.GetContactShortcutList(); Assert.IsNotNull(jsonRet); OkNegotiatedContentResult <List <ContactShortcut> > ret = jsonRet as OkNegotiatedContentResult <List <ContactShortcut> >; Assert.AreEqual(contactShortcutFirst.ContactShortcutID, ret.Content[0].ContactShortcutID); Assert.AreEqual((count > query.Take ? query.Take : count), ret.Content.Count); List <ContactShortcut> contactShortcutList = new List <ContactShortcut>(); count = -1; query = new Query(); using (CSSPDBContext db = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { ContactShortcutService contactShortcutService = new ContactShortcutService(query, db, ContactID); contactShortcutList = (from c in db.ContactShortcuts select c).OrderBy(c => c.ContactShortcutID).Skip(0).Take(2).ToList(); count = (from c in db.ContactShortcuts select c).Count(); } if (count > 0) { query.Skip = 0; query.Take = 5; count = (query.Take > count ? query.Take : count); // ok with ContactShortcut info jsonRet = contactShortcutController.GetContactShortcutList(query.Language.ToString(), query.Skip, query.Take); Assert.IsNotNull(jsonRet); ret = jsonRet as OkNegotiatedContentResult <List <ContactShortcut> >; Assert.AreEqual(contactShortcutList[0].ContactShortcutID, ret.Content[0].ContactShortcutID); 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 ContactShortcut info IHttpActionResult jsonRet2 = contactShortcutController.GetContactShortcutList(query.Language.ToString(), query.Skip, query.Take); Assert.IsNotNull(jsonRet2); OkNegotiatedContentResult <List <ContactShortcut> > ret2 = jsonRet2 as OkNegotiatedContentResult <List <ContactShortcut> >; Assert.AreEqual(contactShortcutList[1].ContactShortcutID, ret2.Content[0].ContactShortcutID); Assert.AreEqual((count > query.Take ? query.Take : count), ret2.Content.Count); } } } } }
public void ContactShortcut_Controller_Delete_Test() { foreach (LanguageEnum LanguageRequest in AllowableLanguages) { foreach (int ContactID in new List <int>() { AdminContactID }) //, TestEmailValidatedContactID, TestEmailNotValidatedContactID }) { ContactShortcutController contactShortcutController = new ContactShortcutController(DatabaseTypeEnum.SqlServerTestDB); Assert.IsNotNull(contactShortcutController); Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, contactShortcutController.DatabaseType); ContactShortcut contactShortcutLast = new ContactShortcut(); using (CSSPDBContext db = new CSSPDBContext(DatabaseType)) { Query query = new Query(); query.Language = LanguageRequest; query.Asc = ""; query.Desc = ""; ContactShortcutService contactShortcutService = new ContactShortcutService(query, db, ContactID); contactShortcutLast = (from c in db.ContactShortcuts select c).FirstOrDefault(); } // ok with ContactShortcut info IHttpActionResult jsonRet = contactShortcutController.GetContactShortcutWithID(contactShortcutLast.ContactShortcutID); Assert.IsNotNull(jsonRet); OkNegotiatedContentResult <ContactShortcut> Ret = jsonRet as OkNegotiatedContentResult <ContactShortcut>; ContactShortcut contactShortcutRet = Ret.Content; Assert.AreEqual(contactShortcutLast.ContactShortcutID, contactShortcutRet.ContactShortcutID); BadRequestErrorMessageResult badRequest = jsonRet as BadRequestErrorMessageResult; Assert.IsNull(badRequest); // Post to return newly added ContactShortcut contactShortcutRet.ContactShortcutID = 0; contactShortcutController.Request = new System.Net.Http.HttpRequestMessage(); contactShortcutController.Request.RequestUri = new System.Uri("http://localhost:5000/api/contactShortcut"); IHttpActionResult jsonRet3 = contactShortcutController.Post(contactShortcutRet, LanguageRequest.ToString()); Assert.IsNotNull(jsonRet3); CreatedNegotiatedContentResult <ContactShortcut> contactShortcutRet3 = jsonRet3 as CreatedNegotiatedContentResult <ContactShortcut>; Assert.IsNotNull(contactShortcutRet3); ContactShortcut contactShortcut = contactShortcutRet3.Content; BadRequestErrorMessageResult badRequest3 = jsonRet3 as BadRequestErrorMessageResult; Assert.IsNull(badRequest3); // Delete to return success IHttpActionResult jsonRet2 = contactShortcutController.Delete(contactShortcutRet, LanguageRequest.ToString()); Assert.IsNotNull(jsonRet2); OkNegotiatedContentResult <ContactShortcut> contactShortcutRet2 = jsonRet2 as OkNegotiatedContentResult <ContactShortcut>; Assert.IsNotNull(contactShortcutRet2); BadRequestErrorMessageResult badRequest2 = jsonRet2 as BadRequestErrorMessageResult; Assert.IsNull(badRequest2); // Delete to return CSSPError because ContactShortcutID of 0 does not exist contactShortcutRet.ContactShortcutID = 0; IHttpActionResult jsonRet4 = contactShortcutController.Delete(contactShortcutRet, LanguageRequest.ToString()); Assert.IsNotNull(jsonRet4); OkNegotiatedContentResult <ContactShortcut> contactShortcutRet4 = jsonRet4 as OkNegotiatedContentResult <ContactShortcut>; Assert.IsNull(contactShortcutRet4); BadRequestErrorMessageResult badRequest4 = jsonRet4 as BadRequestErrorMessageResult; Assert.IsNotNull(badRequest4); } } }
public void ContactShortcut_Properties_Test() { foreach (CultureInfo culture in AllowableCulture) { ChangeCulture(culture); using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { ContactShortcutService contactShortcutService = new ContactShortcutService(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 = contactShortcutService.GetContactShortcutList().Count(); ContactShortcut contactShortcut = GetFilledRandomContactShortcut(""); // ------------------------------- // ------------------------------- // Properties testing // ------------------------------- // ------------------------------- // ----------------------------------- // [Key] // Is NOT Nullable // contactShortcut.ContactShortcutID (Int32) // ----------------------------------- contactShortcut = null; contactShortcut = GetFilledRandomContactShortcut(""); contactShortcut.ContactShortcutID = 0; contactShortcutService.Update(contactShortcut); Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "ContactShortcutID"), contactShortcut.ValidationResults.FirstOrDefault().ErrorMessage); contactShortcut = null; contactShortcut = GetFilledRandomContactShortcut(""); contactShortcut.ContactShortcutID = 10000000; contactShortcutService.Update(contactShortcut); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "ContactShortcut", "ContactShortcutID", contactShortcut.ContactShortcutID.ToString()), contactShortcut.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [CSSPExist(ExistTypeName = "Contact", ExistPlurial = "s", ExistFieldID = "ContactID", AllowableTVtypeList = )] // contactShortcut.ContactID (Int32) // ----------------------------------- contactShortcut = null; contactShortcut = GetFilledRandomContactShortcut(""); contactShortcut.ContactID = 0; contactShortcutService.Add(contactShortcut); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "Contact", "ContactID", contactShortcut.ContactID.ToString()), contactShortcut.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [StringLength(100))] // contactShortcut.ShortCutText (String) // ----------------------------------- contactShortcut = null; contactShortcut = GetFilledRandomContactShortcut("ShortCutText"); Assert.AreEqual(false, contactShortcutService.Add(contactShortcut)); Assert.AreEqual(1, contactShortcut.ValidationResults.Count()); Assert.IsTrue(contactShortcut.ValidationResults.Where(c => c.ErrorMessage == string.Format(CSSPServicesRes._IsRequired, "ShortCutText")).Any()); Assert.AreEqual(null, contactShortcut.ShortCutText); Assert.AreEqual(count, contactShortcutService.GetContactShortcutList().Count()); contactShortcut = null; contactShortcut = GetFilledRandomContactShortcut(""); contactShortcut.ShortCutText = GetRandomString("", 101); Assert.AreEqual(false, contactShortcutService.Add(contactShortcut)); Assert.AreEqual(string.Format(CSSPServicesRes._MaxLengthIs_, "ShortCutText", "100"), contactShortcut.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, contactShortcutService.GetContactShortcutList().Count()); // ----------------------------------- // Is NOT Nullable // [StringLength(200))] // contactShortcut.ShortCutAddress (String) // ----------------------------------- contactShortcut = null; contactShortcut = GetFilledRandomContactShortcut("ShortCutAddress"); Assert.AreEqual(false, contactShortcutService.Add(contactShortcut)); Assert.AreEqual(1, contactShortcut.ValidationResults.Count()); Assert.IsTrue(contactShortcut.ValidationResults.Where(c => c.ErrorMessage == string.Format(CSSPServicesRes._IsRequired, "ShortCutAddress")).Any()); Assert.AreEqual(null, contactShortcut.ShortCutAddress); Assert.AreEqual(count, contactShortcutService.GetContactShortcutList().Count()); contactShortcut = null; contactShortcut = GetFilledRandomContactShortcut(""); contactShortcut.ShortCutAddress = GetRandomString("", 201); Assert.AreEqual(false, contactShortcutService.Add(contactShortcut)); Assert.AreEqual(string.Format(CSSPServicesRes._MaxLengthIs_, "ShortCutAddress", "200"), contactShortcut.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, contactShortcutService.GetContactShortcutList().Count()); // ----------------------------------- // Is NOT Nullable // [CSSPAfter(Year = 1980)] // contactShortcut.LastUpdateDate_UTC (DateTime) // ----------------------------------- contactShortcut = null; contactShortcut = GetFilledRandomContactShortcut(""); contactShortcut.LastUpdateDate_UTC = new DateTime(); contactShortcutService.Add(contactShortcut); Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "LastUpdateDate_UTC"), contactShortcut.ValidationResults.FirstOrDefault().ErrorMessage); contactShortcut = null; contactShortcut = GetFilledRandomContactShortcut(""); contactShortcut.LastUpdateDate_UTC = new DateTime(1979, 1, 1); contactShortcutService.Add(contactShortcut); Assert.AreEqual(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "LastUpdateDate_UTC", "1980"), contactShortcut.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [CSSPExist(ExistTypeName = "TVItem", ExistPlurial = "s", ExistFieldID = "TVItemID", AllowableTVtypeList = Contact)] // contactShortcut.LastUpdateContactTVItemID (Int32) // ----------------------------------- contactShortcut = null; contactShortcut = GetFilledRandomContactShortcut(""); contactShortcut.LastUpdateContactTVItemID = 0; contactShortcutService.Add(contactShortcut); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "LastUpdateContactTVItemID", contactShortcut.LastUpdateContactTVItemID.ToString()), contactShortcut.ValidationResults.FirstOrDefault().ErrorMessage); contactShortcut = null; contactShortcut = GetFilledRandomContactShortcut(""); contactShortcut.LastUpdateContactTVItemID = 1; contactShortcutService.Add(contactShortcut); Assert.AreEqual(string.Format(CSSPServicesRes._IsNotOfType_, "LastUpdateContactTVItemID", "Contact"), contactShortcut.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [NotMapped] // contactShortcut.HasErrors (Boolean) // ----------------------------------- // No testing requied // ----------------------------------- // Is NOT Nullable // [NotMapped] // contactShortcut.ValidationResults (IEnumerable`1) // ----------------------------------- // No testing requied } } }
public IHttpActionResult GetContactShortcutList([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)) { ContactShortcutService contactShortcutService = new ContactShortcutService(new Query() { Lang = lang }, db, ContactID); if (extra == "A") // QueryString contains [extra=A] { contactShortcutService.Query = contactShortcutService.FillQuery(typeof(ContactShortcutExtraA), lang, skip, take, asc, desc, where, extra); if (contactShortcutService.Query.HasErrors) { return(Ok(new List <ContactShortcutExtraA>() { new ContactShortcutExtraA() { HasErrors = contactShortcutService.Query.HasErrors, ValidationResults = contactShortcutService.Query.ValidationResults, }, }.ToList())); } else { return(Ok(contactShortcutService.GetContactShortcutExtraAList().ToList())); } } else if (extra == "B") // QueryString contains [extra=B] { contactShortcutService.Query = contactShortcutService.FillQuery(typeof(ContactShortcutExtraB), lang, skip, take, asc, desc, where, extra); if (contactShortcutService.Query.HasErrors) { return(Ok(new List <ContactShortcutExtraB>() { new ContactShortcutExtraB() { HasErrors = contactShortcutService.Query.HasErrors, ValidationResults = contactShortcutService.Query.ValidationResults, }, }.ToList())); } else { return(Ok(contactShortcutService.GetContactShortcutExtraBList().ToList())); } } else // QueryString has no parameter [extra] or extra is empty { contactShortcutService.Query = contactShortcutService.FillQuery(typeof(ContactShortcut), lang, skip, take, asc, desc, where, extra); if (contactShortcutService.Query.HasErrors) { return(Ok(new List <ContactShortcut>() { new ContactShortcut() { HasErrors = contactShortcutService.Query.HasErrors, ValidationResults = contactShortcutService.Query.ValidationResults, }, }.ToList())); } else { return(Ok(contactShortcutService.GetContactShortcutList().ToList())); } } } }