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

                    TVItemStat tvItemStatLast = new TVItemStat();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
                    {
                        Query query = new Query();
                        query.Language = LanguageRequest;

                        TVItemStatService tvItemStatService = new TVItemStatService(query, db, ContactID);
                        tvItemStatLast = (from c in db.TVItemStats select c).FirstOrDefault();
                    }

                    // ok with TVItemStat info
                    IHttpActionResult jsonRet = tvItemStatController.GetTVItemStatWithID(tvItemStatLast.TVItemStatID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <TVItemStat> Ret = jsonRet as OkNegotiatedContentResult <TVItemStat>;
                    TVItemStat tvItemStatRet = Ret.Content;
                    Assert.AreEqual(tvItemStatLast.TVItemStatID, tvItemStatRet.TVItemStatID);

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

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

                    OkNegotiatedContentResult <TVItemStat> tvItemStatRet2 = jsonRet2 as OkNegotiatedContentResult <TVItemStat>;
                    Assert.IsNotNull(tvItemStatRet2);

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

                    // Put to return CSSPError because TVItemStatID of 0 does not exist
                    tvItemStatRet.TVItemStatID = 0;
                    IHttpActionResult jsonRet3 = tvItemStatController.Put(tvItemStatRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet3);

                    OkNegotiatedContentResult <TVItemStat> tvItemStatRet3 = jsonRet3 as OkNegotiatedContentResult <TVItemStat>;
                    Assert.IsNull(tvItemStatRet3);

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

                    TVItemStat tvItemStatFirst = new TVItemStat();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
                    {
                        TVItemStatService tvItemStatService = new TVItemStatService(new Query(), db, ContactID);
                        tvItemStatFirst = (from c in db.TVItemStats select c).FirstOrDefault();
                    }

                    // ok with TVItemStat info
                    IHttpActionResult jsonRet = tvItemStatController.GetTVItemStatWithID(tvItemStatFirst.TVItemStatID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <TVItemStat> Ret = jsonRet as OkNegotiatedContentResult <TVItemStat>;
                    TVItemStat tvItemStatRet = Ret.Content;
                    Assert.AreEqual(tvItemStatFirst.TVItemStatID, tvItemStatRet.TVItemStatID);

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

                    // Not Found
                    IHttpActionResult jsonRet2 = tvItemStatController.GetTVItemStatWithID(0);
                    Assert.IsNotNull(jsonRet2);

                    OkNegotiatedContentResult <TVItemStat> tvItemStatRet2 = jsonRet2 as OkNegotiatedContentResult <TVItemStat>;
                    Assert.IsNull(tvItemStatRet2);

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

                    TVItemStat tvItemStatFirst = new TVItemStat();
                    int        count           = -1;
                    Query      query           = new Query();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                    {
                        TVItemStatService tvItemStatService = new TVItemStatService(query, db, ContactID);
                        tvItemStatFirst = (from c in db.TVItemStats select c).FirstOrDefault();
                        count           = (from c in db.TVItemStats select c).Count();
                        count           = (query.Take > count ? count : query.Take);
                    }

                    // ok with TVItemStat info
                    IHttpActionResult jsonRet = tvItemStatController.GetTVItemStatList();
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <List <TVItemStat> > ret = jsonRet as OkNegotiatedContentResult <List <TVItemStat> >;
                    Assert.AreEqual(tvItemStatFirst.TVItemStatID, ret.Content[0].TVItemStatID);
                    Assert.AreEqual((count > query.Take ? query.Take : count), ret.Content.Count);

                    List <TVItemStat> tvItemStatList = new List <TVItemStat>();
                    count = -1;
                    query = new Query();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                    {
                        TVItemStatService tvItemStatService = new TVItemStatService(query, db, ContactID);
                        tvItemStatList = (from c in db.TVItemStats select c).OrderBy(c => c.TVItemStatID).Skip(0).Take(2).ToList();
                        count          = (from c in db.TVItemStats select c).Count();
                    }

                    if (count > 0)
                    {
                        query.Skip = 0;
                        query.Take = 5;
                        count      = (query.Take > count ? query.Take : count);

                        // ok with TVItemStat info
                        jsonRet = tvItemStatController.GetTVItemStatList(query.Language.ToString(), query.Skip, query.Take);
                        Assert.IsNotNull(jsonRet);

                        ret = jsonRet as OkNegotiatedContentResult <List <TVItemStat> >;
                        Assert.AreEqual(tvItemStatList[0].TVItemStatID, ret.Content[0].TVItemStatID);
                        Assert.AreEqual((count > query.Take ? query.Take : count), ret.Content.Count);

                        if (count > 1)
                        {
                            query.Skip = 1;
                            query.Take = 5;
                            count      = (query.Take > count ? query.Take : count);

                            // ok with TVItemStat info
                            IHttpActionResult jsonRet2 = tvItemStatController.GetTVItemStatList(query.Language.ToString(), query.Skip, query.Take);
                            Assert.IsNotNull(jsonRet2);

                            OkNegotiatedContentResult <List <TVItemStat> > ret2 = jsonRet2 as OkNegotiatedContentResult <List <TVItemStat> >;
                            Assert.AreEqual(tvItemStatList[1].TVItemStatID, ret2.Content[0].TVItemStatID);
                            Assert.AreEqual((count > query.Take ? query.Take : count), ret2.Content.Count);
                        }
                    }
                }
            }
        }
示例#4
0
        public void TVItemStat_Controller_Post_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    TVItemStatController tvItemStatController = new TVItemStatController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(tvItemStatController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, tvItemStatController.DatabaseType);

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

                        TVItemStatService tvItemStatService = new TVItemStatService(query, db, ContactID);
                        tvItemStatLast = (from c in db.TVItemStats select c).FirstOrDefault();
                    }

                    // ok with TVItemStat info
                    IHttpActionResult jsonRet = tvItemStatController.GetTVItemStatWithID(tvItemStatLast.TVItemStatID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <TVItemStat> Ret = jsonRet as OkNegotiatedContentResult <TVItemStat>;
                    TVItemStat tvItemStatRet = Ret.Content;
                    Assert.AreEqual(tvItemStatLast.TVItemStatID, tvItemStatRet.TVItemStatID);

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

                    // Post to return CSSPError because TVItemStatID exist
                    IHttpActionResult jsonRet2 = tvItemStatController.Post(tvItemStatRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet2);

                    OkNegotiatedContentResult <TVItemStat> tvItemStatRet2 = jsonRet2 as OkNegotiatedContentResult <TVItemStat>;
                    Assert.IsNull(tvItemStatRet2);

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

                    // Post to return newly added TVItemStat
                    tvItemStatRet.TVItemStatID              = 0;
                    tvItemStatController.Request            = new System.Net.Http.HttpRequestMessage();
                    tvItemStatController.Request.RequestUri = new System.Uri("http://localhost:5000/api/tvItemStat");
                    IHttpActionResult jsonRet3 = tvItemStatController.Post(tvItemStatRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet3);

                    CreatedNegotiatedContentResult <TVItemStat> tvItemStatRet3 = jsonRet3 as CreatedNegotiatedContentResult <TVItemStat>;
                    Assert.IsNotNull(tvItemStatRet3);

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

                    IHttpActionResult jsonRet4 = tvItemStatController.Delete(tvItemStatRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet4);

                    OkNegotiatedContentResult <TVItemStat> tvItemStatRet4 = jsonRet4 as OkNegotiatedContentResult <TVItemStat>;
                    Assert.IsNotNull(tvItemStatRet4);

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