コード例 #1
0
        public void Classification_CRUD_Test()
        {
            foreach (CultureInfo culture in AllowableCulture)
            {
                ChangeCulture(culture);

                using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                {
                    ClassificationService classificationService = new ClassificationService(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]
                    }

                    Classification classification = GetFilledRandomClassification("");

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

                    count = classificationService.GetClassificationList().Count();

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

                    classificationService.Add(classification);
                    if (classification.HasErrors)
                    {
                        Assert.AreEqual("", classification.ValidationResults.FirstOrDefault().ErrorMessage);
                    }
                    Assert.AreEqual(true, classificationService.GetClassificationList().Where(c => c == classification).Any());
                    classificationService.Update(classification);
                    if (classification.HasErrors)
                    {
                        Assert.AreEqual("", classification.ValidationResults.FirstOrDefault().ErrorMessage);
                    }
                    Assert.AreEqual(count + 1, classificationService.GetClassificationList().Count());
                    classificationService.Delete(classification);
                    if (classification.HasErrors)
                    {
                        Assert.AreEqual("", classification.ValidationResults.FirstOrDefault().ErrorMessage);
                    }
                    Assert.AreEqual(count, classificationService.GetClassificationList().Count());
                }
            }
        }
コード例 #2
0
        public void GetClassificationList_Test()
        {
            foreach (CultureInfo culture in AllowableCulture)
            {
                ChangeCulture(culture);

                using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                {
                    ClassificationService classificationService = new ClassificationService(new Query()
                    {
                        Lang = culture.TwoLetterISOLanguageName
                    }, dbTestDB, ContactID);
                    Classification classification = (from c in dbTestDB.Classifications select c).FirstOrDefault();
                    Assert.IsNotNull(classification);

                    List <Classification> classificationDirectQueryList = new List <Classification>();
                    classificationDirectQueryList = (from c in dbTestDB.Classifications select c).Take(200).ToList();

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

                        if (string.IsNullOrWhiteSpace(extra))
                        {
                            List <Classification> classificationList = new List <Classification>();
                            classificationList = classificationService.GetClassificationList().ToList();
                            CheckClassificationFields(classificationList);
                        }
                        else
                        {
                            //Assert.AreEqual(true, false);
                        }
                    }
                }
            }
        }
コード例 #3
0
        public void GetClassificationList_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"
                    })
                    {
                        ClassificationService classificationService = new ClassificationService(new Query()
                        {
                            Lang = culture.TwoLetterISOLanguageName
                        }, dbTestDB, ContactID);

                        classificationService.Query = classificationService.FillQuery(typeof(Classification), culture.TwoLetterISOLanguageName, 0, 10000, "", "", "ClassificationID,GT,2|ClassificationID,LT,5", extra);

                        List <Classification> classificationDirectQueryList = new List <Classification>();
                        classificationDirectQueryList = (from c in dbTestDB.Classifications select c).Where(c => c.ClassificationID > 2 && c.ClassificationID < 5).ToList();

                        if (string.IsNullOrWhiteSpace(extra))
                        {
                            List <Classification> classificationList = new List <Classification>();
                            classificationList = classificationService.GetClassificationList().ToList();
                            CheckClassificationFields(classificationList);
                            Assert.AreEqual(classificationDirectQueryList[0].ClassificationID, classificationList[0].ClassificationID);
                        }
                        else
                        {
                            //Assert.AreEqual(true, false);
                        }
                    }
                }
            }
        }
