Beispiel #1
0
        public void DrogueRun_CRUD_Test()
        {
            foreach (CultureInfo culture in AllowableCulture)
            {
                ChangeCulture(culture);

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

                    DrogueRun drogueRun = GetFilledRandomDrogueRun("");

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

                    count = drogueRunService.GetDrogueRunList().Count();

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

                    drogueRunService.Add(drogueRun);
                    if (drogueRun.HasErrors)
                    {
                        Assert.AreEqual("", drogueRun.ValidationResults.FirstOrDefault().ErrorMessage);
                    }
                    Assert.AreEqual(true, drogueRunService.GetDrogueRunList().Where(c => c == drogueRun).Any());
                    drogueRunService.Update(drogueRun);
                    if (drogueRun.HasErrors)
                    {
                        Assert.AreEqual("", drogueRun.ValidationResults.FirstOrDefault().ErrorMessage);
                    }
                    Assert.AreEqual(count + 1, drogueRunService.GetDrogueRunList().Count());
                    drogueRunService.Delete(drogueRun);
                    if (drogueRun.HasErrors)
                    {
                        Assert.AreEqual("", drogueRun.ValidationResults.FirstOrDefault().ErrorMessage);
                    }
                    Assert.AreEqual(count, drogueRunService.GetDrogueRunList().Count());
                }
            }
        }
Beispiel #2
0
        public void GetDrogueRunList_Test()
        {
            foreach (CultureInfo culture in AllowableCulture)
            {
                ChangeCulture(culture);

                using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                {
                    DrogueRunService drogueRunService = new DrogueRunService(new Query()
                    {
                        Lang = culture.TwoLetterISOLanguageName
                    }, dbTestDB, ContactID);
                    DrogueRun drogueRun = (from c in dbTestDB.DrogueRuns select c).FirstOrDefault();
                    Assert.IsNotNull(drogueRun);

                    List <DrogueRun> drogueRunDirectQueryList = new List <DrogueRun>();
                    drogueRunDirectQueryList = (from c in dbTestDB.DrogueRuns select c).Take(200).ToList();

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

                        if (string.IsNullOrWhiteSpace(extra))
                        {
                            List <DrogueRun> drogueRunList = new List <DrogueRun>();
                            drogueRunList = drogueRunService.GetDrogueRunList().ToList();
                            CheckDrogueRunFields(drogueRunList);
                        }
                        else
                        {
                            //Assert.AreEqual(true, false);
                        }
                    }
                }
            }
        }
Beispiel #3
0
        public void GetDrogueRunList_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"
                    })
                    {
                        DrogueRunService drogueRunService = new DrogueRunService(new Query()
                        {
                            Lang = culture.TwoLetterISOLanguageName
                        }, dbTestDB, ContactID);

                        drogueRunService.Query = drogueRunService.FillQuery(typeof(DrogueRun), culture.TwoLetterISOLanguageName, 0, 10000, "", "", "DrogueRunID,GT,2|DrogueRunID,LT,5", extra);

                        List <DrogueRun> drogueRunDirectQueryList = new List <DrogueRun>();
                        drogueRunDirectQueryList = (from c in dbTestDB.DrogueRuns select c).Where(c => c.DrogueRunID > 2 && c.DrogueRunID < 5).ToList();

                        if (string.IsNullOrWhiteSpace(extra))
                        {
                            List <DrogueRun> drogueRunList = new List <DrogueRun>();
                            drogueRunList = drogueRunService.GetDrogueRunList().ToList();
                            CheckDrogueRunFields(drogueRunList);
                            Assert.AreEqual(drogueRunDirectQueryList[0].DrogueRunID, drogueRunList[0].DrogueRunID);
                        }
                        else
                        {
                            //Assert.AreEqual(true, false);
                        }
                    }
                }
            }
        }
