public void TVItemLanguage_Controller_Put_Test() { foreach (LanguageEnum LanguageRequest in AllowableLanguages) { foreach (int ContactID in new List <int>() { AdminContactID }) //, TestEmailValidatedContactID, TestEmailNotValidatedContactID }) { TVItemLanguageController tvItemLanguageController = new TVItemLanguageController(DatabaseTypeEnum.SqlServerTestDB); Assert.IsNotNull(tvItemLanguageController); Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, tvItemLanguageController.DatabaseType); TVItemLanguage tvItemLanguageLast = new TVItemLanguage(); using (CSSPDBContext db = new CSSPDBContext(DatabaseType)) { Query query = new Query(); query.Language = LanguageRequest; TVItemLanguageService tvItemLanguageService = new TVItemLanguageService(query, db, ContactID); tvItemLanguageLast = (from c in db.TVItemLanguages select c).FirstOrDefault(); } // ok with TVItemLanguage info IHttpActionResult jsonRet = tvItemLanguageController.GetTVItemLanguageWithID(tvItemLanguageLast.TVItemLanguageID); Assert.IsNotNull(jsonRet); OkNegotiatedContentResult <TVItemLanguage> Ret = jsonRet as OkNegotiatedContentResult <TVItemLanguage>; TVItemLanguage tvItemLanguageRet = Ret.Content; Assert.AreEqual(tvItemLanguageLast.TVItemLanguageID, tvItemLanguageRet.TVItemLanguageID); BadRequestErrorMessageResult badRequest = jsonRet as BadRequestErrorMessageResult; Assert.IsNull(badRequest); // Put to return success IHttpActionResult jsonRet2 = tvItemLanguageController.Put(tvItemLanguageRet, LanguageRequest.ToString()); Assert.IsNotNull(jsonRet2); OkNegotiatedContentResult <TVItemLanguage> tvItemLanguageRet2 = jsonRet2 as OkNegotiatedContentResult <TVItemLanguage>; Assert.IsNotNull(tvItemLanguageRet2); BadRequestErrorMessageResult badRequest2 = jsonRet2 as BadRequestErrorMessageResult; Assert.IsNull(badRequest2); // Put to return CSSPError because TVItemLanguageID of 0 does not exist tvItemLanguageRet.TVItemLanguageID = 0; IHttpActionResult jsonRet3 = tvItemLanguageController.Put(tvItemLanguageRet, LanguageRequest.ToString()); Assert.IsNotNull(jsonRet3); OkNegotiatedContentResult <TVItemLanguage> tvItemLanguageRet3 = jsonRet3 as OkNegotiatedContentResult <TVItemLanguage>; Assert.IsNull(tvItemLanguageRet3); BadRequestErrorMessageResult badRequest3 = jsonRet3 as BadRequestErrorMessageResult; Assert.IsNotNull(badRequest3); } } }
public void TVItemLanguage_Controller_GetTVItemLanguageWithID_Test() { foreach (LanguageEnum LanguageRequest in AllowableLanguages) { foreach (int ContactID in new List <int>() { AdminContactID }) //, TestEmailValidatedContactID, TestEmailNotValidatedContactID }) { TVItemLanguageController tvItemLanguageController = new TVItemLanguageController(DatabaseTypeEnum.SqlServerTestDB); Assert.IsNotNull(tvItemLanguageController); Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, tvItemLanguageController.DatabaseType); TVItemLanguage tvItemLanguageFirst = new TVItemLanguage(); using (CSSPDBContext db = new CSSPDBContext(DatabaseType)) { TVItemLanguageService tvItemLanguageService = new TVItemLanguageService(new Query(), db, ContactID); tvItemLanguageFirst = (from c in db.TVItemLanguages select c).FirstOrDefault(); } // ok with TVItemLanguage info IHttpActionResult jsonRet = tvItemLanguageController.GetTVItemLanguageWithID(tvItemLanguageFirst.TVItemLanguageID); Assert.IsNotNull(jsonRet); OkNegotiatedContentResult <TVItemLanguage> Ret = jsonRet as OkNegotiatedContentResult <TVItemLanguage>; TVItemLanguage tvItemLanguageRet = Ret.Content; Assert.AreEqual(tvItemLanguageFirst.TVItemLanguageID, tvItemLanguageRet.TVItemLanguageID); BadRequestErrorMessageResult badRequest = jsonRet as BadRequestErrorMessageResult; Assert.IsNull(badRequest); // Not Found IHttpActionResult jsonRet2 = tvItemLanguageController.GetTVItemLanguageWithID(0); Assert.IsNotNull(jsonRet2); OkNegotiatedContentResult <TVItemLanguage> tvItemLanguageRet2 = jsonRet2 as OkNegotiatedContentResult <TVItemLanguage>; Assert.IsNull(tvItemLanguageRet2); NotFoundResult notFoundRequest = jsonRet2 as NotFoundResult; Assert.IsNotNull(notFoundRequest); } } }
public void TVItemLanguage_Controller_Post_Test() { foreach (LanguageEnum LanguageRequest in AllowableLanguages) { foreach (int ContactID in new List <int>() { AdminContactID }) //, TestEmailValidatedContactID, TestEmailNotValidatedContactID }) { TVItemLanguageController tvItemLanguageController = new TVItemLanguageController(DatabaseTypeEnum.SqlServerTestDB); Assert.IsNotNull(tvItemLanguageController); Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, tvItemLanguageController.DatabaseType); TVItemLanguage tvItemLanguageLast = new TVItemLanguage(); using (CSSPDBContext db = new CSSPDBContext(DatabaseType)) { Query query = new Query(); query.Language = LanguageRequest; query.Asc = ""; query.Desc = ""; TVItemLanguageService tvItemLanguageService = new TVItemLanguageService(query, db, ContactID); tvItemLanguageLast = (from c in db.TVItemLanguages select c).FirstOrDefault(); } // ok with TVItemLanguage info IHttpActionResult jsonRet = tvItemLanguageController.GetTVItemLanguageWithID(tvItemLanguageLast.TVItemLanguageID); Assert.IsNotNull(jsonRet); OkNegotiatedContentResult <TVItemLanguage> Ret = jsonRet as OkNegotiatedContentResult <TVItemLanguage>; TVItemLanguage tvItemLanguageRet = Ret.Content; Assert.AreEqual(tvItemLanguageLast.TVItemLanguageID, tvItemLanguageRet.TVItemLanguageID); BadRequestErrorMessageResult badRequest = jsonRet as BadRequestErrorMessageResult; Assert.IsNull(badRequest); // Post to return CSSPError because TVItemLanguageID exist IHttpActionResult jsonRet2 = tvItemLanguageController.Post(tvItemLanguageRet, LanguageRequest.ToString()); Assert.IsNotNull(jsonRet2); OkNegotiatedContentResult <TVItemLanguage> tvItemLanguageRet2 = jsonRet2 as OkNegotiatedContentResult <TVItemLanguage>; Assert.IsNull(tvItemLanguageRet2); BadRequestErrorMessageResult badRequest2 = jsonRet2 as BadRequestErrorMessageResult; Assert.IsNotNull(badRequest2); // Post to return newly added TVItemLanguage tvItemLanguageRet.TVItemLanguageID = 0; tvItemLanguageController.Request = new System.Net.Http.HttpRequestMessage(); tvItemLanguageController.Request.RequestUri = new System.Uri("http://localhost:5000/api/tvItemLanguage"); IHttpActionResult jsonRet3 = tvItemLanguageController.Post(tvItemLanguageRet, LanguageRequest.ToString()); Assert.IsNotNull(jsonRet3); CreatedNegotiatedContentResult <TVItemLanguage> tvItemLanguageRet3 = jsonRet3 as CreatedNegotiatedContentResult <TVItemLanguage>; Assert.IsNotNull(tvItemLanguageRet3); BadRequestErrorMessageResult badRequest3 = jsonRet3 as BadRequestErrorMessageResult; Assert.IsNull(badRequest3); IHttpActionResult jsonRet4 = tvItemLanguageController.Delete(tvItemLanguageRet, LanguageRequest.ToString()); Assert.IsNotNull(jsonRet4); OkNegotiatedContentResult <TVItemLanguage> tvItemLanguageRet4 = jsonRet4 as OkNegotiatedContentResult <TVItemLanguage>; Assert.IsNotNull(tvItemLanguageRet4); BadRequestErrorMessageResult badRequest4 = jsonRet4 as BadRequestErrorMessageResult; Assert.IsNull(badRequest4); } } }