示例#1
0
        public void VPResult_Controller_Put_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    VPResultController vpResultController = new VPResultController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(vpResultController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, vpResultController.DatabaseType);

                    VPResult vpResultLast = new VPResult();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
                    {
                        Query query = new Query();
                        query.Language = LanguageRequest;

                        VPResultService vpResultService = new VPResultService(query, db, ContactID);
                        vpResultLast = (from c in db.VPResults select c).FirstOrDefault();
                    }

                    // ok with VPResult info
                    IHttpActionResult jsonRet = vpResultController.GetVPResultWithID(vpResultLast.VPResultID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <VPResult> Ret = jsonRet as OkNegotiatedContentResult <VPResult>;
                    VPResult vpResultRet = Ret.Content;
                    Assert.AreEqual(vpResultLast.VPResultID, vpResultRet.VPResultID);

                    BadRequestErrorMessageResult badRequest = jsonRet as BadRequestErrorMessageResult;
                    Assert.IsNull(badRequest);

                    // Put to return success
                    IHttpActionResult jsonRet2 = vpResultController.Put(vpResultRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet2);

                    OkNegotiatedContentResult <VPResult> vpResultRet2 = jsonRet2 as OkNegotiatedContentResult <VPResult>;
                    Assert.IsNotNull(vpResultRet2);

                    BadRequestErrorMessageResult badRequest2 = jsonRet2 as BadRequestErrorMessageResult;
                    Assert.IsNull(badRequest2);

                    // Put to return CSSPError because VPResultID of 0 does not exist
                    vpResultRet.VPResultID = 0;
                    IHttpActionResult jsonRet3 = vpResultController.Put(vpResultRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet3);

                    OkNegotiatedContentResult <VPResult> vpResultRet3 = jsonRet3 as OkNegotiatedContentResult <VPResult>;
                    Assert.IsNull(vpResultRet3);

                    BadRequestErrorMessageResult badRequest3 = jsonRet3 as BadRequestErrorMessageResult;
                    Assert.IsNotNull(badRequest3);
                }
            }
        }
示例#2
0
        public void VPResult_Controller_GetVPResultWithID_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    VPResultController vpResultController = new VPResultController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(vpResultController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, vpResultController.DatabaseType);

                    VPResult vpResultFirst = new VPResult();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
                    {
                        VPResultService vpResultService = new VPResultService(new Query(), db, ContactID);
                        vpResultFirst = (from c in db.VPResults select c).FirstOrDefault();
                    }

                    // ok with VPResult info
                    IHttpActionResult jsonRet = vpResultController.GetVPResultWithID(vpResultFirst.VPResultID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <VPResult> Ret = jsonRet as OkNegotiatedContentResult <VPResult>;
                    VPResult vpResultRet = Ret.Content;
                    Assert.AreEqual(vpResultFirst.VPResultID, vpResultRet.VPResultID);

                    BadRequestErrorMessageResult badRequest = jsonRet as BadRequestErrorMessageResult;
                    Assert.IsNull(badRequest);

                    // Not Found
                    IHttpActionResult jsonRet2 = vpResultController.GetVPResultWithID(0);
                    Assert.IsNotNull(jsonRet2);

                    OkNegotiatedContentResult <VPResult> vpResultRet2 = jsonRet2 as OkNegotiatedContentResult <VPResult>;
                    Assert.IsNull(vpResultRet2);

                    NotFoundResult notFoundRequest = jsonRet2 as NotFoundResult;
                    Assert.IsNotNull(notFoundRequest);
                }
            }
        }
示例#3
0
        public void VPResult_Controller_Post_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    VPResultController vpResultController = new VPResultController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(vpResultController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, vpResultController.DatabaseType);

                    VPResult vpResultLast = new VPResult();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
                    {
                        Query query = new Query();
                        query.Language = LanguageRequest;
                        query.Asc      = "";
                        query.Desc     = "";

                        VPResultService vpResultService = new VPResultService(query, db, ContactID);
                        vpResultLast = (from c in db.VPResults select c).FirstOrDefault();
                    }

                    // ok with VPResult info
                    IHttpActionResult jsonRet = vpResultController.GetVPResultWithID(vpResultLast.VPResultID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <VPResult> Ret = jsonRet as OkNegotiatedContentResult <VPResult>;
                    VPResult vpResultRet = Ret.Content;
                    Assert.AreEqual(vpResultLast.VPResultID, vpResultRet.VPResultID);

                    BadRequestErrorMessageResult badRequest = jsonRet as BadRequestErrorMessageResult;
                    Assert.IsNull(badRequest);

                    // Post to return CSSPError because VPResultID exist
                    IHttpActionResult jsonRet2 = vpResultController.Post(vpResultRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet2);

                    OkNegotiatedContentResult <VPResult> vpResultRet2 = jsonRet2 as OkNegotiatedContentResult <VPResult>;
                    Assert.IsNull(vpResultRet2);

                    BadRequestErrorMessageResult badRequest2 = jsonRet2 as BadRequestErrorMessageResult;
                    Assert.IsNotNull(badRequest2);

                    // Post to return newly added VPResult
                    vpResultRet.VPResultID                = 0;
                    vpResultController.Request            = new System.Net.Http.HttpRequestMessage();
                    vpResultController.Request.RequestUri = new System.Uri("http://localhost:5000/api/vpResult");
                    IHttpActionResult jsonRet3 = vpResultController.Post(vpResultRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet3);

                    CreatedNegotiatedContentResult <VPResult> vpResultRet3 = jsonRet3 as CreatedNegotiatedContentResult <VPResult>;
                    Assert.IsNotNull(vpResultRet3);

                    BadRequestErrorMessageResult badRequest3 = jsonRet3 as BadRequestErrorMessageResult;
                    Assert.IsNull(badRequest3);

                    IHttpActionResult jsonRet4 = vpResultController.Delete(vpResultRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet4);

                    OkNegotiatedContentResult <VPResult> vpResultRet4 = jsonRet4 as OkNegotiatedContentResult <VPResult>;
                    Assert.IsNotNull(vpResultRet4);

                    BadRequestErrorMessageResult badRequest4 = jsonRet4 as BadRequestErrorMessageResult;
                    Assert.IsNull(badRequest4);
                }
            }
        }