Beispiel #4
0
        public void GetDrogueRunList_Skip_Take_2Desc_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"
                    })
                    {
                        DrogueRunService drogueRunService = new DrogueRunService(new Query()
                        {
                            Lang = culture.TwoLetterISOLanguageName
                        }, dbTestDB, ContactID);

                        drogueRunService.Query = drogueRunService.FillQuery(typeof(DrogueRun), culture.TwoLetterISOLanguageName, 1, 1, "", "DrogueRunID,SubsectorTVItemID", "", extra);

                        List <DrogueRun> drogueRunDirectQueryList = new List <DrogueRun>();
                        drogueRunDirectQueryList = (from c in dbTestDB.DrogueRuns select c).OrderByDescending(c => c.DrogueRunID).ThenByDescending(c => c.SubsectorTVItemID).Skip(1).Take(1).ToList();

                        if (string.IsNullOrWhiteSpace(extra))
                        {
                            List <DrogueRun> drogueRunList = new List <DrogueRun>();
                            drogueRunList = drogueRunService.GetDrogueRunList().ToList();
                            CheckDrogueRunFields(drogueRunList);
                            Assert.AreEqual(drogueRunDirectQueryList[0].DrogueRunID, drogueRunList[0].DrogueRunID);
                        }
                        else
                        {
                            //Assert.AreEqual(true, false);
                        }
                    }
                }
            }
        }
Beispiel #5
0
        public IHttpActionResult GetDrogueRunList([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))
            {
                DrogueRunService drogueRunService = new DrogueRunService(new Query()
                {
                    Lang = lang
                }, db, ContactID);

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

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

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

                    if (drogueRunService.Query.HasErrors)
                    {
                        return(Ok(new List <DrogueRun>()
                        {
                            new DrogueRun()
                            {
                                HasErrors = drogueRunService.Query.HasErrors,
                                ValidationResults = drogueRunService.Query.ValidationResults,
                            },
                        }.ToList()));
                    }
                    else
                    {
                        return(Ok(drogueRunService.GetDrogueRunList().ToList()));
                    }
                }
            }
        }
