예제 #1
0
        public void UseOfSite_Controller_Put_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    UseOfSiteController useOfSiteController = new UseOfSiteController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(useOfSiteController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, useOfSiteController.DatabaseType);

                    UseOfSite useOfSiteLast = new UseOfSite();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
                    {
                        Query query = new Query();
                        query.Language = LanguageRequest;

                        UseOfSiteService useOfSiteService = new UseOfSiteService(query, db, ContactID);
                        useOfSiteLast = (from c in db.UseOfSites select c).FirstOrDefault();
                    }

                    // ok with UseOfSite info
                    IHttpActionResult jsonRet = useOfSiteController.GetUseOfSiteWithID(useOfSiteLast.UseOfSiteID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <UseOfSite> Ret = jsonRet as OkNegotiatedContentResult <UseOfSite>;
                    UseOfSite useOfSiteRet = Ret.Content;
                    Assert.AreEqual(useOfSiteLast.UseOfSiteID, useOfSiteRet.UseOfSiteID);

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

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

                    OkNegotiatedContentResult <UseOfSite> useOfSiteRet2 = jsonRet2 as OkNegotiatedContentResult <UseOfSite>;
                    Assert.IsNotNull(useOfSiteRet2);

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

                    // Put to return CSSPError because UseOfSiteID of 0 does not exist
                    useOfSiteRet.UseOfSiteID = 0;
                    IHttpActionResult jsonRet3 = useOfSiteController.Put(useOfSiteRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet3);

                    OkNegotiatedContentResult <UseOfSite> useOfSiteRet3 = jsonRet3 as OkNegotiatedContentResult <UseOfSite>;
                    Assert.IsNull(useOfSiteRet3);

                    BadRequestErrorMessageResult badRequest3 = jsonRet3 as BadRequestErrorMessageResult;
                    Assert.IsNotNull(badRequest3);
                }
            }
        }
예제 #2
0
        public void UseOfSite_Controller_GetUseOfSiteWithID_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    UseOfSiteController useOfSiteController = new UseOfSiteController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(useOfSiteController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, useOfSiteController.DatabaseType);

                    UseOfSite useOfSiteFirst = new UseOfSite();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
                    {
                        UseOfSiteService useOfSiteService = new UseOfSiteService(new Query(), db, ContactID);
                        useOfSiteFirst = (from c in db.UseOfSites select c).FirstOrDefault();
                    }

                    // ok with UseOfSite info
                    IHttpActionResult jsonRet = useOfSiteController.GetUseOfSiteWithID(useOfSiteFirst.UseOfSiteID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <UseOfSite> Ret = jsonRet as OkNegotiatedContentResult <UseOfSite>;
                    UseOfSite useOfSiteRet = Ret.Content;
                    Assert.AreEqual(useOfSiteFirst.UseOfSiteID, useOfSiteRet.UseOfSiteID);

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

                    // Not Found
                    IHttpActionResult jsonRet2 = useOfSiteController.GetUseOfSiteWithID(0);
                    Assert.IsNotNull(jsonRet2);

                    OkNegotiatedContentResult <UseOfSite> useOfSiteRet2 = jsonRet2 as OkNegotiatedContentResult <UseOfSite>;
                    Assert.IsNull(useOfSiteRet2);

                    NotFoundResult notFoundRequest = jsonRet2 as NotFoundResult;
                    Assert.IsNotNull(notFoundRequest);
                }
            }
        }
예제 #3
0
        public void UseOfSite_Controller_Post_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    UseOfSiteController useOfSiteController = new UseOfSiteController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(useOfSiteController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, useOfSiteController.DatabaseType);

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

                        UseOfSiteService useOfSiteService = new UseOfSiteService(query, db, ContactID);
                        useOfSiteLast = (from c in db.UseOfSites select c).FirstOrDefault();
                    }

                    // ok with UseOfSite info
                    IHttpActionResult jsonRet = useOfSiteController.GetUseOfSiteWithID(useOfSiteLast.UseOfSiteID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <UseOfSite> Ret = jsonRet as OkNegotiatedContentResult <UseOfSite>;
                    UseOfSite useOfSiteRet = Ret.Content;
                    Assert.AreEqual(useOfSiteLast.UseOfSiteID, useOfSiteRet.UseOfSiteID);

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

                    // Post to return CSSPError because UseOfSiteID exist
                    IHttpActionResult jsonRet2 = useOfSiteController.Post(useOfSiteRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet2);

                    OkNegotiatedContentResult <UseOfSite> useOfSiteRet2 = jsonRet2 as OkNegotiatedContentResult <UseOfSite>;
                    Assert.IsNull(useOfSiteRet2);

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

                    // Post to return newly added UseOfSite
                    useOfSiteRet.UseOfSiteID               = 0;
                    useOfSiteController.Request            = new System.Net.Http.HttpRequestMessage();
                    useOfSiteController.Request.RequestUri = new System.Uri("http://localhost:5000/api/useOfSite");
                    IHttpActionResult jsonRet3 = useOfSiteController.Post(useOfSiteRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet3);

                    CreatedNegotiatedContentResult <UseOfSite> useOfSiteRet3 = jsonRet3 as CreatedNegotiatedContentResult <UseOfSite>;
                    Assert.IsNotNull(useOfSiteRet3);

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

                    IHttpActionResult jsonRet4 = useOfSiteController.Delete(useOfSiteRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet4);

                    OkNegotiatedContentResult <UseOfSite> useOfSiteRet4 = jsonRet4 as OkNegotiatedContentResult <UseOfSite>;
                    Assert.IsNotNull(useOfSiteRet4);

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