public void Tel_Controller_Put_Test() { foreach (LanguageEnum LanguageRequest in AllowableLanguages) { foreach (int ContactID in new List <int>() { AdminContactID }) //, TestEmailValidatedContactID, TestEmailNotValidatedContactID }) { TelController telController = new TelController(DatabaseTypeEnum.SqlServerTestDB); Assert.IsNotNull(telController); Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, telController.DatabaseType); Tel telLast = new Tel(); using (CSSPDBContext db = new CSSPDBContext(DatabaseType)) { Query query = new Query(); query.Language = LanguageRequest; TelService telService = new TelService(query, db, ContactID); telLast = (from c in db.Tels select c).FirstOrDefault(); } // ok with Tel info IHttpActionResult jsonRet = telController.GetTelWithID(telLast.TelID); Assert.IsNotNull(jsonRet); OkNegotiatedContentResult <Tel> Ret = jsonRet as OkNegotiatedContentResult <Tel>; Tel telRet = Ret.Content; Assert.AreEqual(telLast.TelID, telRet.TelID); BadRequestErrorMessageResult badRequest = jsonRet as BadRequestErrorMessageResult; Assert.IsNull(badRequest); // Put to return success IHttpActionResult jsonRet2 = telController.Put(telRet, LanguageRequest.ToString()); Assert.IsNotNull(jsonRet2); OkNegotiatedContentResult <Tel> telRet2 = jsonRet2 as OkNegotiatedContentResult <Tel>; Assert.IsNotNull(telRet2); BadRequestErrorMessageResult badRequest2 = jsonRet2 as BadRequestErrorMessageResult; Assert.IsNull(badRequest2); // Put to return CSSPError because TelID of 0 does not exist telRet.TelID = 0; IHttpActionResult jsonRet3 = telController.Put(telRet, LanguageRequest.ToString()); Assert.IsNotNull(jsonRet3); OkNegotiatedContentResult <Tel> telRet3 = jsonRet3 as OkNegotiatedContentResult <Tel>; Assert.IsNull(telRet3); BadRequestErrorMessageResult badRequest3 = jsonRet3 as BadRequestErrorMessageResult; Assert.IsNotNull(badRequest3); } } }
public void TelController__telEditList_Test() { foreach (CultureInfo culture in setupData.cultureListGood) { controllerAction = "_telEditList"; contactModel = contactModelListGood[0]; SetupTest(contactModel, culture, controllerAction); using (TransactionScope ts = new TransactionScope()) { int ContactTVItemID = contactModelListGood[0].ContactTVItemID; TVItemLinkModel tvItemLinkModel = telService._TVItemLinkService.PostDeleteTVItemLinkWithFromTVItemIDDB(ContactTVItemID); Assert.AreEqual("", tvItemLinkModel.Error); TVItemModel tvItemModelContact = telService._TVItemService.GetTVItemModelWithTVItemIDDB(ContactTVItemID); Assert.AreEqual("", tvItemModelContact.Error); TelModel telModel = randomService.RandomTelModel(true); Assert.AreEqual("", telModel.Error); TVItemModel tvItemModelTel = telService._TVItemService.GetTVItemModelWithTVItemIDDB(telModel.TelTVItemID); Assert.AreEqual("", tvItemModelTel.Error); tvItemLinkModel = randomService.RandomTVItemLinkModel(tvItemModelContact, tvItemModelTel, true); Assert.AreEqual("", tvItemLinkModel.Error); PartialViewResult partialViewResult = controller._telEditList(ContactTVItemID) as PartialViewResult; Assert.IsNotNull(partialViewResult); ContactModel contactModelRet = (ContactModel)partialViewResult.ViewBag.ContactModel; Assert.AreEqual(contactModel.FirstName, contactModelRet.FirstName); Assert.AreEqual(contactModel.Initial, contactModelRet.Initial); Assert.AreEqual(contactModel.LastName, contactModelRet.LastName); List <TelModel> telModelList = (List <TelModel>)partialViewResult.ViewBag.TelModelList; Assert.AreEqual(1, telModelList.Count); Assert.AreEqual(telModel.TelNumber, telModelList[0].TelNumber); Assert.AreEqual(telModel.TelType, telModelList[0].TelType); TelController telControllerRet = (TelController)partialViewResult.ViewBag.TelController; Assert.IsNotNull(telControllerRet); } } }
public void Tel_Controller_GetTelWithID_Test() { foreach (LanguageEnum LanguageRequest in AllowableLanguages) { foreach (int ContactID in new List <int>() { AdminContactID }) //, TestEmailValidatedContactID, TestEmailNotValidatedContactID }) { TelController telController = new TelController(DatabaseTypeEnum.SqlServerTestDB); Assert.IsNotNull(telController); Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, telController.DatabaseType); Tel telFirst = new Tel(); using (CSSPDBContext db = new CSSPDBContext(DatabaseType)) { TelService telService = new TelService(new Query(), db, ContactID); telFirst = (from c in db.Tels select c).FirstOrDefault(); } // ok with Tel info IHttpActionResult jsonRet = telController.GetTelWithID(telFirst.TelID); Assert.IsNotNull(jsonRet); OkNegotiatedContentResult <Tel> Ret = jsonRet as OkNegotiatedContentResult <Tel>; Tel telRet = Ret.Content; Assert.AreEqual(telFirst.TelID, telRet.TelID); BadRequestErrorMessageResult badRequest = jsonRet as BadRequestErrorMessageResult; Assert.IsNull(badRequest); // Not Found IHttpActionResult jsonRet2 = telController.GetTelWithID(0); Assert.IsNotNull(jsonRet2); OkNegotiatedContentResult <Tel> telRet2 = jsonRet2 as OkNegotiatedContentResult <Tel>; Assert.IsNull(telRet2); NotFoundResult notFoundRequest = jsonRet2 as NotFoundResult; Assert.IsNotNull(notFoundRequest); } } }
private void SetupTest(ContactModel contactModelToDo, CultureInfo culture, string actionStr) { LanguageEnum languageEnum = (culture.TwoLetterISOLanguageName == "fr" ? LanguageEnum.fr : LanguageEnum.en); if (contactModelToDo == null) { user = null; } else { user = new GenericPrincipal(new GenericIdentity(contactModelToDo.LoginEmail, "Forms"), null); } routeData = new RouteData(); routeData.Values.Add("culture", culture); routeData.Values.Add("controller", controllerName); routeData.Values.Add("action", actionStr); stubHttpContext = new StubHttpContextBase(); stubHttpRequestBase = new StubHttpRequestBase(); stubHttpContext.RequestGet = () => stubHttpRequestBase; requestContext = new RequestContext(stubHttpContext, routeData); controller = new TelController(); controller.Url = new UrlHelper(requestContext); controller.ControllerContext = new ControllerContext(stubHttpContext, routeData, controller); stubHttpContext.UserGet = () => user; controller.SetRequestContext(requestContext); // BaseController Asserts Assert.IsNotNull(controller); Assert.AreEqual(2, controller.CultureListAllowable.Count); Assert.AreEqual("en-CA", controller.CultureListAllowable[0]); Assert.AreEqual("fr-CA", controller.CultureListAllowable[1]); Assert.IsNotNull(controller._ContactService); Assert.IsNotNull(controller._RequestContext); Assert.IsNotNull(controller._TVItemService); Assert.IsNotNull(controller._TVItemStatService); Assert.IsNotNull(culture.Name, controller._RequestContext.RouteData.Values["culture"].ToString()); Assert.IsNotNull(controllerName, controller._RequestContext.RouteData.Values["controller"].ToString()); Assert.IsNotNull(actionStr, controller._RequestContext.RouteData.Values["action"].ToString()); Assert.AreEqual((culture.TwoLetterISOLanguageName == "fr" ? LanguageEnum.fr : LanguageEnum.en), controller.LanguageRequest); Assert.AreEqual((culture.TwoLetterISOLanguageName == "fr" ? LanguageEnum.fr : LanguageEnum.en), controller.ViewBag.Language); Assert.AreEqual(culture.Name, controller.CultureRequest); Assert.AreEqual(culture.Name, controller.ViewBag.Culture); Assert.AreEqual(Thread.CurrentThread.CurrentCulture, culture); Assert.AreEqual(Thread.CurrentThread.CurrentUICulture, culture); if (contactModelToDo != null) { Assert.AreEqual(contactModelToDo.IsAdmin, controller.IsAdmin); Assert.AreEqual(contactModelToDo.IsAdmin, controller.ViewBag.IsAdmin); } Assert.AreEqual(true, controller.Debug); Assert.AreEqual(true, controller.ViewBag.Debug); // TelController Asserts Assert.IsNotNull(controller._TelController); Assert.IsNotNull(controller._TelService); Assert.IsNotNull(controller._TVItemLinkService); // variables for testing randomService = new RandomService(languageEnum, user); telService = new TelService(languageEnum, user); }
public void Tel_Controller_GetTelList_Test() { foreach (LanguageEnum LanguageRequest in AllowableLanguages) { foreach (int ContactID in new List <int>() { AdminContactID }) //, TestEmailValidatedContactID, TestEmailNotValidatedContactID }) { TelController telController = new TelController(DatabaseTypeEnum.SqlServerTestDB); Assert.IsNotNull(telController); Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, telController.DatabaseType); Tel telFirst = new Tel(); int count = -1; Query query = new Query(); using (CSSPDBContext db = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { TelService telService = new TelService(query, db, ContactID); telFirst = (from c in db.Tels select c).FirstOrDefault(); count = (from c in db.Tels select c).Count(); count = (query.Take > count ? count : query.Take); } // ok with Tel info IHttpActionResult jsonRet = telController.GetTelList(); Assert.IsNotNull(jsonRet); OkNegotiatedContentResult <List <Tel> > ret = jsonRet as OkNegotiatedContentResult <List <Tel> >; Assert.AreEqual(telFirst.TelID, ret.Content[0].TelID); Assert.AreEqual((count > query.Take ? query.Take : count), ret.Content.Count); List <Tel> telList = new List <Tel>(); count = -1; query = new Query(); using (CSSPDBContext db = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { TelService telService = new TelService(query, db, ContactID); telList = (from c in db.Tels select c).OrderBy(c => c.TelID).Skip(0).Take(2).ToList(); count = (from c in db.Tels select c).Count(); } if (count > 0) { query.Skip = 0; query.Take = 5; count = (query.Take > count ? query.Take : count); // ok with Tel info jsonRet = telController.GetTelList(query.Language.ToString(), query.Skip, query.Take); Assert.IsNotNull(jsonRet); ret = jsonRet as OkNegotiatedContentResult <List <Tel> >; Assert.AreEqual(telList[0].TelID, ret.Content[0].TelID); 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 Tel info IHttpActionResult jsonRet2 = telController.GetTelList(query.Language.ToString(), query.Skip, query.Take); Assert.IsNotNull(jsonRet2); OkNegotiatedContentResult <List <Tel> > ret2 = jsonRet2 as OkNegotiatedContentResult <List <Tel> >; Assert.AreEqual(telList[1].TelID, ret2.Content[0].TelID); Assert.AreEqual((count > query.Take ? query.Take : count), ret2.Content.Count); } } } } }
public void Tel_Controller_Post_Test() { foreach (LanguageEnum LanguageRequest in AllowableLanguages) { foreach (int ContactID in new List <int>() { AdminContactID }) //, TestEmailValidatedContactID, TestEmailNotValidatedContactID }) { TelController telController = new TelController(DatabaseTypeEnum.SqlServerTestDB); Assert.IsNotNull(telController); Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, telController.DatabaseType); Tel telLast = new Tel(); using (CSSPDBContext db = new CSSPDBContext(DatabaseType)) { Query query = new Query(); query.Language = LanguageRequest; query.Asc = ""; query.Desc = ""; TelService telService = new TelService(query, db, ContactID); telLast = (from c in db.Tels select c).FirstOrDefault(); } // ok with Tel info IHttpActionResult jsonRet = telController.GetTelWithID(telLast.TelID); Assert.IsNotNull(jsonRet); OkNegotiatedContentResult <Tel> Ret = jsonRet as OkNegotiatedContentResult <Tel>; Tel telRet = Ret.Content; Assert.AreEqual(telLast.TelID, telRet.TelID); BadRequestErrorMessageResult badRequest = jsonRet as BadRequestErrorMessageResult; Assert.IsNull(badRequest); // Post to return CSSPError because TelID exist IHttpActionResult jsonRet2 = telController.Post(telRet, LanguageRequest.ToString()); Assert.IsNotNull(jsonRet2); OkNegotiatedContentResult <Tel> telRet2 = jsonRet2 as OkNegotiatedContentResult <Tel>; Assert.IsNull(telRet2); BadRequestErrorMessageResult badRequest2 = jsonRet2 as BadRequestErrorMessageResult; Assert.IsNotNull(badRequest2); // Post to return newly added Tel telRet.TelID = 0; telController.Request = new System.Net.Http.HttpRequestMessage(); telController.Request.RequestUri = new System.Uri("http://localhost:5000/api/tel"); IHttpActionResult jsonRet3 = telController.Post(telRet, LanguageRequest.ToString()); Assert.IsNotNull(jsonRet3); CreatedNegotiatedContentResult <Tel> telRet3 = jsonRet3 as CreatedNegotiatedContentResult <Tel>; Assert.IsNotNull(telRet3); BadRequestErrorMessageResult badRequest3 = jsonRet3 as BadRequestErrorMessageResult; Assert.IsNull(badRequest3); IHttpActionResult jsonRet4 = telController.Delete(telRet, LanguageRequest.ToString()); Assert.IsNotNull(jsonRet4); OkNegotiatedContentResult <Tel> telRet4 = jsonRet4 as OkNegotiatedContentResult <Tel>; Assert.IsNotNull(telRet4); BadRequestErrorMessageResult badRequest4 = jsonRet4 as BadRequestErrorMessageResult; Assert.IsNull(badRequest4); } } }