Example #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());
                }
            }
        }
Example #2
0
        public IHttpActionResult Post([FromBody] DrogueRun drogueRun, [FromUri] string lang = "en")
        {
            using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
            {
                DrogueRunService drogueRunService = new DrogueRunService(new Query()
                {
                    Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en)
                }, db, ContactID);

                if (!drogueRunService.Add(drogueRun))
                {
                    return(BadRequest(String.Join("|||", drogueRun.ValidationResults)));
                }
                else
                {
                    drogueRun.ValidationResults = null;
                    return(Created <DrogueRun>(new Uri(Request.RequestUri, drogueRun.DrogueRunID.ToString()), drogueRun));
                }
            }
        }
Example #3
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
                }
            }
        }