Esempio n. 1
0
        public void MikeScenarioResult_CRUD_Test()
        {
            foreach (CultureInfo culture in AllowableCulture)
            {
                ChangeCulture(culture);

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

                    MikeScenarioResult mikeScenarioResult = GetFilledRandomMikeScenarioResult("");

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

                    count = mikeScenarioResultService.GetMikeScenarioResultList().Count();

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

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

                if (!mikeScenarioResultService.Update(mikeScenarioResult))
                {
                    return(BadRequest(String.Join("|||", mikeScenarioResult.ValidationResults)));
                }
                else
                {
                    mikeScenarioResult.ValidationResults = null;
                    return(Ok(mikeScenarioResult));
                }
            }
        }
Esempio n. 3
0
        public void MikeScenarioResult_Properties_Test()
        {
            foreach (CultureInfo culture in AllowableCulture)
            {
                ChangeCulture(culture);

                using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                {
                    MikeScenarioResultService mikeScenarioResultService = new MikeScenarioResultService(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 = mikeScenarioResultService.GetMikeScenarioResultList().Count();

                    MikeScenarioResult mikeScenarioResult = GetFilledRandomMikeScenarioResult("");

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


                    // -----------------------------------
                    // [Key]
                    // Is NOT Nullable
                    // mikeScenarioResult.MikeScenarioResultID   (Int32)
                    // -----------------------------------

                    mikeScenarioResult = null;
                    mikeScenarioResult = GetFilledRandomMikeScenarioResult("");
                    mikeScenarioResult.MikeScenarioResultID = 0;
                    mikeScenarioResultService.Update(mikeScenarioResult);
                    Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "MikeScenarioResultID"), mikeScenarioResult.ValidationResults.FirstOrDefault().ErrorMessage);

                    mikeScenarioResult = null;
                    mikeScenarioResult = GetFilledRandomMikeScenarioResult("");
                    mikeScenarioResult.MikeScenarioResultID = 10000000;
                    mikeScenarioResultService.Update(mikeScenarioResult);
                    Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "MikeScenarioResult", "MikeScenarioResultID", mikeScenarioResult.MikeScenarioResultID.ToString()), mikeScenarioResult.ValidationResults.FirstOrDefault().ErrorMessage);


                    // -----------------------------------
                    // Is NOT Nullable
                    // [CSSPExist(ExistTypeName = "TVItem", ExistPlurial = "s", ExistFieldID = "TVItemID", AllowableTVtypeList = MikeScenario)]
                    // mikeScenarioResult.MikeScenarioTVItemID   (Int32)
                    // -----------------------------------

                    mikeScenarioResult = null;
                    mikeScenarioResult = GetFilledRandomMikeScenarioResult("");
                    mikeScenarioResult.MikeScenarioTVItemID = 0;
                    mikeScenarioResultService.Add(mikeScenarioResult);
                    Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "MikeScenarioTVItemID", mikeScenarioResult.MikeScenarioTVItemID.ToString()), mikeScenarioResult.ValidationResults.FirstOrDefault().ErrorMessage);

                    mikeScenarioResult = null;
                    mikeScenarioResult = GetFilledRandomMikeScenarioResult("");
                    mikeScenarioResult.MikeScenarioTVItemID = 1;
                    mikeScenarioResultService.Add(mikeScenarioResult);
                    Assert.AreEqual(string.Format(CSSPServicesRes._IsNotOfType_, "MikeScenarioTVItemID", "MikeScenario"), mikeScenarioResult.ValidationResults.FirstOrDefault().ErrorMessage);


                    // -----------------------------------
                    // Is Nullable
                    // mikeScenarioResult.MikeResultsJSON   (String)
                    // -----------------------------------


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

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

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

                    mikeScenarioResult = null;
                    mikeScenarioResult = GetFilledRandomMikeScenarioResult("");
                    mikeScenarioResult.LastUpdateContactTVItemID = 0;
                    mikeScenarioResultService.Add(mikeScenarioResult);
                    Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "LastUpdateContactTVItemID", mikeScenarioResult.LastUpdateContactTVItemID.ToString()), mikeScenarioResult.ValidationResults.FirstOrDefault().ErrorMessage);

                    mikeScenarioResult = null;
                    mikeScenarioResult = GetFilledRandomMikeScenarioResult("");
                    mikeScenarioResult.LastUpdateContactTVItemID = 1;
                    mikeScenarioResultService.Add(mikeScenarioResult);
                    Assert.AreEqual(string.Format(CSSPServicesRes._IsNotOfType_, "LastUpdateContactTVItemID", "Contact"), mikeScenarioResult.ValidationResults.FirstOrDefault().ErrorMessage);


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

                    // No testing requied

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

                    // No testing requied
                }
            }
        }