public void TVItem_Controller_Delete_Test() { foreach (LanguageEnum LanguageRequest in AllowableLanguages) { foreach (int ContactID in new List <int>() { AdminContactID }) //, TestEmailValidatedContactID, TestEmailNotValidatedContactID }) { TVItemController tvItemController = new TVItemController(DatabaseTypeEnum.SqlServerTestDB); Assert.IsNotNull(tvItemController); Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, tvItemController.DatabaseType); TVItem tvItemLast = new TVItem(); using (CSSPDBContext db = new CSSPDBContext(DatabaseType)) { Query query = new Query(); query.Language = LanguageRequest; query.Asc = ""; query.Desc = ""; TVItemService tvItemService = new TVItemService(query, db, ContactID); tvItemLast = (from c in db.TVItems select c).FirstOrDefault(); } // ok with TVItem info IHttpActionResult jsonRet = tvItemController.GetTVItemWithID(tvItemLast.TVItemID); Assert.IsNotNull(jsonRet); OkNegotiatedContentResult <TVItem> Ret = jsonRet as OkNegotiatedContentResult <TVItem>; TVItem tvItemRet = Ret.Content; Assert.AreEqual(tvItemLast.TVItemID, tvItemRet.TVItemID); BadRequestErrorMessageResult badRequest = jsonRet as BadRequestErrorMessageResult; Assert.IsNull(badRequest); // Post to return newly added TVItem tvItemRet.TVItemID = 0; tvItemRet.TVLevel = 1; tvItemRet.TVType = TVTypeEnum.Contact; tvItemController.Request = new System.Net.Http.HttpRequestMessage(); tvItemController.Request.RequestUri = new System.Uri("http://localhost:5000/api/tvItem"); IHttpActionResult jsonRet3 = tvItemController.Post(tvItemRet, LanguageRequest.ToString()); Assert.IsNotNull(jsonRet3); CreatedNegotiatedContentResult <TVItem> tvItemRet3 = jsonRet3 as CreatedNegotiatedContentResult <TVItem>; Assert.IsNotNull(tvItemRet3); TVItem tvItem = tvItemRet3.Content; BadRequestErrorMessageResult badRequest3 = jsonRet3 as BadRequestErrorMessageResult; Assert.IsNull(badRequest3); // Delete to return success IHttpActionResult jsonRet2 = tvItemController.Delete(tvItemRet, LanguageRequest.ToString()); Assert.IsNotNull(jsonRet2); OkNegotiatedContentResult <TVItem> tvItemRet2 = jsonRet2 as OkNegotiatedContentResult <TVItem>; Assert.IsNotNull(tvItemRet2); BadRequestErrorMessageResult badRequest2 = jsonRet2 as BadRequestErrorMessageResult; Assert.IsNull(badRequest2); // Delete to return CSSPError because TVItemID of 0 does not exist tvItemRet.TVItemID = 0; IHttpActionResult jsonRet4 = tvItemController.Delete(tvItemRet, LanguageRequest.ToString()); Assert.IsNotNull(jsonRet4); OkNegotiatedContentResult <TVItem> tvItemRet4 = jsonRet4 as OkNegotiatedContentResult <TVItem>; Assert.IsNull(tvItemRet4); BadRequestErrorMessageResult badRequest4 = jsonRet4 as BadRequestErrorMessageResult; Assert.IsNotNull(badRequest4); } } }