예제 #1
0
        public void DrogueRunPosition_CRUD_Test()
        {
            foreach (CultureInfo culture in AllowableCulture)
            {
                ChangeCulture(culture);

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

                    DrogueRunPosition drogueRunPosition = GetFilledRandomDrogueRunPosition("");

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

                    count = drogueRunPositionService.GetDrogueRunPositionList().Count();

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

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

                if (!drogueRunPositionService.Update(drogueRunPosition))
                {
                    return BadRequest(String.Join("|||", drogueRunPosition.ValidationResults));
                }
                else
                {
                    drogueRunPosition.ValidationResults = null;
                    return Ok(drogueRunPosition);
                }
            }
        }
예제 #3
0
        public void DrogueRunPosition_Properties_Test()
        {
            foreach (CultureInfo culture in AllowableCulture)
            {
                ChangeCulture(culture);

                using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                {
                    DrogueRunPositionService drogueRunPositionService = new DrogueRunPositionService(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 = drogueRunPositionService.GetDrogueRunPositionList().Count();

                    DrogueRunPosition drogueRunPosition = GetFilledRandomDrogueRunPosition("");

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


                    // -----------------------------------
                    // [Key]
                    // Is NOT Nullable
                    // drogueRunPosition.DrogueRunPositionID   (Int32)
                    // -----------------------------------

                    drogueRunPosition = null;
                    drogueRunPosition = GetFilledRandomDrogueRunPosition("");
                    drogueRunPosition.DrogueRunPositionID = 0;
                    drogueRunPositionService.Update(drogueRunPosition);
                    Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "DrogueRunPositionID"), drogueRunPosition.ValidationResults.FirstOrDefault().ErrorMessage);

                    drogueRunPosition = null;
                    drogueRunPosition = GetFilledRandomDrogueRunPosition("");
                    drogueRunPosition.DrogueRunPositionID = 10000000;
                    drogueRunPositionService.Update(drogueRunPosition);
                    Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "DrogueRunPosition", "DrogueRunPositionID", drogueRunPosition.DrogueRunPositionID.ToString()), drogueRunPosition.ValidationResults.FirstOrDefault().ErrorMessage);


                    // -----------------------------------
                    // Is NOT Nullable
                    // [CSSPExist(ExistTypeName = "DrogueRun", ExistPlurial = "s", ExistFieldID = "DrogueRunID", AllowableTVtypeList = )]
                    // drogueRunPosition.DrogueRunID   (Int32)
                    // -----------------------------------

                    drogueRunPosition             = null;
                    drogueRunPosition             = GetFilledRandomDrogueRunPosition("");
                    drogueRunPosition.DrogueRunID = 0;
                    drogueRunPositionService.Add(drogueRunPosition);
                    Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "DrogueRun", "DrogueRunID", drogueRunPosition.DrogueRunID.ToString()), drogueRunPosition.ValidationResults.FirstOrDefault().ErrorMessage);


                    // -----------------------------------
                    // Is NOT Nullable
                    // [Range(0, 100000)]
                    // drogueRunPosition.Ordinal   (Int32)
                    // -----------------------------------

                    drogueRunPosition         = null;
                    drogueRunPosition         = GetFilledRandomDrogueRunPosition("");
                    drogueRunPosition.Ordinal = -1;
                    Assert.AreEqual(false, drogueRunPositionService.Add(drogueRunPosition));
                    Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "Ordinal", "0", "100000"), drogueRunPosition.ValidationResults.FirstOrDefault().ErrorMessage);
                    Assert.AreEqual(count, drogueRunPositionService.GetDrogueRunPositionList().Count());
                    drogueRunPosition         = null;
                    drogueRunPosition         = GetFilledRandomDrogueRunPosition("");
                    drogueRunPosition.Ordinal = 100001;
                    Assert.AreEqual(false, drogueRunPositionService.Add(drogueRunPosition));
                    Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "Ordinal", "0", "100000"), drogueRunPosition.ValidationResults.FirstOrDefault().ErrorMessage);
                    Assert.AreEqual(count, drogueRunPositionService.GetDrogueRunPositionList().Count());

                    // -----------------------------------
                    // Is NOT Nullable
                    // [Range(-180, 180)]
                    // drogueRunPosition.StepLat   (Double)
                    // -----------------------------------

                    //CSSPError: Type not implemented [StepLat]

                    //CSSPError: Type not implemented [StepLat]

                    drogueRunPosition         = null;
                    drogueRunPosition         = GetFilledRandomDrogueRunPosition("");
                    drogueRunPosition.StepLat = -181.0D;
                    Assert.AreEqual(false, drogueRunPositionService.Add(drogueRunPosition));
                    Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "StepLat", "-180", "180"), drogueRunPosition.ValidationResults.FirstOrDefault().ErrorMessage);
                    Assert.AreEqual(count, drogueRunPositionService.GetDrogueRunPositionList().Count());
                    drogueRunPosition         = null;
                    drogueRunPosition         = GetFilledRandomDrogueRunPosition("");
                    drogueRunPosition.StepLat = 181.0D;
                    Assert.AreEqual(false, drogueRunPositionService.Add(drogueRunPosition));
                    Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "StepLat", "-180", "180"), drogueRunPosition.ValidationResults.FirstOrDefault().ErrorMessage);
                    Assert.AreEqual(count, drogueRunPositionService.GetDrogueRunPositionList().Count());

                    // -----------------------------------
                    // Is NOT Nullable
                    // [Range(-90, 90)]
                    // drogueRunPosition.StepLng   (Double)
                    // -----------------------------------

                    //CSSPError: Type not implemented [StepLng]

                    //CSSPError: Type not implemented [StepLng]

                    drogueRunPosition         = null;
                    drogueRunPosition         = GetFilledRandomDrogueRunPosition("");
                    drogueRunPosition.StepLng = -91.0D;
                    Assert.AreEqual(false, drogueRunPositionService.Add(drogueRunPosition));
                    Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "StepLng", "-90", "90"), drogueRunPosition.ValidationResults.FirstOrDefault().ErrorMessage);
                    Assert.AreEqual(count, drogueRunPositionService.GetDrogueRunPositionList().Count());
                    drogueRunPosition         = null;
                    drogueRunPosition         = GetFilledRandomDrogueRunPosition("");
                    drogueRunPosition.StepLng = 91.0D;
                    Assert.AreEqual(false, drogueRunPositionService.Add(drogueRunPosition));
                    Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "StepLng", "-90", "90"), drogueRunPosition.ValidationResults.FirstOrDefault().ErrorMessage);
                    Assert.AreEqual(count, drogueRunPositionService.GetDrogueRunPositionList().Count());

                    // -----------------------------------
                    // Is NOT Nullable
                    // [CSSPAfter(Year = 1980)]
                    // drogueRunPosition.StepDateTime_Local   (DateTime)
                    // -----------------------------------

                    drogueRunPosition = null;
                    drogueRunPosition = GetFilledRandomDrogueRunPosition("");
                    drogueRunPosition.StepDateTime_Local = new DateTime();
                    drogueRunPositionService.Add(drogueRunPosition);
                    Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "StepDateTime_Local"), drogueRunPosition.ValidationResults.FirstOrDefault().ErrorMessage);
                    drogueRunPosition = null;
                    drogueRunPosition = GetFilledRandomDrogueRunPosition("");
                    drogueRunPosition.StepDateTime_Local = new DateTime(1979, 1, 1);
                    drogueRunPositionService.Add(drogueRunPosition);
                    Assert.AreEqual(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "StepDateTime_Local", "1980"), drogueRunPosition.ValidationResults.FirstOrDefault().ErrorMessage);

                    // -----------------------------------
                    // Is NOT Nullable
                    // [Range(0, 10)]
                    // drogueRunPosition.CalculatedSpeed_m_s   (Double)
                    // -----------------------------------

                    //CSSPError: Type not implemented [CalculatedSpeed_m_s]

                    //CSSPError: Type not implemented [CalculatedSpeed_m_s]

                    drogueRunPosition = null;
                    drogueRunPosition = GetFilledRandomDrogueRunPosition("");
                    drogueRunPosition.CalculatedSpeed_m_s = -1.0D;
                    Assert.AreEqual(false, drogueRunPositionService.Add(drogueRunPosition));
                    Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "CalculatedSpeed_m_s", "0", "10"), drogueRunPosition.ValidationResults.FirstOrDefault().ErrorMessage);
                    Assert.AreEqual(count, drogueRunPositionService.GetDrogueRunPositionList().Count());
                    drogueRunPosition = null;
                    drogueRunPosition = GetFilledRandomDrogueRunPosition("");
                    drogueRunPosition.CalculatedSpeed_m_s = 11.0D;
                    Assert.AreEqual(false, drogueRunPositionService.Add(drogueRunPosition));
                    Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "CalculatedSpeed_m_s", "0", "10"), drogueRunPosition.ValidationResults.FirstOrDefault().ErrorMessage);
                    Assert.AreEqual(count, drogueRunPositionService.GetDrogueRunPositionList().Count());

                    // -----------------------------------
                    // Is NOT Nullable
                    // [Range(0, 360)]
                    // drogueRunPosition.CalculatedDirection_deg   (Double)
                    // -----------------------------------

                    //CSSPError: Type not implemented [CalculatedDirection_deg]

                    //CSSPError: Type not implemented [CalculatedDirection_deg]

                    drogueRunPosition = null;
                    drogueRunPosition = GetFilledRandomDrogueRunPosition("");
                    drogueRunPosition.CalculatedDirection_deg = -1.0D;
                    Assert.AreEqual(false, drogueRunPositionService.Add(drogueRunPosition));
                    Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "CalculatedDirection_deg", "0", "360"), drogueRunPosition.ValidationResults.FirstOrDefault().ErrorMessage);
                    Assert.AreEqual(count, drogueRunPositionService.GetDrogueRunPositionList().Count());
                    drogueRunPosition = null;
                    drogueRunPosition = GetFilledRandomDrogueRunPosition("");
                    drogueRunPosition.CalculatedDirection_deg = 361.0D;
                    Assert.AreEqual(false, drogueRunPositionService.Add(drogueRunPosition));
                    Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "CalculatedDirection_deg", "0", "360"), drogueRunPosition.ValidationResults.FirstOrDefault().ErrorMessage);
                    Assert.AreEqual(count, drogueRunPositionService.GetDrogueRunPositionList().Count());

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

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

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

                    drogueRunPosition = null;
                    drogueRunPosition = GetFilledRandomDrogueRunPosition("");
                    drogueRunPosition.LastUpdateContactTVItemID = 0;
                    drogueRunPositionService.Add(drogueRunPosition);
                    Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "LastUpdateContactTVItemID", drogueRunPosition.LastUpdateContactTVItemID.ToString()), drogueRunPosition.ValidationResults.FirstOrDefault().ErrorMessage);

                    drogueRunPosition = null;
                    drogueRunPosition = GetFilledRandomDrogueRunPosition("");
                    drogueRunPosition.LastUpdateContactTVItemID = 1;
                    drogueRunPositionService.Add(drogueRunPosition);
                    Assert.AreEqual(string.Format(CSSPServicesRes._IsNotOfType_, "LastUpdateContactTVItemID", "Contact"), drogueRunPosition.ValidationResults.FirstOrDefault().ErrorMessage);


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

                    // No testing requied

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

                    // No testing requied
                }
            }
        }