Beispiel #1
0
        public virtual string GetHelp(object typeItem)
        {
            string itemToFind = string.Empty;

            if (typeItem is MethodInfo)
            {
                var methodInfo = typeItem as MethodInfo;
                itemToFind = GetHelpString("M", methodInfo.DeclaringType.Namespace, methodInfo.DeclaringType.Name,
                                           methodInfo.Name);
            }
            if (typeItem is PropertyInfo)
            {
                var propInfo = typeItem as PropertyInfo;
                itemToFind = GetHelpString("P", propInfo.DeclaringType.Namespace, propInfo.DeclaringType.Name,
                                           propInfo.Name);
            }
            if (itemToFind != string.Empty)
            {
// ReSharper disable PossibleNullReferenceException
                XElement item =
                    HelpDoc.Descendants("member").SingleOrDefault(p => p.Attribute("name").Value == itemToFind);
// ReSharper restore PossibleNullReferenceException
                if (item != null)
                {
                    XElement helpSummary = item.Element("summary");
                    if (helpSummary != null)
                    {
                        return(helpSummary.Value);
                    }
                }
            }
            return("No help found  (or) check the file : " + HelpXmlFile);
        }
Beispiel #2
0
        public HelpDocModel PostDeleteHelpDocDB(int HelpDocID, LanguageEnum Language)
        {
            ContactOK contactOK = IsContactOK();

            if (!string.IsNullOrEmpty(contactOK.Error))
            {
                return(ReturnError(contactOK.Error));
            }

            HelpDoc helpDocToDelete = GetHelpDocWithHelpDocIDDB(HelpDocID);

            if (helpDocToDelete == null)
            {
                return(ReturnError(string.Format(ServiceRes.CouldNotFind_ToDelete, ServiceRes.HelpDoc)));
            }

            using (TransactionScope ts = new TransactionScope())
            {
                db.HelpDocs.Remove(helpDocToDelete);
                string retStr = DoDeleteChanges();
                if (!string.IsNullOrWhiteSpace(retStr))
                {
                    return(ReturnError(retStr));
                }

                LogModel logModel = _LogService.PostAddLogForObj("HelpDocs", helpDocToDelete.HelpDocID, LogCommandEnum.Delete, helpDocToDelete);
                if (!string.IsNullOrWhiteSpace(logModel.Error))
                {
                    return(ReturnError(logModel.Error));
                }

                ts.Complete();
            }
            return(ReturnError(""));
        }
Beispiel #3
0
        public ActionResult DocEdit(HttpPostedFileBase uploadFile, DocMgrVM vm, int id)
        {
            if (ModelState.IsValid)
            {
                HelpDoc doc = db.HelpDocs.Single(p => p.DocId == id);
                doc.DocName     = vm.HelpDoc.DocName;
                doc.Description = vm.HelpDoc.Description;
                doc.DocInfo     = vm.HelpDoc.DocInfo;
                doc.IsVisible   = vm.HelpDoc.IsVisible;

                if (uploadFile != null && uploadFile.ContentLength != 0)
                {
                    using (MemoryStream ms = new MemoryStream())
                    {
                        uploadFile.InputStream.CopyTo(ms);
                        byte[] fileData = ms.GetBuffer();
                        doc.Filename      = uploadFile.FileName;
                        doc.ContentLength = uploadFile.ContentLength;
                        doc.ContentType   = uploadFile.ContentType;
                        doc.Data          = fileData;
                    }
                }
                db.SaveChanges();

                return(RedirectToAction("DocList", new { id = vm.HelpDoc.MenuId }));
            }
            vm.HelpDoc = db.HelpDocs.Single(p => p.DocId == id);
            return(View(vm));
        }
Beispiel #4
0
        private HelpDoc GetFilledRandomHelpDoc(string OmitPropName)
        {
            HelpDoc helpDoc = new HelpDoc();

            if (OmitPropName != "DocKey")
            {
                helpDoc.DocKey = GetRandomString("", 5);
            }
            if (OmitPropName != "Language")
            {
                helpDoc.Language = LanguageRequest;
            }
            if (OmitPropName != "DocHTMLText")
            {
                helpDoc.DocHTMLText = GetRandomString("", 5);
            }
            if (OmitPropName != "LastUpdateDate_UTC")
            {
                helpDoc.LastUpdateDate_UTC = new DateTime(2005, 3, 6);
            }
            if (OmitPropName != "LastUpdateContactTVItemID")
            {
                helpDoc.LastUpdateContactTVItemID = 2;
            }

            return(helpDoc);
        }
