Example #1
0
        public void GetHelpDocWithHelpDocID__helpDoc_HelpDocID__Test()
        {
            foreach (CultureInfo culture in AllowableCulture)
            {
                ChangeCulture(culture);

                using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                {
                    HelpDocService helpDocService = new HelpDocService(new Query()
                    {
                        Lang = culture.TwoLetterISOLanguageName
                    }, dbTestDB, ContactID);
                    HelpDoc helpDoc = (from c in dbTestDB.HelpDocs select c).FirstOrDefault();
                    Assert.IsNotNull(helpDoc);

                    foreach (string extra in new List <string>()
                    {
                        null, "A", "B", "C", "D", "E"
                    })
                    {
                        helpDocService.Query.Extra = extra;

                        if (string.IsNullOrWhiteSpace(extra))
                        {
                            HelpDoc helpDocRet = helpDocService.GetHelpDocWithHelpDocID(helpDoc.HelpDocID);
                            CheckHelpDocFields(new List <HelpDoc>()
                            {
                                helpDocRet
                            });
                            Assert.AreEqual(helpDoc.HelpDocID, helpDocRet.HelpDocID);
                        }
                        else
                        {
                            //Assert.AreEqual(true, false);
                        }
                    }
                }
            }
        }
Example #2
0
        public void GetHelpDocList_2Where_Test()
        {
            foreach (CultureInfo culture in AllowableCulture)
            {
                ChangeCulture(culture);

                using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                {
                    foreach (string extra in new List <string>()
                    {
                        null, "A", "B", "C", "D", "E"
                    })
                    {
                        HelpDocService helpDocService = new HelpDocService(new Query()
                        {
                            Lang = culture.TwoLetterISOLanguageName
                        }, dbTestDB, ContactID);

                        helpDocService.Query = helpDocService.FillQuery(typeof(HelpDoc), culture.TwoLetterISOLanguageName, 0, 10000, "", "", "HelpDocID,GT,2|HelpDocID,LT,5", extra);

                        List <HelpDoc> helpDocDirectQueryList = new List <HelpDoc>();
                        helpDocDirectQueryList = (from c in dbTestDB.HelpDocs select c).Where(c => c.HelpDocID > 2 && c.HelpDocID < 5).ToList();

                        if (string.IsNullOrWhiteSpace(extra))
                        {
                            List <HelpDoc> helpDocList = new List <HelpDoc>();
                            helpDocList = helpDocService.GetHelpDocList().ToList();
                            CheckHelpDocFields(helpDocList);
                            Assert.AreEqual(helpDocDirectQueryList[0].HelpDocID, helpDocList[0].HelpDocID);
                        }
                        else
                        {
                            //Assert.AreEqual(true, false);
                        }
                    }
                }
            }
        }
