コード例 #1
0
        public void MWQMRun_Controller_Put_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    MWQMRunController mwqmRunController = new MWQMRunController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(mwqmRunController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, mwqmRunController.DatabaseType);

                    MWQMRun mwqmRunLast = new MWQMRun();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
                    {
                        Query query = new Query();
                        query.Language = LanguageRequest;

                        MWQMRunService mwqmRunService = new MWQMRunService(query, db, ContactID);
                        mwqmRunLast = (from c in db.MWQMRuns select c).FirstOrDefault();
                    }

                    // ok with MWQMRun info
                    IHttpActionResult jsonRet = mwqmRunController.GetMWQMRunWithID(mwqmRunLast.MWQMRunID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <MWQMRun> Ret = jsonRet as OkNegotiatedContentResult <MWQMRun>;
                    MWQMRun mwqmRunRet = Ret.Content;
                    Assert.AreEqual(mwqmRunLast.MWQMRunID, mwqmRunRet.MWQMRunID);

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

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

                    OkNegotiatedContentResult <MWQMRun> mwqmRunRet2 = jsonRet2 as OkNegotiatedContentResult <MWQMRun>;
                    Assert.IsNotNull(mwqmRunRet2);

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

                    // Put to return CSSPError because MWQMRunID of 0 does not exist
                    mwqmRunRet.MWQMRunID = 0;
                    IHttpActionResult jsonRet3 = mwqmRunController.Put(mwqmRunRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet3);

                    OkNegotiatedContentResult <MWQMRun> mwqmRunRet3 = jsonRet3 as OkNegotiatedContentResult <MWQMRun>;
                    Assert.IsNull(mwqmRunRet3);

                    BadRequestErrorMessageResult badRequest3 = jsonRet3 as BadRequestErrorMessageResult;
                    Assert.IsNotNull(badRequest3);
                }
            }
        }
コード例 #2
0
        public void MWQMRun_Controller_GetMWQMRunWithID_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    MWQMRunController mwqmRunController = new MWQMRunController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(mwqmRunController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, mwqmRunController.DatabaseType);

                    MWQMRun mwqmRunFirst = new MWQMRun();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
                    {
                        MWQMRunService mwqmRunService = new MWQMRunService(new Query(), db, ContactID);
                        mwqmRunFirst = (from c in db.MWQMRuns select c).FirstOrDefault();
                    }

                    // ok with MWQMRun info
                    IHttpActionResult jsonRet = mwqmRunController.GetMWQMRunWithID(mwqmRunFirst.MWQMRunID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <MWQMRun> Ret = jsonRet as OkNegotiatedContentResult <MWQMRun>;
                    MWQMRun mwqmRunRet = Ret.Content;
                    Assert.AreEqual(mwqmRunFirst.MWQMRunID, mwqmRunRet.MWQMRunID);

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

                    // Not Found
                    IHttpActionResult jsonRet2 = mwqmRunController.GetMWQMRunWithID(0);
                    Assert.IsNotNull(jsonRet2);

                    OkNegotiatedContentResult <MWQMRun> mwqmRunRet2 = jsonRet2 as OkNegotiatedContentResult <MWQMRun>;
                    Assert.IsNull(mwqmRunRet2);

                    NotFoundResult notFoundRequest = jsonRet2 as NotFoundResult;
                    Assert.IsNotNull(notFoundRequest);
                }
            }
        }
コード例 #3
0
        public void MWQMRun_Controller_Post_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    MWQMRunController mwqmRunController = new MWQMRunController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(mwqmRunController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, mwqmRunController.DatabaseType);

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

                        MWQMRunService mwqmRunService = new MWQMRunService(query, db, ContactID);
                        mwqmRunLast = (from c in db.MWQMRuns select c).FirstOrDefault();
                    }

                    // ok with MWQMRun info
                    IHttpActionResult jsonRet = mwqmRunController.GetMWQMRunWithID(mwqmRunLast.MWQMRunID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <MWQMRun> Ret = jsonRet as OkNegotiatedContentResult <MWQMRun>;
                    MWQMRun mwqmRunRet = Ret.Content;
                    Assert.AreEqual(mwqmRunLast.MWQMRunID, mwqmRunRet.MWQMRunID);

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

                    // Post to return CSSPError because MWQMRunID exist
                    IHttpActionResult jsonRet2 = mwqmRunController.Post(mwqmRunRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet2);

                    OkNegotiatedContentResult <MWQMRun> mwqmRunRet2 = jsonRet2 as OkNegotiatedContentResult <MWQMRun>;
                    Assert.IsNull(mwqmRunRet2);

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

                    // Post to return newly added MWQMRun
                    mwqmRunRet.MWQMRunID                 = 0;
                    mwqmRunController.Request            = new System.Net.Http.HttpRequestMessage();
                    mwqmRunController.Request.RequestUri = new System.Uri("http://localhost:5000/api/mwqmRun");
                    IHttpActionResult jsonRet3 = mwqmRunController.Post(mwqmRunRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet3);

                    CreatedNegotiatedContentResult <MWQMRun> mwqmRunRet3 = jsonRet3 as CreatedNegotiatedContentResult <MWQMRun>;
                    Assert.IsNotNull(mwqmRunRet3);

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

                    IHttpActionResult jsonRet4 = mwqmRunController.Delete(mwqmRunRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet4);

                    OkNegotiatedContentResult <MWQMRun> mwqmRunRet4 = jsonRet4 as OkNegotiatedContentResult <MWQMRun>;
                    Assert.IsNotNull(mwqmRunRet4);

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