Beispiel #5
0
        public HelpDoc GetHelpDocWithHelpDocIDDB(int HelpDocID)
        {
            HelpDoc HelpDoc = (from c in db.HelpDocs
                               where c.HelpDocID == HelpDocID
                               select c).FirstOrDefault <HelpDoc>();

            return(HelpDoc);
        }
        public void HelpDoc_Controller_Put_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;

                        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);

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

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

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

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

                    OkNegotiatedContentResult <HelpDoc> helpDocRet3 = jsonRet3 as OkNegotiatedContentResult <HelpDoc>;
                    Assert.IsNull(helpDocRet3);

                    BadRequestErrorMessageResult badRequest3 = jsonRet3 as BadRequestErrorMessageResult;
                    Assert.IsNotNull(badRequest3);
                }
            }
        }
Beispiel #7
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());
                }
            }
        }
Beispiel #8
0
        public HelpDocModel PostAddHelpDocDB(HelpDocModel helpDocModel)
        {
            string retStr = HelpDocModelOK(helpDocModel);

            if (!string.IsNullOrEmpty(retStr))
            {
                return(ReturnError(retStr));
            }

            ContactOK contactOK = IsContactOK();

            if (!string.IsNullOrEmpty(contactOK.Error))
            {
                return(ReturnError(contactOK.Error));
            }

            HelpDocModel helpDocModelExist = GetHelpDocModelWithDocKeyAndLanguageDB(helpDocModel.DocKey, helpDocModel.Language);

            if (string.IsNullOrWhiteSpace(helpDocModelExist.Error))
            {
                return(ReturnError(string.Format(ServiceRes._AlreadyExists, ServiceRes.HelpDoc)));
            }

            HelpDoc helpDocNew = new HelpDoc();

            retStr = FillHelpDoc(helpDocNew, helpDocModel, contactOK);
            if (!string.IsNullOrWhiteSpace(retStr))
            {
                return(ReturnError(retStr));
            }

            using (TransactionScope ts = new TransactionScope())
            {
                db.HelpDocs.Add(helpDocNew);
                retStr = DoAddChanges();
                if (!string.IsNullOrWhiteSpace(retStr))
                {
                    return(ReturnError(retStr));
                }

                LogModel logModel = _LogService.PostAddLogForObj("HelpDocs", helpDocNew.HelpDocID, LogCommandEnum.Add, helpDocNew);
                if (!string.IsNullOrWhiteSpace(logModel.Error))
                {
                    return(ReturnError(logModel.Error));
                }

                ts.Complete();
            }
            return(GetHelpDocModelWithHelpDocIDDB(helpDocNew.HelpDocID));
        }
        public IHttpActionResult GetHelpDocWithID([FromUri] int HelpDocID, [FromUri] string lang = "en", [FromUri] string extra = "")
        {
            using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
            {
                HelpDocService helpDocService = new HelpDocService(new Query()
                {
                    Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en)
                }, db, ContactID);

                helpDocService.Query = helpDocService.FillQuery(typeof(HelpDoc), lang, 0, 1, "", "", extra);

                if (helpDocService.Query.Extra == "A")
                {
                    HelpDocExtraA helpDocExtraA = new HelpDocExtraA();
                    helpDocExtraA = helpDocService.GetHelpDocExtraAWithHelpDocID(HelpDocID);

                    if (helpDocExtraA == null)
                    {
                        return(NotFound());
                    }

                    return(Ok(helpDocExtraA));
                }
                else if (helpDocService.Query.Extra == "B")
                {
                    HelpDocExtraB helpDocExtraB = new HelpDocExtraB();
                    helpDocExtraB = helpDocService.GetHelpDocExtraBWithHelpDocID(HelpDocID);

                    if (helpDocExtraB == null)
                    {
                        return(NotFound());
                    }

                    return(Ok(helpDocExtraB));
                }
                else
                {
                    HelpDoc helpDoc = new HelpDoc();
                    helpDoc = helpDocService.GetHelpDocWithHelpDocID(HelpDocID);

                    if (helpDoc == null)
                    {
                        return(NotFound());
                    }

                    return(Ok(helpDoc));
                }
            }
        }
Beispiel #10
0
        public HelpDocModel PostUpdateHelpDocDB(HelpDocModel helpDocModel)
        {
            string retStr = HelpDocModelOK(helpDocModel);

            if (!string.IsNullOrWhiteSpace(retStr))
            {
                return(ReturnError(retStr));
            }

            ContactOK contactOK = IsContactOK();

            if (!string.IsNullOrEmpty(contactOK.Error))
            {
                return(ReturnError(contactOK.Error));
            }

            HelpDoc helpDocToUpdate = GetHelpDocWithHelpDocIDDB(helpDocModel.HelpDocID);

            if (helpDocToUpdate == null)
            {
                return(ReturnError(string.Format(ServiceRes.CouldNotFind_ToUpdate, ServiceRes.HelpDoc)));
            }

            retStr = FillHelpDoc(helpDocToUpdate, helpDocModel, contactOK);
            if (!string.IsNullOrWhiteSpace(retStr))
            {
                return(ReturnError(retStr));
            }

            using (TransactionScope ts = new TransactionScope())
            {
                retStr = DoUpdateChanges();
                if (!string.IsNullOrWhiteSpace(retStr))
                {
                    return(ReturnError(retStr));
                }

                LogModel logModel = _LogService.PostAddLogForObj("HelpDocs", helpDocToUpdate.HelpDocID, LogCommandEnum.Change, helpDocToUpdate);
                if (!string.IsNullOrWhiteSpace(logModel.Error))
                {
                    return(ReturnError(logModel.Error));
                }

                ts.Complete();
            }
            return(GetHelpDocModelWithHelpDocIDDB(helpDocToUpdate.HelpDocID));
        }
