public void TVItemStat_Controller_Put_Test() { foreach (LanguageEnum LanguageRequest in AllowableLanguages) { foreach (int ContactID in new List <int>() { AdminContactID }) //, TestEmailValidatedContactID, TestEmailNotValidatedContactID }) { TVItemStatController tvItemStatController = new TVItemStatController(DatabaseTypeEnum.SqlServerTestDB); Assert.IsNotNull(tvItemStatController); Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, tvItemStatController.DatabaseType); TVItemStat tvItemStatLast = new TVItemStat(); using (CSSPDBContext db = new CSSPDBContext(DatabaseType)) { Query query = new Query(); query.Language = LanguageRequest; TVItemStatService tvItemStatService = new TVItemStatService(query, db, ContactID); tvItemStatLast = (from c in db.TVItemStats select c).FirstOrDefault(); } // ok with TVItemStat info IHttpActionResult jsonRet = tvItemStatController.GetTVItemStatWithID(tvItemStatLast.TVItemStatID); Assert.IsNotNull(jsonRet); OkNegotiatedContentResult <TVItemStat> Ret = jsonRet as OkNegotiatedContentResult <TVItemStat>; TVItemStat tvItemStatRet = Ret.Content; Assert.AreEqual(tvItemStatLast.TVItemStatID, tvItemStatRet.TVItemStatID); BadRequestErrorMessageResult badRequest = jsonRet as BadRequestErrorMessageResult; Assert.IsNull(badRequest); // Put to return success IHttpActionResult jsonRet2 = tvItemStatController.Put(tvItemStatRet, LanguageRequest.ToString()); Assert.IsNotNull(jsonRet2); OkNegotiatedContentResult <TVItemStat> tvItemStatRet2 = jsonRet2 as OkNegotiatedContentResult <TVItemStat>; Assert.IsNotNull(tvItemStatRet2); BadRequestErrorMessageResult badRequest2 = jsonRet2 as BadRequestErrorMessageResult; Assert.IsNull(badRequest2); // Put to return CSSPError because TVItemStatID of 0 does not exist tvItemStatRet.TVItemStatID = 0; IHttpActionResult jsonRet3 = tvItemStatController.Put(tvItemStatRet, LanguageRequest.ToString()); Assert.IsNotNull(jsonRet3); OkNegotiatedContentResult <TVItemStat> tvItemStatRet3 = jsonRet3 as OkNegotiatedContentResult <TVItemStat>; Assert.IsNull(tvItemStatRet3); BadRequestErrorMessageResult badRequest3 = jsonRet3 as BadRequestErrorMessageResult; Assert.IsNotNull(badRequest3); } } }
public void TVItemStat_Controller_GetTVItemStatWithID_Test() { foreach (LanguageEnum LanguageRequest in AllowableLanguages) { foreach (int ContactID in new List <int>() { AdminContactID }) //, TestEmailValidatedContactID, TestEmailNotValidatedContactID }) { TVItemStatController tvItemStatController = new TVItemStatController(DatabaseTypeEnum.SqlServerTestDB); Assert.IsNotNull(tvItemStatController); Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, tvItemStatController.DatabaseType); TVItemStat tvItemStatFirst = new TVItemStat(); using (CSSPDBContext db = new CSSPDBContext(DatabaseType)) { TVItemStatService tvItemStatService = new TVItemStatService(new Query(), db, ContactID); tvItemStatFirst = (from c in db.TVItemStats select c).FirstOrDefault(); } // ok with TVItemStat info IHttpActionResult jsonRet = tvItemStatController.GetTVItemStatWithID(tvItemStatFirst.TVItemStatID); Assert.IsNotNull(jsonRet); OkNegotiatedContentResult <TVItemStat> Ret = jsonRet as OkNegotiatedContentResult <TVItemStat>; TVItemStat tvItemStatRet = Ret.Content; Assert.AreEqual(tvItemStatFirst.TVItemStatID, tvItemStatRet.TVItemStatID); BadRequestErrorMessageResult badRequest = jsonRet as BadRequestErrorMessageResult; Assert.IsNull(badRequest); // Not Found IHttpActionResult jsonRet2 = tvItemStatController.GetTVItemStatWithID(0); Assert.IsNotNull(jsonRet2); OkNegotiatedContentResult <TVItemStat> tvItemStatRet2 = jsonRet2 as OkNegotiatedContentResult <TVItemStat>; Assert.IsNull(tvItemStatRet2); NotFoundResult notFoundRequest = jsonRet2 as NotFoundResult; Assert.IsNotNull(notFoundRequest); } } }
public void TVItemStat_Controller_Post_Test() { foreach (LanguageEnum LanguageRequest in AllowableLanguages) { foreach (int ContactID in new List <int>() { AdminContactID }) //, TestEmailValidatedContactID, TestEmailNotValidatedContactID }) { TVItemStatController tvItemStatController = new TVItemStatController(DatabaseTypeEnum.SqlServerTestDB); Assert.IsNotNull(tvItemStatController); Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, tvItemStatController.DatabaseType); TVItemStat tvItemStatLast = new TVItemStat(); using (CSSPDBContext db = new CSSPDBContext(DatabaseType)) { Query query = new Query(); query.Language = LanguageRequest; query.Asc = ""; query.Desc = ""; TVItemStatService tvItemStatService = new TVItemStatService(query, db, ContactID); tvItemStatLast = (from c in db.TVItemStats select c).FirstOrDefault(); } // ok with TVItemStat info IHttpActionResult jsonRet = tvItemStatController.GetTVItemStatWithID(tvItemStatLast.TVItemStatID); Assert.IsNotNull(jsonRet); OkNegotiatedContentResult <TVItemStat> Ret = jsonRet as OkNegotiatedContentResult <TVItemStat>; TVItemStat tvItemStatRet = Ret.Content; Assert.AreEqual(tvItemStatLast.TVItemStatID, tvItemStatRet.TVItemStatID); BadRequestErrorMessageResult badRequest = jsonRet as BadRequestErrorMessageResult; Assert.IsNull(badRequest); // Post to return CSSPError because TVItemStatID exist IHttpActionResult jsonRet2 = tvItemStatController.Post(tvItemStatRet, LanguageRequest.ToString()); Assert.IsNotNull(jsonRet2); OkNegotiatedContentResult <TVItemStat> tvItemStatRet2 = jsonRet2 as OkNegotiatedContentResult <TVItemStat>; Assert.IsNull(tvItemStatRet2); BadRequestErrorMessageResult badRequest2 = jsonRet2 as BadRequestErrorMessageResult; Assert.IsNotNull(badRequest2); // Post to return newly added TVItemStat tvItemStatRet.TVItemStatID = 0; tvItemStatController.Request = new System.Net.Http.HttpRequestMessage(); tvItemStatController.Request.RequestUri = new System.Uri("http://localhost:5000/api/tvItemStat"); IHttpActionResult jsonRet3 = tvItemStatController.Post(tvItemStatRet, LanguageRequest.ToString()); Assert.IsNotNull(jsonRet3); CreatedNegotiatedContentResult <TVItemStat> tvItemStatRet3 = jsonRet3 as CreatedNegotiatedContentResult <TVItemStat>; Assert.IsNotNull(tvItemStatRet3); BadRequestErrorMessageResult badRequest3 = jsonRet3 as BadRequestErrorMessageResult; Assert.IsNull(badRequest3); IHttpActionResult jsonRet4 = tvItemStatController.Delete(tvItemStatRet, LanguageRequest.ToString()); Assert.IsNotNull(jsonRet4); OkNegotiatedContentResult <TVItemStat> tvItemStatRet4 = jsonRet4 as OkNegotiatedContentResult <TVItemStat>; Assert.IsNotNull(tvItemStatRet4); BadRequestErrorMessageResult badRequest4 = jsonRet4 as BadRequestErrorMessageResult; Assert.IsNull(badRequest4); } } }