Example #1
0
        public void HelpDoc_CRUD_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]
                    }

                    HelpDoc helpDoc = GetFilledRandomHelpDoc("");

                    // -------------------------------
                    // -------------------------------
                    // CRUD testing
                    // -------------------------------
                    // -------------------------------

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

                    Assert.AreEqual(count, (from c in dbTestDB.HelpDocs select c).Count());

                    helpDocService.Add(helpDoc);
                    if (helpDoc.HasErrors)
                    {
                        Assert.AreEqual("", helpDoc.ValidationResults.FirstOrDefault().ErrorMessage);
                    }
                    Assert.AreEqual(true, helpDocService.GetHelpDocList().Where(c => c == helpDoc).Any());
                    helpDocService.Update(helpDoc);
                    if (helpDoc.HasErrors)
                    {
                        Assert.AreEqual("", helpDoc.ValidationResults.FirstOrDefault().ErrorMessage);
                    }
                    Assert.AreEqual(count + 1, helpDocService.GetHelpDocList().Count());
                    helpDocService.Delete(helpDoc);
                    if (helpDoc.HasErrors)
                    {
                        Assert.AreEqual("", helpDoc.ValidationResults.FirstOrDefault().ErrorMessage);
                    }
                    Assert.AreEqual(count, helpDocService.GetHelpDocList().Count());
                }
            }
        }
        public IHttpActionResult Put([FromBody] HelpDoc helpDoc, [FromUri] string lang = "en")
        {
            using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
            {
                HelpDocService helpDocService = new HelpDocService(new Query()
                {
                    Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en)
                }, db, ContactID);

                if (!helpDocService.Update(helpDoc))
                {
                    return(BadRequest(String.Join("|||", helpDoc.ValidationResults)));
                }
                else
                {
                    helpDoc.ValidationResults = null;
                    return(Ok(helpDoc));
                }
            }
        }
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
                }
            }
        }