Beispiel #11
0
        /// <summary>
        /// Updates an [HelpDoc](CSSPModels.HelpDoc.html) item in CSSPDB
        /// </summary>
        /// <param name="helpDoc">Is the HelpDoc item the client want to add to CSSPDB. What's important here is the HelpDocID</param>
        /// <returns>true if HelpDoc item was updated to CSSPDB, false if an error happened during the DB requested transtaction</returns>
        public bool Update(HelpDoc helpDoc)
        {
            helpDoc.ValidationResults = Validate(new ValidationContext(helpDoc), ActionDBTypeEnum.Update);
            if (helpDoc.ValidationResults.Count() > 0)
            {
                return(false);
            }

            db.HelpDocs.Update(helpDoc);

            if (!TryToSave(helpDoc))
            {
                return(false);
            }

            return(true);
        }
Beispiel #12
0
        /// <summary>
        /// Tries to execute the CSSPDB transaction (add/delete/update) on an [HelpDoc](CSSPModels.HelpDoc.html) item
        /// </summary>
        /// <param name="helpDoc">Is the HelpDoc item the client want to add to CSSPDB. What's important here is the HelpDocID</param>
        /// <returns>true if HelpDoc item was updated to CSSPDB, false if an error happened during the DB requested transtaction</returns>
        private bool TryToSave(HelpDoc helpDoc)
        {
            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException ex)
            {
                helpDoc.ValidationResults = new List <ValidationResult>()
                {
                    new ValidationResult(ex.Message + (ex.InnerException != null ? " Inner: " + ex.InnerException.Message : ""))
                }.AsEnumerable();
                return(false);
            }

            return(true);
        }
Beispiel #13
0
        // Fill
        public string FillHelpDoc(HelpDoc helpDocNew, HelpDocModel helpDocModel, ContactOK contactOK)
        {
            helpDocNew.DBCommand          = (int)helpDocModel.DBCommand;
            helpDocNew.DocKey             = helpDocModel.DocKey;
            helpDocNew.Language           = (int)helpDocModel.Language;
            helpDocNew.DocHTMLText        = helpDocModel.DocHTMLText;
            helpDocNew.LastUpdateDate_UTC = DateTime.UtcNow;
            if (contactOK == null)
            {
                helpDocNew.LastUpdateContactTVItemID = 2;
            }
            else
            {
                helpDocNew.LastUpdateContactTVItemID = contactOK.ContactTVItemID;
            }

            return("");
        }
        public void HelpDoc_Controller_GetHelpDocWithID_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();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
                    {
                        HelpDocService helpDocService = new HelpDocService(new Query(), db, ContactID);
                        helpDocFirst = (from c in db.HelpDocs select c).FirstOrDefault();
                    }

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

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

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

                    // Not Found
                    IHttpActionResult jsonRet2 = helpDocController.GetHelpDocWithID(0);
                    Assert.IsNotNull(jsonRet2);

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

                    NotFoundResult notFoundRequest = jsonRet2 as NotFoundResult;
                    Assert.IsNotNull(notFoundRequest);
                }
            }
        }
        public IHttpActionResult Delete([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.Delete(helpDoc))
                {
                    return(BadRequest(String.Join("|||", helpDoc.ValidationResults)));
                }
                else
                {
                    helpDoc.ValidationResults = null;
                    return(Ok(helpDoc));
                }
            }
        }
Beispiel #16
0
        public void GetHelpDocList_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);

                    List <HelpDoc> helpDocDirectQueryList = new List <HelpDoc>();
                    helpDocDirectQueryList = (from c in dbTestDB.HelpDocs select c).Take(200).ToList();

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

                        if (string.IsNullOrWhiteSpace(extra))
                        {
                            List <HelpDoc> helpDocList = new List <HelpDoc>();
                            helpDocList = helpDocService.GetHelpDocList().ToList();
                            CheckHelpDocFields(helpDocList);
                        }
                        else
                        {
                            //Assert.AreEqual(true, false);
                        }
                    }
                }
            }
        }