Example #3
0
        public void HelpDoc_Properties_Test()
        {
            foreach (CultureInfo culture in AllowableCulture)
            {
                ChangeCulture(culture);

                using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                {
                    HelpDocService helpDocService = new HelpDocService(new Query()
                    {
                        Lang = culture.TwoLetterISOLanguageName
                    }, dbTestDB, ContactID);

                    int count = 0;
                    if (count == 1)
                    {
                        // just so we don't get a warning during compile [The variable 'count' is assigned but its value is never used]
                    }

                    count = helpDocService.GetHelpDocList().Count();

                    HelpDoc helpDoc = GetFilledRandomHelpDoc("");

                    // -------------------------------
                    // -------------------------------
                    // Properties testing
                    // -------------------------------
                    // -------------------------------


                    // -----------------------------------
                    // [Key]
                    // Is NOT Nullable
                    // helpDoc.HelpDocID   (Int32)
                    // -----------------------------------

                    helpDoc           = null;
                    helpDoc           = GetFilledRandomHelpDoc("");
                    helpDoc.HelpDocID = 0;
                    helpDocService.Update(helpDoc);
                    Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "HelpDocID"), helpDoc.ValidationResults.FirstOrDefault().ErrorMessage);

                    helpDoc           = null;
                    helpDoc           = GetFilledRandomHelpDoc("");
                    helpDoc.HelpDocID = 10000000;
                    helpDocService.Update(helpDoc);
                    Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "HelpDoc", "HelpDocID", helpDoc.HelpDocID.ToString()), helpDoc.ValidationResults.FirstOrDefault().ErrorMessage);


                    // -----------------------------------
                    // Is NOT Nullable
                    // [StringLength(100))]
                    // helpDoc.DocKey   (String)
                    // -----------------------------------

                    helpDoc = null;
                    helpDoc = GetFilledRandomHelpDoc("DocKey");
                    Assert.AreEqual(false, helpDocService.Add(helpDoc));
                    Assert.AreEqual(1, helpDoc.ValidationResults.Count());
                    Assert.IsTrue(helpDoc.ValidationResults.Where(c => c.ErrorMessage == string.Format(CSSPServicesRes._IsRequired, "DocKey")).Any());
                    Assert.AreEqual(null, helpDoc.DocKey);
                    Assert.AreEqual(count, helpDocService.GetHelpDocList().Count());

                    helpDoc        = null;
                    helpDoc        = GetFilledRandomHelpDoc("");
                    helpDoc.DocKey = GetRandomString("", 101);
                    Assert.AreEqual(false, helpDocService.Add(helpDoc));
                    Assert.AreEqual(string.Format(CSSPServicesRes._MaxLengthIs_, "DocKey", "100"), helpDoc.ValidationResults.FirstOrDefault().ErrorMessage);
                    Assert.AreEqual(count, helpDocService.GetHelpDocList().Count());

                    // -----------------------------------
                    // Is NOT Nullable
                    // [CSSPEnumType]
                    // helpDoc.Language   (LanguageEnum)
                    // -----------------------------------

                    helpDoc          = null;
                    helpDoc          = GetFilledRandomHelpDoc("");
                    helpDoc.Language = (LanguageEnum)1000000;
                    helpDocService.Add(helpDoc);
                    Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "Language"), helpDoc.ValidationResults.FirstOrDefault().ErrorMessage);


                    // -----------------------------------
                    // Is NOT Nullable
                    // [StringLength(100000))]
                    // helpDoc.DocHTMLText   (String)
                    // -----------------------------------

                    helpDoc = null;
                    helpDoc = GetFilledRandomHelpDoc("DocHTMLText");
                    Assert.AreEqual(false, helpDocService.Add(helpDoc));
                    Assert.AreEqual(1, helpDoc.ValidationResults.Count());
                    Assert.IsTrue(helpDoc.ValidationResults.Where(c => c.ErrorMessage == string.Format(CSSPServicesRes._IsRequired, "DocHTMLText")).Any());
                    Assert.AreEqual(null, helpDoc.DocHTMLText);
                    Assert.AreEqual(count, helpDocService.GetHelpDocList().Count());

                    helpDoc             = null;
                    helpDoc             = GetFilledRandomHelpDoc("");
                    helpDoc.DocHTMLText = GetRandomString("", 100001);
                    Assert.AreEqual(false, helpDocService.Add(helpDoc));
                    Assert.AreEqual(string.Format(CSSPServicesRes._MaxLengthIs_, "DocHTMLText", "100000"), helpDoc.ValidationResults.FirstOrDefault().ErrorMessage);
                    Assert.AreEqual(count, helpDocService.GetHelpDocList().Count());

                    // -----------------------------------
                    // Is NOT Nullable
                    // [CSSPAfter(Year = 1980)]
                    // helpDoc.LastUpdateDate_UTC   (DateTime)
                    // -----------------------------------

                    helpDoc = null;
                    helpDoc = GetFilledRandomHelpDoc("");
                    helpDoc.LastUpdateDate_UTC = new DateTime();
                    helpDocService.Add(helpDoc);
                    Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "LastUpdateDate_UTC"), helpDoc.ValidationResults.FirstOrDefault().ErrorMessage);
                    helpDoc = null;
                    helpDoc = GetFilledRandomHelpDoc("");
                    helpDoc.LastUpdateDate_UTC = new DateTime(1979, 1, 1);
                    helpDocService.Add(helpDoc);
                    Assert.AreEqual(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "LastUpdateDate_UTC", "1980"), helpDoc.ValidationResults.FirstOrDefault().ErrorMessage);

                    // -----------------------------------
                    // Is NOT Nullable
                    // [CSSPExist(ExistTypeName = "TVItem", ExistPlurial = "s", ExistFieldID = "TVItemID", AllowableTVtypeList = Contact)]
                    // helpDoc.LastUpdateContactTVItemID   (Int32)
                    // -----------------------------------

                    helpDoc = null;
                    helpDoc = GetFilledRandomHelpDoc("");
                    helpDoc.LastUpdateContactTVItemID = 0;
                    helpDocService.Add(helpDoc);
                    Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "LastUpdateContactTVItemID", helpDoc.LastUpdateContactTVItemID.ToString()), helpDoc.ValidationResults.FirstOrDefault().ErrorMessage);

                    helpDoc = null;
                    helpDoc = GetFilledRandomHelpDoc("");
                    helpDoc.LastUpdateContactTVItemID = 1;
                    helpDocService.Add(helpDoc);
                    Assert.AreEqual(string.Format(CSSPServicesRes._IsNotOfType_, "LastUpdateContactTVItemID", "Contact"), helpDoc.ValidationResults.FirstOrDefault().ErrorMessage);


                    // -----------------------------------
                    // Is NOT Nullable
                    // [NotMapped]
                    // helpDoc.HasErrors   (Boolean)
                    // -----------------------------------

                    // No testing requied

                    // -----------------------------------
                    // Is NOT Nullable
                    // [NotMapped]
                    // helpDoc.ValidationResults   (IEnumerable`1)
                    // -----------------------------------

                    // No testing requied
                }
            }
        }
        public IHttpActionResult GetHelpDocList([FromUri] string lang = "en", [FromUri] int skip  = 0, [FromUri] int take      = 200,
                                                [FromUri] string asc  = "", [FromUri] string desc = "", [FromUri] string where = "", [FromUri] string extra = "")
        {
            using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
            {
                HelpDocService helpDocService = new HelpDocService(new Query()
                {
                    Lang = lang
                }, db, ContactID);

                if (extra == "A") // QueryString contains [extra=A]
                {
                    helpDocService.Query = helpDocService.FillQuery(typeof(HelpDocExtraA), lang, skip, take, asc, desc, where, extra);

                    if (helpDocService.Query.HasErrors)
                    {
                        return(Ok(new List <HelpDocExtraA>()
                        {
                            new HelpDocExtraA()
                            {
                                HasErrors = helpDocService.Query.HasErrors,
                                ValidationResults = helpDocService.Query.ValidationResults,
                            },
                        }.ToList()));
                    }
                    else
                    {
                        return(Ok(helpDocService.GetHelpDocExtraAList().ToList()));
                    }
                }
                else if (extra == "B") // QueryString contains [extra=B]
                {
                    helpDocService.Query = helpDocService.FillQuery(typeof(HelpDocExtraB), lang, skip, take, asc, desc, where, extra);

                    if (helpDocService.Query.HasErrors)
                    {
                        return(Ok(new List <HelpDocExtraB>()
                        {
                            new HelpDocExtraB()
                            {
                                HasErrors = helpDocService.Query.HasErrors,
                                ValidationResults = helpDocService.Query.ValidationResults,
                            },
                        }.ToList()));
                    }
                    else
                    {
                        return(Ok(helpDocService.GetHelpDocExtraBList().ToList()));
                    }
                }
                else // QueryString has no parameter [extra] or extra is empty
                {
                    helpDocService.Query = helpDocService.FillQuery(typeof(HelpDoc), lang, skip, take, asc, desc, where, extra);

                    if (helpDocService.Query.HasErrors)
                    {
                        return(Ok(new List <HelpDoc>()
                        {
                            new HelpDoc()
                            {
                                HasErrors = helpDocService.Query.HasErrors,
                                ValidationResults = helpDocService.Query.ValidationResults,
                            },
                        }.ToList()));
                    }
                    else
                    {
                        return(Ok(helpDocService.GetHelpDocList().ToList()));
                    }
                }
            }
        }
 protected override void Initialize(System.Web.Routing.RequestContext requestContext)
 {
     base.Initialize(requestContext);
     _HelpDocService = new HelpDocService(LanguageRequest, User);
 }
        public void HelpDoc_Controller_GetHelpDocList_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    HelpDocController helpDocController = new HelpDocController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(helpDocController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, helpDocController.DatabaseType);

                    HelpDoc helpDocFirst = new HelpDoc();
                    int     count        = -1;
                    Query   query        = new Query();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                    {
                        HelpDocService helpDocService = new HelpDocService(query, db, ContactID);
                        helpDocFirst = (from c in db.HelpDocs select c).FirstOrDefault();
                        count        = (from c in db.HelpDocs select c).Count();
                        count        = (query.Take > count ? count : query.Take);
                    }

                    // ok with HelpDoc info
                    IHttpActionResult jsonRet = helpDocController.GetHelpDocList();
                    Assert.IsNotNull(jsonRet);

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

                    List <HelpDoc> helpDocList = new List <HelpDoc>();
                    count = -1;
                    query = new Query();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                    {
                        HelpDocService helpDocService = new HelpDocService(query, db, ContactID);
                        helpDocList = (from c in db.HelpDocs select c).OrderBy(c => c.HelpDocID).Skip(0).Take(2).ToList();
                        count       = (from c in db.HelpDocs select c).Count();
                    }

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

                        // ok with HelpDoc info
                        jsonRet = helpDocController.GetHelpDocList(query.Language.ToString(), query.Skip, query.Take);
                        Assert.IsNotNull(jsonRet);

                        ret = jsonRet as OkNegotiatedContentResult <List <HelpDoc> >;
                        Assert.AreEqual(helpDocList[0].HelpDocID, ret.Content[0].HelpDocID);
                        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 HelpDoc info
                            IHttpActionResult jsonRet2 = helpDocController.GetHelpDocList(query.Language.ToString(), query.Skip, query.Take);
                            Assert.IsNotNull(jsonRet2);

                            OkNegotiatedContentResult <List <HelpDoc> > ret2 = jsonRet2 as OkNegotiatedContentResult <List <HelpDoc> >;
                            Assert.AreEqual(helpDocList[1].HelpDocID, ret2.Content[0].HelpDocID);
                            Assert.AreEqual((count > query.Take ? query.Take : count), ret2.Content.Count);
                        }
                    }
                }
            }
        }
        public void HelpDoc_Controller_Delete_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    HelpDocController helpDocController = new HelpDocController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(helpDocController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, helpDocController.DatabaseType);

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

                        HelpDocService helpDocService = new HelpDocService(query, db, ContactID);
                        helpDocLast = (from c in db.HelpDocs select c).FirstOrDefault();
                    }

                    // ok with HelpDoc info
                    IHttpActionResult jsonRet = helpDocController.GetHelpDocWithID(helpDocLast.HelpDocID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <HelpDoc> Ret = jsonRet as OkNegotiatedContentResult <HelpDoc>;
                    HelpDoc helpDocRet = Ret.Content;
                    Assert.AreEqual(helpDocLast.HelpDocID, helpDocRet.HelpDocID);

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

                    // Post to return newly added HelpDoc
                    helpDocRet.HelpDocID                 = 0;
                    helpDocController.Request            = new System.Net.Http.HttpRequestMessage();
                    helpDocController.Request.RequestUri = new System.Uri("http://localhost:5000/api/helpDoc");
                    IHttpActionResult jsonRet3 = helpDocController.Post(helpDocRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet3);

                    CreatedNegotiatedContentResult <HelpDoc> helpDocRet3 = jsonRet3 as CreatedNegotiatedContentResult <HelpDoc>;
                    Assert.IsNotNull(helpDocRet3);
                    HelpDoc helpDoc = helpDocRet3.Content;

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

                    // Delete to return success
                    IHttpActionResult jsonRet2 = helpDocController.Delete(helpDocRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet2);

                    OkNegotiatedContentResult <HelpDoc> helpDocRet2 = jsonRet2 as OkNegotiatedContentResult <HelpDoc>;
                    Assert.IsNotNull(helpDocRet2);

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

                    // Delete to return CSSPError because HelpDocID of 0 does not exist
                    helpDocRet.HelpDocID = 0;
                    IHttpActionResult jsonRet4 = helpDocController.Delete(helpDocRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet4);

                    OkNegotiatedContentResult <HelpDoc> helpDocRet4 = jsonRet4 as OkNegotiatedContentResult <HelpDoc>;
                    Assert.IsNull(helpDocRet4);

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