Exemplo n.º 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());
                }
            }
        }
Exemplo n.º 2
0
        public IHttpActionResult Delete([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.Delete(drogueRun))
                {
                    return(BadRequest(String.Join("|||", drogueRun.ValidationResults)));
                }
                else
                {
                    drogueRun.ValidationResults = null;
                    return(Ok(drogueRun));
                }
            }
        }