public void InfrastructureControllerConstructorTest1() { var adwService = new Mock <IAdwService>().Object; var target = new InfrastructureController(null, adwService); Assert.Fail("Expected Exception"); }
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", "Infrastructure"); routeData.Values.Add("action", actionStr); stubHttpContext = new StubHttpContextBase(); stubHttpRequestBase = new StubHttpRequestBase(); stubHttpContext.RequestGet = () => stubHttpRequestBase; requestContext = new RequestContext(stubHttpContext, routeData); controller = new InfrastructureController(); controller.Url = new UrlHelper(requestContext); controller.ControllerContext = new ControllerContext(stubHttpContext, routeData, controller); stubHttpContext.UserGet = () => user; randomService = new RandomService(languageEnum, user); tvItemService = new TVItemService(languageEnum, user); infrastructureService = new InfrastructureService(languageEnum, user); tvItemLinkService = new TVItemLinkService(languageEnum, user); mapInfoPointService = new MapInfoPointService(languageEnum, user); controller.SetRequestContext(requestContext); 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._InfrastructureService); Assert.IsNotNull(controller._TVItemService); Assert.IsNotNull(controller.urlModel); Assert.IsNotNull(culture.Name, controller._RequestContext.RouteData.Values["culture"].ToString()); Assert.IsNotNull("Infrastructure", 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); 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); }
public void Infrastructure_Controller_Put_Test() { foreach (LanguageEnum LanguageRequest in AllowableLanguages) { foreach (int ContactID in new List <int>() { AdminContactID }) //, TestEmailValidatedContactID, TestEmailNotValidatedContactID }) { InfrastructureController infrastructureController = new InfrastructureController(DatabaseTypeEnum.SqlServerTestDB); Assert.IsNotNull(infrastructureController); Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, infrastructureController.DatabaseType); Infrastructure infrastructureLast = new Infrastructure(); using (CSSPDBContext db = new CSSPDBContext(DatabaseType)) { Query query = new Query(); query.Language = LanguageRequest; InfrastructureService infrastructureService = new InfrastructureService(query, db, ContactID); infrastructureLast = (from c in db.Infrastructures select c).FirstOrDefault(); } // ok with Infrastructure info IHttpActionResult jsonRet = infrastructureController.GetInfrastructureWithID(infrastructureLast.InfrastructureID); Assert.IsNotNull(jsonRet); OkNegotiatedContentResult <Infrastructure> Ret = jsonRet as OkNegotiatedContentResult <Infrastructure>; Infrastructure infrastructureRet = Ret.Content; Assert.AreEqual(infrastructureLast.InfrastructureID, infrastructureRet.InfrastructureID); BadRequestErrorMessageResult badRequest = jsonRet as BadRequestErrorMessageResult; Assert.IsNull(badRequest); // Put to return success IHttpActionResult jsonRet2 = infrastructureController.Put(infrastructureRet, LanguageRequest.ToString()); Assert.IsNotNull(jsonRet2); OkNegotiatedContentResult <Infrastructure> infrastructureRet2 = jsonRet2 as OkNegotiatedContentResult <Infrastructure>; Assert.IsNotNull(infrastructureRet2); BadRequestErrorMessageResult badRequest2 = jsonRet2 as BadRequestErrorMessageResult; Assert.IsNull(badRequest2); // Put to return CSSPError because InfrastructureID of 0 does not exist infrastructureRet.InfrastructureID = 0; IHttpActionResult jsonRet3 = infrastructureController.Put(infrastructureRet, LanguageRequest.ToString()); Assert.IsNotNull(jsonRet3); OkNegotiatedContentResult <Infrastructure> infrastructureRet3 = jsonRet3 as OkNegotiatedContentResult <Infrastructure>; Assert.IsNull(infrastructureRet3); BadRequestErrorMessageResult badRequest3 = jsonRet3 as BadRequestErrorMessageResult; Assert.IsNotNull(badRequest3); } } }
public void Infrastructure_Controller_GetInfrastructureWithID_Test() { foreach (LanguageEnum LanguageRequest in AllowableLanguages) { foreach (int ContactID in new List <int>() { AdminContactID }) //, TestEmailValidatedContactID, TestEmailNotValidatedContactID }) { InfrastructureController infrastructureController = new InfrastructureController(DatabaseTypeEnum.SqlServerTestDB); Assert.IsNotNull(infrastructureController); Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, infrastructureController.DatabaseType); Infrastructure infrastructureFirst = new Infrastructure(); using (CSSPDBContext db = new CSSPDBContext(DatabaseType)) { InfrastructureService infrastructureService = new InfrastructureService(new Query(), db, ContactID); infrastructureFirst = (from c in db.Infrastructures select c).FirstOrDefault(); } // ok with Infrastructure info IHttpActionResult jsonRet = infrastructureController.GetInfrastructureWithID(infrastructureFirst.InfrastructureID); Assert.IsNotNull(jsonRet); OkNegotiatedContentResult <Infrastructure> Ret = jsonRet as OkNegotiatedContentResult <Infrastructure>; Infrastructure infrastructureRet = Ret.Content; Assert.AreEqual(infrastructureFirst.InfrastructureID, infrastructureRet.InfrastructureID); BadRequestErrorMessageResult badRequest = jsonRet as BadRequestErrorMessageResult; Assert.IsNull(badRequest); // Not Found IHttpActionResult jsonRet2 = infrastructureController.GetInfrastructureWithID(0); Assert.IsNotNull(jsonRet2); OkNegotiatedContentResult <Infrastructure> infrastructureRet2 = jsonRet2 as OkNegotiatedContentResult <Infrastructure>; Assert.IsNull(infrastructureRet2); NotFoundResult notFoundRequest = jsonRet2 as NotFoundResult; Assert.IsNotNull(notFoundRequest); } } }
public void Infrastructure_Controller_GetInfrastructureList_Test() { foreach (LanguageEnum LanguageRequest in AllowableLanguages) { foreach (int ContactID in new List <int>() { AdminContactID }) //, TestEmailValidatedContactID, TestEmailNotValidatedContactID }) { InfrastructureController infrastructureController = new InfrastructureController(DatabaseTypeEnum.SqlServerTestDB); Assert.IsNotNull(infrastructureController); Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, infrastructureController.DatabaseType); Infrastructure infrastructureFirst = new Infrastructure(); int count = -1; Query query = new Query(); using (CSSPDBContext db = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { InfrastructureService infrastructureService = new InfrastructureService(query, db, ContactID); infrastructureFirst = (from c in db.Infrastructures select c).FirstOrDefault(); count = (from c in db.Infrastructures select c).Count(); count = (query.Take > count ? count : query.Take); } // ok with Infrastructure info IHttpActionResult jsonRet = infrastructureController.GetInfrastructureList(); Assert.IsNotNull(jsonRet); OkNegotiatedContentResult <List <Infrastructure> > ret = jsonRet as OkNegotiatedContentResult <List <Infrastructure> >; Assert.AreEqual(infrastructureFirst.InfrastructureID, ret.Content[0].InfrastructureID); Assert.AreEqual((count > query.Take ? query.Take : count), ret.Content.Count); List <Infrastructure> infrastructureList = new List <Infrastructure>(); count = -1; query = new Query(); using (CSSPDBContext db = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { InfrastructureService infrastructureService = new InfrastructureService(query, db, ContactID); infrastructureList = (from c in db.Infrastructures select c).OrderBy(c => c.InfrastructureID).Skip(0).Take(2).ToList(); count = (from c in db.Infrastructures select c).Count(); } if (count > 0) { query.Skip = 0; query.Take = 5; count = (query.Take > count ? query.Take : count); // ok with Infrastructure info jsonRet = infrastructureController.GetInfrastructureList(query.Language.ToString(), query.Skip, query.Take); Assert.IsNotNull(jsonRet); ret = jsonRet as OkNegotiatedContentResult <List <Infrastructure> >; Assert.AreEqual(infrastructureList[0].InfrastructureID, ret.Content[0].InfrastructureID); 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 Infrastructure info IHttpActionResult jsonRet2 = infrastructureController.GetInfrastructureList(query.Language.ToString(), query.Skip, query.Take); Assert.IsNotNull(jsonRet2); OkNegotiatedContentResult <List <Infrastructure> > ret2 = jsonRet2 as OkNegotiatedContentResult <List <Infrastructure> >; Assert.AreEqual(infrastructureList[1].InfrastructureID, ret2.Content[0].InfrastructureID); Assert.AreEqual((count > query.Take ? query.Take : count), ret2.Content.Count); } } } } }
public void Infrastructure_Controller_Post_Test() { foreach (LanguageEnum LanguageRequest in AllowableLanguages) { foreach (int ContactID in new List <int>() { AdminContactID }) //, TestEmailValidatedContactID, TestEmailNotValidatedContactID }) { InfrastructureController infrastructureController = new InfrastructureController(DatabaseTypeEnum.SqlServerTestDB); Assert.IsNotNull(infrastructureController); Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, infrastructureController.DatabaseType); Infrastructure infrastructureLast = new Infrastructure(); using (CSSPDBContext db = new CSSPDBContext(DatabaseType)) { Query query = new Query(); query.Language = LanguageRequest; query.Asc = ""; query.Desc = ""; InfrastructureService infrastructureService = new InfrastructureService(query, db, ContactID); infrastructureLast = (from c in db.Infrastructures select c).FirstOrDefault(); } // ok with Infrastructure info IHttpActionResult jsonRet = infrastructureController.GetInfrastructureWithID(infrastructureLast.InfrastructureID); Assert.IsNotNull(jsonRet); OkNegotiatedContentResult <Infrastructure> Ret = jsonRet as OkNegotiatedContentResult <Infrastructure>; Infrastructure infrastructureRet = Ret.Content; Assert.AreEqual(infrastructureLast.InfrastructureID, infrastructureRet.InfrastructureID); BadRequestErrorMessageResult badRequest = jsonRet as BadRequestErrorMessageResult; Assert.IsNull(badRequest); // Post to return CSSPError because InfrastructureID exist IHttpActionResult jsonRet2 = infrastructureController.Post(infrastructureRet, LanguageRequest.ToString()); Assert.IsNotNull(jsonRet2); OkNegotiatedContentResult <Infrastructure> infrastructureRet2 = jsonRet2 as OkNegotiatedContentResult <Infrastructure>; Assert.IsNull(infrastructureRet2); BadRequestErrorMessageResult badRequest2 = jsonRet2 as BadRequestErrorMessageResult; Assert.IsNotNull(badRequest2); // Post to return newly added Infrastructure infrastructureRet.InfrastructureID = 0; infrastructureController.Request = new System.Net.Http.HttpRequestMessage(); infrastructureController.Request.RequestUri = new System.Uri("http://localhost:5000/api/infrastructure"); IHttpActionResult jsonRet3 = infrastructureController.Post(infrastructureRet, LanguageRequest.ToString()); Assert.IsNotNull(jsonRet3); CreatedNegotiatedContentResult <Infrastructure> infrastructureRet3 = jsonRet3 as CreatedNegotiatedContentResult <Infrastructure>; Assert.IsNotNull(infrastructureRet3); BadRequestErrorMessageResult badRequest3 = jsonRet3 as BadRequestErrorMessageResult; Assert.IsNull(badRequest3); IHttpActionResult jsonRet4 = infrastructureController.Delete(infrastructureRet, LanguageRequest.ToString()); Assert.IsNotNull(jsonRet4); OkNegotiatedContentResult <Infrastructure> infrastructureRet4 = jsonRet4 as OkNegotiatedContentResult <Infrastructure>; Assert.IsNotNull(infrastructureRet4); BadRequestErrorMessageResult badRequest4 = jsonRet4 as BadRequestErrorMessageResult; Assert.IsNull(badRequest4); } } }