public void PolSourceObservation_Controller_Put_Test() { foreach (LanguageEnum LanguageRequest in AllowableLanguages) { foreach (int ContactID in new List <int>() { AdminContactID }) //, TestEmailValidatedContactID, TestEmailNotValidatedContactID }) { PolSourceObservationController polSourceObservationController = new PolSourceObservationController(DatabaseTypeEnum.SqlServerTestDB); Assert.IsNotNull(polSourceObservationController); Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, polSourceObservationController.DatabaseType); PolSourceObservation polSourceObservationLast = new PolSourceObservation(); using (CSSPDBContext db = new CSSPDBContext(DatabaseType)) { Query query = new Query(); query.Language = LanguageRequest; PolSourceObservationService polSourceObservationService = new PolSourceObservationService(query, db, ContactID); polSourceObservationLast = (from c in db.PolSourceObservations select c).FirstOrDefault(); } // ok with PolSourceObservation info IHttpActionResult jsonRet = polSourceObservationController.GetPolSourceObservationWithID(polSourceObservationLast.PolSourceObservationID); Assert.IsNotNull(jsonRet); OkNegotiatedContentResult <PolSourceObservation> Ret = jsonRet as OkNegotiatedContentResult <PolSourceObservation>; PolSourceObservation polSourceObservationRet = Ret.Content; Assert.AreEqual(polSourceObservationLast.PolSourceObservationID, polSourceObservationRet.PolSourceObservationID); BadRequestErrorMessageResult badRequest = jsonRet as BadRequestErrorMessageResult; Assert.IsNull(badRequest); // Put to return success IHttpActionResult jsonRet2 = polSourceObservationController.Put(polSourceObservationRet, LanguageRequest.ToString()); Assert.IsNotNull(jsonRet2); OkNegotiatedContentResult <PolSourceObservation> polSourceObservationRet2 = jsonRet2 as OkNegotiatedContentResult <PolSourceObservation>; Assert.IsNotNull(polSourceObservationRet2); BadRequestErrorMessageResult badRequest2 = jsonRet2 as BadRequestErrorMessageResult; Assert.IsNull(badRequest2); // Put to return CSSPError because PolSourceObservationID of 0 does not exist polSourceObservationRet.PolSourceObservationID = 0; IHttpActionResult jsonRet3 = polSourceObservationController.Put(polSourceObservationRet, LanguageRequest.ToString()); Assert.IsNotNull(jsonRet3); OkNegotiatedContentResult <PolSourceObservation> polSourceObservationRet3 = jsonRet3 as OkNegotiatedContentResult <PolSourceObservation>; Assert.IsNull(polSourceObservationRet3); BadRequestErrorMessageResult badRequest3 = jsonRet3 as BadRequestErrorMessageResult; Assert.IsNotNull(badRequest3); } } }
public void PolSourceObservation_Controller_GetPolSourceObservationWithID_Test() { foreach (LanguageEnum LanguageRequest in AllowableLanguages) { foreach (int ContactID in new List <int>() { AdminContactID }) //, TestEmailValidatedContactID, TestEmailNotValidatedContactID }) { PolSourceObservationController polSourceObservationController = new PolSourceObservationController(DatabaseTypeEnum.SqlServerTestDB); Assert.IsNotNull(polSourceObservationController); Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, polSourceObservationController.DatabaseType); PolSourceObservation polSourceObservationFirst = new PolSourceObservation(); using (CSSPDBContext db = new CSSPDBContext(DatabaseType)) { PolSourceObservationService polSourceObservationService = new PolSourceObservationService(new Query(), db, ContactID); polSourceObservationFirst = (from c in db.PolSourceObservations select c).FirstOrDefault(); } // ok with PolSourceObservation info IHttpActionResult jsonRet = polSourceObservationController.GetPolSourceObservationWithID(polSourceObservationFirst.PolSourceObservationID); Assert.IsNotNull(jsonRet); OkNegotiatedContentResult <PolSourceObservation> Ret = jsonRet as OkNegotiatedContentResult <PolSourceObservation>; PolSourceObservation polSourceObservationRet = Ret.Content; Assert.AreEqual(polSourceObservationFirst.PolSourceObservationID, polSourceObservationRet.PolSourceObservationID); BadRequestErrorMessageResult badRequest = jsonRet as BadRequestErrorMessageResult; Assert.IsNull(badRequest); // Not Found IHttpActionResult jsonRet2 = polSourceObservationController.GetPolSourceObservationWithID(0); Assert.IsNotNull(jsonRet2); OkNegotiatedContentResult <PolSourceObservation> polSourceObservationRet2 = jsonRet2 as OkNegotiatedContentResult <PolSourceObservation>; Assert.IsNull(polSourceObservationRet2); NotFoundResult notFoundRequest = jsonRet2 as NotFoundResult; Assert.IsNotNull(notFoundRequest); } } }
public void PolSourceObservation_Controller_Post_Test() { foreach (LanguageEnum LanguageRequest in AllowableLanguages) { foreach (int ContactID in new List <int>() { AdminContactID }) //, TestEmailValidatedContactID, TestEmailNotValidatedContactID }) { PolSourceObservationController polSourceObservationController = new PolSourceObservationController(DatabaseTypeEnum.SqlServerTestDB); Assert.IsNotNull(polSourceObservationController); Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, polSourceObservationController.DatabaseType); PolSourceObservation polSourceObservationLast = new PolSourceObservation(); using (CSSPDBContext db = new CSSPDBContext(DatabaseType)) { Query query = new Query(); query.Language = LanguageRequest; query.Asc = ""; query.Desc = ""; PolSourceObservationService polSourceObservationService = new PolSourceObservationService(query, db, ContactID); polSourceObservationLast = (from c in db.PolSourceObservations select c).FirstOrDefault(); } // ok with PolSourceObservation info IHttpActionResult jsonRet = polSourceObservationController.GetPolSourceObservationWithID(polSourceObservationLast.PolSourceObservationID); Assert.IsNotNull(jsonRet); OkNegotiatedContentResult <PolSourceObservation> Ret = jsonRet as OkNegotiatedContentResult <PolSourceObservation>; PolSourceObservation polSourceObservationRet = Ret.Content; Assert.AreEqual(polSourceObservationLast.PolSourceObservationID, polSourceObservationRet.PolSourceObservationID); BadRequestErrorMessageResult badRequest = jsonRet as BadRequestErrorMessageResult; Assert.IsNull(badRequest); // Post to return CSSPError because PolSourceObservationID exist IHttpActionResult jsonRet2 = polSourceObservationController.Post(polSourceObservationRet, LanguageRequest.ToString()); Assert.IsNotNull(jsonRet2); OkNegotiatedContentResult <PolSourceObservation> polSourceObservationRet2 = jsonRet2 as OkNegotiatedContentResult <PolSourceObservation>; Assert.IsNull(polSourceObservationRet2); BadRequestErrorMessageResult badRequest2 = jsonRet2 as BadRequestErrorMessageResult; Assert.IsNotNull(badRequest2); // Post to return newly added PolSourceObservation polSourceObservationRet.PolSourceObservationID = 0; polSourceObservationController.Request = new System.Net.Http.HttpRequestMessage(); polSourceObservationController.Request.RequestUri = new System.Uri("http://localhost:5000/api/polSourceObservation"); IHttpActionResult jsonRet3 = polSourceObservationController.Post(polSourceObservationRet, LanguageRequest.ToString()); Assert.IsNotNull(jsonRet3); CreatedNegotiatedContentResult <PolSourceObservation> polSourceObservationRet3 = jsonRet3 as CreatedNegotiatedContentResult <PolSourceObservation>; Assert.IsNotNull(polSourceObservationRet3); BadRequestErrorMessageResult badRequest3 = jsonRet3 as BadRequestErrorMessageResult; Assert.IsNull(badRequest3); IHttpActionResult jsonRet4 = polSourceObservationController.Delete(polSourceObservationRet, LanguageRequest.ToString()); Assert.IsNotNull(jsonRet4); OkNegotiatedContentResult <PolSourceObservation> polSourceObservationRet4 = jsonRet4 as OkNegotiatedContentResult <PolSourceObservation>; Assert.IsNotNull(polSourceObservationRet4); BadRequestErrorMessageResult badRequest4 = jsonRet4 as BadRequestErrorMessageResult; Assert.IsNull(badRequest4); } } }