コード例 #4
0
        public void Classification_Properties_Test()
        {
            foreach (CultureInfo culture in AllowableCulture)
            {
                ChangeCulture(culture);

                using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                {
                    ClassificationService classificationService = new ClassificationService(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 = classificationService.GetClassificationList().Count();

                    Classification classification = GetFilledRandomClassification("");

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


                    // -----------------------------------
                    // [Key]
                    // Is NOT Nullable
                    // classification.ClassificationID   (Int32)
                    // -----------------------------------

                    classification = null;
                    classification = GetFilledRandomClassification("");
                    classification.ClassificationID = 0;
                    classificationService.Update(classification);
                    Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "ClassificationID"), classification.ValidationResults.FirstOrDefault().ErrorMessage);

                    classification = null;
                    classification = GetFilledRandomClassification("");
                    classification.ClassificationID = 10000000;
                    classificationService.Update(classification);
                    Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "Classification", "ClassificationID", classification.ClassificationID.ToString()), classification.ValidationResults.FirstOrDefault().ErrorMessage);


                    // -----------------------------------
                    // Is NOT Nullable
                    // [CSSPExist(ExistTypeName = "TVItem", ExistPlurial = "s", ExistFieldID = "TVItemID", AllowableTVtypeList = Classification)]
                    // classification.ClassificationTVItemID   (Int32)
                    // -----------------------------------

                    classification = null;
                    classification = GetFilledRandomClassification("");
                    classification.ClassificationTVItemID = 0;
                    classificationService.Add(classification);
                    Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "ClassificationTVItemID", classification.ClassificationTVItemID.ToString()), classification.ValidationResults.FirstOrDefault().ErrorMessage);

                    classification = null;
                    classification = GetFilledRandomClassification("");
                    classification.ClassificationTVItemID = 1;
                    classificationService.Add(classification);
                    Assert.AreEqual(string.Format(CSSPServicesRes._IsNotOfType_, "ClassificationTVItemID", "Classification"), classification.ValidationResults.FirstOrDefault().ErrorMessage);


                    // -----------------------------------
                    // Is NOT Nullable
                    // [CSSPEnumType]
                    // classification.ClassificationType   (ClassificationTypeEnum)
                    // -----------------------------------

                    classification = null;
                    classification = GetFilledRandomClassification("");
                    classification.ClassificationType = (ClassificationTypeEnum)1000000;
                    classificationService.Add(classification);
                    Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "ClassificationType"), classification.ValidationResults.FirstOrDefault().ErrorMessage);


                    // -----------------------------------
                    // Is NOT Nullable
                    // [Range(0, 10000)]
                    // classification.Ordinal   (Int32)
                    // -----------------------------------

                    classification         = null;
                    classification         = GetFilledRandomClassification("");
                    classification.Ordinal = -1;
                    Assert.AreEqual(false, classificationService.Add(classification));
                    Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "Ordinal", "0", "10000"), classification.ValidationResults.FirstOrDefault().ErrorMessage);
                    Assert.AreEqual(count, classificationService.GetClassificationList().Count());
                    classification         = null;
                    classification         = GetFilledRandomClassification("");
                    classification.Ordinal = 10001;
                    Assert.AreEqual(false, classificationService.Add(classification));
                    Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "Ordinal", "0", "10000"), classification.ValidationResults.FirstOrDefault().ErrorMessage);
                    Assert.AreEqual(count, classificationService.GetClassificationList().Count());

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

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

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

                    classification = null;
                    classification = GetFilledRandomClassification("");
                    classification.LastUpdateContactTVItemID = 0;
                    classificationService.Add(classification);
                    Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "LastUpdateContactTVItemID", classification.LastUpdateContactTVItemID.ToString()), classification.ValidationResults.FirstOrDefault().ErrorMessage);

                    classification = null;
                    classification = GetFilledRandomClassification("");
                    classification.LastUpdateContactTVItemID = 1;
                    classificationService.Add(classification);
                    Assert.AreEqual(string.Format(CSSPServicesRes._IsNotOfType_, "LastUpdateContactTVItemID", "Contact"), classification.ValidationResults.FirstOrDefault().ErrorMessage);


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

                    // No testing requied

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

                    // No testing requied
                }
            }
        }
コード例 #5
0
        public IHttpActionResult GetClassificationList([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))
            {
                ClassificationService classificationService = new ClassificationService(new Query()
                {
                    Lang = lang
                }, db, ContactID);

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

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

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

                    if (classificationService.Query.HasErrors)
                    {
                        return(Ok(new List <Classification>()
                        {
                            new Classification()
                            {
                                HasErrors = classificationService.Query.HasErrors,
                                ValidationResults = classificationService.Query.ValidationResults,
                            },
                        }.ToList()));
                    }
                    else
                    {
                        return(Ok(classificationService.GetClassificationList().ToList()));
                    }
                }
            }
        }