Beispiel #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 Delete([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.Delete(drogueRunPosition))
                {
                    return BadRequest(String.Join("|||", drogueRunPosition.ValidationResults));
                }
                else
                {
                    drogueRunPosition.ValidationResults = null;
                    return Ok(drogueRunPosition);
                }
            }
        }