Beispiel #17
0
        /// <summary>
        /// Validate function for all HelpDocService commands
        /// </summary>
        /// <param name="validationContext">System.ComponentModel.DataAnnotations.ValidationContext (Describes the context in which a validation check is performed.)</param>
        /// <param name="actionDBType">[ActionDBTypeEnum] (CSSPEnums.ActionDBTypeEnum.html) action type to validate</param>
        /// <returns>IEnumerable of ValidationResult (Where ValidationResult is a container for the results of a validation request.)</returns>
        private IEnumerable <ValidationResult> Validate(ValidationContext validationContext, ActionDBTypeEnum actionDBType)
        {
            string  retStr  = "";
            Enums   enums   = new Enums(LanguageRequest);
            HelpDoc helpDoc = validationContext.ObjectInstance as HelpDoc;

            helpDoc.HasErrors = false;

            if (actionDBType == ActionDBTypeEnum.Update || actionDBType == ActionDBTypeEnum.Delete)
            {
                if (helpDoc.HelpDocID == 0)
                {
                    helpDoc.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "HelpDocID"), new[] { "HelpDocID" }));
                }

                if (!(from c in db.HelpDocs select c).Where(c => c.HelpDocID == helpDoc.HelpDocID).Any())
                {
                    helpDoc.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "HelpDoc", "HelpDocID", helpDoc.HelpDocID.ToString()), new[] { "HelpDocID" }));
                }
            }

            if (string.IsNullOrWhiteSpace(helpDoc.DocKey))
            {
                helpDoc.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "DocKey"), new[] { "DocKey" }));
            }

            if (!string.IsNullOrWhiteSpace(helpDoc.DocKey) && helpDoc.DocKey.Length > 100)
            {
                helpDoc.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "DocKey", "100"), new[] { "DocKey" }));
            }

            retStr = enums.EnumTypeOK(typeof(LanguageEnum), (int?)helpDoc.Language);
            if (!string.IsNullOrWhiteSpace(retStr))
            {
                helpDoc.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "Language"), new[] { "Language" }));
            }

            if (string.IsNullOrWhiteSpace(helpDoc.DocHTMLText))
            {
                helpDoc.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "DocHTMLText"), new[] { "DocHTMLText" }));
            }

            if (!string.IsNullOrWhiteSpace(helpDoc.DocHTMLText) && helpDoc.DocHTMLText.Length > 100000)
            {
                helpDoc.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "DocHTMLText", "100000"), new[] { "DocHTMLText" }));
            }

            if (helpDoc.LastUpdateDate_UTC.Year == 1)
            {
                helpDoc.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "LastUpdateDate_UTC"), new[] { "LastUpdateDate_UTC" }));
            }
            else
            {
                if (helpDoc.LastUpdateDate_UTC.Year < 1980)
                {
                    helpDoc.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "LastUpdateDate_UTC", "1980"), new[] { "LastUpdateDate_UTC" }));
                }
            }

            TVItem TVItemLastUpdateContactTVItemID = (from c in db.TVItems where c.TVItemID == helpDoc.LastUpdateContactTVItemID select c).FirstOrDefault();

            if (TVItemLastUpdateContactTVItemID == null)
            {
                helpDoc.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "LastUpdateContactTVItemID", helpDoc.LastUpdateContactTVItemID.ToString()), new[] { "LastUpdateContactTVItemID" }));
            }
            else
            {
                List <TVTypeEnum> AllowableTVTypes = new List <TVTypeEnum>()
                {
                    TVTypeEnum.Contact,
                };
                if (!AllowableTVTypes.Contains(TVItemLastUpdateContactTVItemID.TVType))
                {
                    helpDoc.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes._IsNotOfType_, "LastUpdateContactTVItemID", "Contact"), new[] { "LastUpdateContactTVItemID" }));
                }
            }

            retStr = "";      // added to stop compiling CSSPError
            if (retStr != "") // will never be true
            {
                helpDoc.HasErrors = true;
                yield return(new ValidationResult("AAA", new[] { "AAA" }));
            }
        }
Beispiel #18
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 void HelpDoc_Controller_Post_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 CSSPError because HelpDocID exist
                    IHttpActionResult jsonRet2 = helpDocController.Post(helpDocRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet2);

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

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

                    // 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);

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

                    IHttpActionResult jsonRet4 = helpDocController.Delete(helpDocRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet4);

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

                    BadRequestErrorMessageResult badRequest4 = jsonRet4 as BadRequestErrorMessageResult;
                    Assert.IsNull(badRequest4);
                }
            }
        }
        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 HelpDocTest()
 {
     helpDoc       = new HelpDoc();
     helpDocExtraA = new HelpDocExtraA();
     helpDocExtraB = new HelpDocExtraB();
 }