Beispiel #6
0
        public void DrogueRun_Properties_Test()
        {
            foreach (CultureInfo culture in AllowableCulture)
            {
                ChangeCulture(culture);

                using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                {
                    DrogueRunService drogueRunService = new DrogueRunService(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 = drogueRunService.GetDrogueRunList().Count();

                    DrogueRun drogueRun = GetFilledRandomDrogueRun("");

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


                    // -----------------------------------
                    // [Key]
                    // Is NOT Nullable
                    // drogueRun.DrogueRunID   (Int32)
                    // -----------------------------------

                    drogueRun             = null;
                    drogueRun             = GetFilledRandomDrogueRun("");
                    drogueRun.DrogueRunID = 0;
                    drogueRunService.Update(drogueRun);
                    Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "DrogueRunID"), drogueRun.ValidationResults.FirstOrDefault().ErrorMessage);

                    drogueRun             = null;
                    drogueRun             = GetFilledRandomDrogueRun("");
                    drogueRun.DrogueRunID = 10000000;
                    drogueRunService.Update(drogueRun);
                    Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "DrogueRun", "DrogueRunID", drogueRun.DrogueRunID.ToString()), drogueRun.ValidationResults.FirstOrDefault().ErrorMessage);


                    // -----------------------------------
                    // Is NOT Nullable
                    // [CSSPExist(ExistTypeName = "TVItem", ExistPlurial = "s", ExistFieldID = "TVItemID", AllowableTVtypeList = Subsector)]
                    // drogueRun.SubsectorTVItemID   (Int32)
                    // -----------------------------------

                    drogueRun = null;
                    drogueRun = GetFilledRandomDrogueRun("");
                    drogueRun.SubsectorTVItemID = 0;
                    drogueRunService.Add(drogueRun);
                    Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "SubsectorTVItemID", drogueRun.SubsectorTVItemID.ToString()), drogueRun.ValidationResults.FirstOrDefault().ErrorMessage);

                    drogueRun = null;
                    drogueRun = GetFilledRandomDrogueRun("");
                    drogueRun.SubsectorTVItemID = 1;
                    drogueRunService.Add(drogueRun);
                    Assert.AreEqual(string.Format(CSSPServicesRes._IsNotOfType_, "SubsectorTVItemID", "Subsector"), drogueRun.ValidationResults.FirstOrDefault().ErrorMessage);


                    // -----------------------------------
                    // Is NOT Nullable
                    // [Range(0, 100)]
                    // drogueRun.DrogueNumber   (Int32)
                    // -----------------------------------

                    drogueRun = null;
                    drogueRun = GetFilledRandomDrogueRun("");
                    drogueRun.DrogueNumber = -1;
                    Assert.AreEqual(false, drogueRunService.Add(drogueRun));
                    Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "DrogueNumber", "0", "100"), drogueRun.ValidationResults.FirstOrDefault().ErrorMessage);
                    Assert.AreEqual(count, drogueRunService.GetDrogueRunList().Count());
                    drogueRun = null;
                    drogueRun = GetFilledRandomDrogueRun("");
                    drogueRun.DrogueNumber = 101;
                    Assert.AreEqual(false, drogueRunService.Add(drogueRun));
                    Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "DrogueNumber", "0", "100"), drogueRun.ValidationResults.FirstOrDefault().ErrorMessage);
                    Assert.AreEqual(count, drogueRunService.GetDrogueRunList().Count());

                    // -----------------------------------
                    // Is NOT Nullable
                    // [CSSPEnumType]
                    // drogueRun.DrogueType   (DrogueTypeEnum)
                    // -----------------------------------

                    drogueRun            = null;
                    drogueRun            = GetFilledRandomDrogueRun("");
                    drogueRun.DrogueType = (DrogueTypeEnum)1000000;
                    drogueRunService.Add(drogueRun);
                    Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "DrogueType"), drogueRun.ValidationResults.FirstOrDefault().ErrorMessage);


                    // -----------------------------------
                    // Is NOT Nullable
                    // [CSSPAfter(Year = 1980)]
                    // drogueRun.RunStartDateTime   (DateTime)
                    // -----------------------------------

                    drogueRun = null;
                    drogueRun = GetFilledRandomDrogueRun("");
                    drogueRun.RunStartDateTime = new DateTime();
                    drogueRunService.Add(drogueRun);
                    Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "RunStartDateTime"), drogueRun.ValidationResults.FirstOrDefault().ErrorMessage);
                    drogueRun = null;
                    drogueRun = GetFilledRandomDrogueRun("");
                    drogueRun.RunStartDateTime = new DateTime(1979, 1, 1);
                    drogueRunService.Add(drogueRun);
                    Assert.AreEqual(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "RunStartDateTime", "1980"), drogueRun.ValidationResults.FirstOrDefault().ErrorMessage);

                    // -----------------------------------
                    // Is NOT Nullable
                    // drogueRun.IsRisingTide   (Boolean)
                    // -----------------------------------


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

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

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

                    drogueRun = null;
                    drogueRun = GetFilledRandomDrogueRun("");
                    drogueRun.LastUpdateContactTVItemID = 0;
                    drogueRunService.Add(drogueRun);
                    Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "LastUpdateContactTVItemID", drogueRun.LastUpdateContactTVItemID.ToString()), drogueRun.ValidationResults.FirstOrDefault().ErrorMessage);

                    drogueRun = null;
                    drogueRun = GetFilledRandomDrogueRun("");
                    drogueRun.LastUpdateContactTVItemID = 1;
                    drogueRunService.Add(drogueRun);
                    Assert.AreEqual(string.Format(CSSPServicesRes._IsNotOfType_, "LastUpdateContactTVItemID", "Contact"), drogueRun.ValidationResults.FirstOrDefault().ErrorMessage);


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

                    // No testing requied

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

                    // No testing requied
                }
            }
        }