Пример #1
0
        public MikeScenarioResultModel PostDeleteMikeScenarioResultWithMikeScenarioTVItemIDDB(int MikeScenarioTVItemID)
        {
            ContactOK contactOK = IsContactOK();

            if (!string.IsNullOrEmpty(contactOK.Error))
            {
                return(ReturnMikeScenarioResultError(contactOK.Error));
            }

            MikeScenarioResult mikeScenarioResultToDelete = GetMikeScenarioResultWithMikeScenarioTVItemIDDB(MikeScenarioTVItemID);

            if (mikeScenarioResultToDelete == null)
            {
                return(ReturnMikeScenarioResultError(string.Format(ServiceRes.CouldNotFind_ToDelete, ServiceRes.MikeScenarioResult)));
            }

            db.MikeScenarioResults.Remove(mikeScenarioResultToDelete);
            string retStr = DoDeleteChanges();

            if (!string.IsNullOrWhiteSpace(retStr))
            {
                return(ReturnMikeScenarioResultError(retStr));
            }

            return(ReturnMikeScenarioResultError(""));
        }
Пример #2
0
        public MikeScenarioResult GetMikeScenarioResultWithMikeScenarioTVItemIDDB(int MikeScenarioTVItemID)
        {
            MikeScenarioResult mikeScenarioResult = (from c in db.MikeScenarioResults
                                                     where c.MikeScenarioTVItemID == MikeScenarioTVItemID
                                                     select c).FirstOrDefault <MikeScenarioResult>();

            return(mikeScenarioResult);
        }
        public void MikeScenarioResult_Controller_Put_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    MikeScenarioResultController mikeScenarioResultController = new MikeScenarioResultController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(mikeScenarioResultController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, mikeScenarioResultController.DatabaseType);

                    MikeScenarioResult mikeScenarioResultLast = new MikeScenarioResult();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
                    {
                        Query query = new Query();
                        query.Language = LanguageRequest;

                        MikeScenarioResultService mikeScenarioResultService = new MikeScenarioResultService(query, db, ContactID);
                        mikeScenarioResultLast = (from c in db.MikeScenarioResults select c).FirstOrDefault();
                    }

                    // ok with MikeScenarioResult info
                    IHttpActionResult jsonRet = mikeScenarioResultController.GetMikeScenarioResultWithID(mikeScenarioResultLast.MikeScenarioResultID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <MikeScenarioResult> Ret = jsonRet as OkNegotiatedContentResult <MikeScenarioResult>;
                    MikeScenarioResult mikeScenarioResultRet           = Ret.Content;
                    Assert.AreEqual(mikeScenarioResultLast.MikeScenarioResultID, mikeScenarioResultRet.MikeScenarioResultID);

                    BadRequestErrorMessageResult badRequest = jsonRet as BadRequestErrorMessageResult;
                    Assert.IsNull(badRequest);

                    // Put to return success
                    IHttpActionResult jsonRet2 = mikeScenarioResultController.Put(mikeScenarioResultRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet2);

                    OkNegotiatedContentResult <MikeScenarioResult> mikeScenarioResultRet2 = jsonRet2 as OkNegotiatedContentResult <MikeScenarioResult>;
                    Assert.IsNotNull(mikeScenarioResultRet2);

                    BadRequestErrorMessageResult badRequest2 = jsonRet2 as BadRequestErrorMessageResult;
                    Assert.IsNull(badRequest2);

                    // Put to return CSSPError because MikeScenarioResultID of 0 does not exist
                    mikeScenarioResultRet.MikeScenarioResultID = 0;
                    IHttpActionResult jsonRet3 = mikeScenarioResultController.Put(mikeScenarioResultRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet3);

                    OkNegotiatedContentResult <MikeScenarioResult> mikeScenarioResultRet3 = jsonRet3 as OkNegotiatedContentResult <MikeScenarioResult>;
                    Assert.IsNull(mikeScenarioResultRet3);

                    BadRequestErrorMessageResult badRequest3 = jsonRet3 as BadRequestErrorMessageResult;
                    Assert.IsNotNull(badRequest3);
                }
            }
        }
Пример #4
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());
                }
            }
        }
Пример #5
0
        public MikeScenarioResultModel PostUpdateMikeScenarioResultDB(MikeScenarioResultModel mikeScenarioResultModel)
        {
            string retStr = MikeScenarioResultModelOK(mikeScenarioResultModel);

            if (!string.IsNullOrEmpty(retStr))
            {
                return(ReturnMikeScenarioResultError(retStr));
            }

            ContactOK contactOK = IsContactOK();

            if (!string.IsNullOrEmpty(contactOK.Error))
            {
                return(ReturnMikeScenarioResultError(contactOK.Error));
            }

            MikeScenarioResult mikeScenarioResultToUpdate = GetMikeScenarioResultWithMikeScenarioResultIDDB(mikeScenarioResultModel.MikeScenarioResultID);

            if (mikeScenarioResultToUpdate == null)
            {
                return(ReturnMikeScenarioResultError(string.Format(ServiceRes.CouldNotFind_ToUpdate, ServiceRes.MikeScenarioResult)));
            }

            TVItemModel tvItemModelMikeScenarioResult = _TVItemService.GetParentTVItemModelWithTVItemIDForLocationDB(mikeScenarioResultModel.MikeScenarioTVItemID);

            if (!string.IsNullOrWhiteSpace(tvItemModelMikeScenarioResult.Error))
            {
                return(ReturnMikeScenarioResultError(tvItemModelMikeScenarioResult.Error));
            }

            retStr = FillMikeScenarioResult(mikeScenarioResultToUpdate, mikeScenarioResultModel, contactOK);
            if (!string.IsNullOrWhiteSpace(retStr))
            {
                return(ReturnMikeScenarioResultError(retStr));
            }

            using (TransactionScope ts = new TransactionScope())
            {
                retStr = DoUpdateChanges();
                if (!string.IsNullOrWhiteSpace(retStr))
                {
                    return(ReturnMikeScenarioResultError(retStr));
                }

                ts.Complete();
            }

            return(GetMikeScenarioResultModelWithMikeScenarioResultIDDB(mikeScenarioResultToUpdate.MikeScenarioResultID));
        }
        public IHttpActionResult GetMikeScenarioResultWithID([FromUri] int MikeScenarioResultID, [FromUri] string lang = "en", [FromUri] string extra = "")
        {
            using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
            {
                MikeScenarioResultService mikeScenarioResultService = new MikeScenarioResultService(new Query()
                {
                    Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en)
                }, db, ContactID);

                mikeScenarioResultService.Query = mikeScenarioResultService.FillQuery(typeof(MikeScenarioResult), lang, 0, 1, "", "", extra);

                if (mikeScenarioResultService.Query.Extra == "A")
                {
                    MikeScenarioResultExtraA mikeScenarioResultExtraA = new MikeScenarioResultExtraA();
                    mikeScenarioResultExtraA = mikeScenarioResultService.GetMikeScenarioResultExtraAWithMikeScenarioResultID(MikeScenarioResultID);

                    if (mikeScenarioResultExtraA == null)
                    {
                        return(NotFound());
                    }

                    return(Ok(mikeScenarioResultExtraA));
                }
                else if (mikeScenarioResultService.Query.Extra == "B")
                {
                    MikeScenarioResultExtraB mikeScenarioResultExtraB = new MikeScenarioResultExtraB();
                    mikeScenarioResultExtraB = mikeScenarioResultService.GetMikeScenarioResultExtraBWithMikeScenarioResultID(MikeScenarioResultID);

                    if (mikeScenarioResultExtraB == null)
                    {
                        return(NotFound());
                    }

                    return(Ok(mikeScenarioResultExtraB));
                }
                else
                {
                    MikeScenarioResult mikeScenarioResult = new MikeScenarioResult();
                    mikeScenarioResult = mikeScenarioResultService.GetMikeScenarioResultWithMikeScenarioResultID(MikeScenarioResultID);

                    if (mikeScenarioResult == null)
                    {
                        return(NotFound());
                    }

                    return(Ok(mikeScenarioResult));
                }
            }
        }
        /// <summary>
        /// Updates an [MikeScenarioResult](CSSPModels.MikeScenarioResult.html) item in CSSPDB
        /// </summary>
        /// <param name="mikeScenarioResult">Is the MikeScenarioResult item the client want to add to CSSPDB. What's important here is the MikeScenarioResultID</param>
        /// <returns>true if MikeScenarioResult item was updated to CSSPDB, false if an error happened during the DB requested transtaction</returns>
        public bool Update(MikeScenarioResult mikeScenarioResult)
        {
            mikeScenarioResult.ValidationResults = Validate(new ValidationContext(mikeScenarioResult), ActionDBTypeEnum.Update);
            if (mikeScenarioResult.ValidationResults.Count() > 0)
            {
                return(false);
            }

            db.MikeScenarioResults.Update(mikeScenarioResult);

            if (!TryToSave(mikeScenarioResult))
            {
                return(false);
            }

            return(true);
        }
Пример #8
0
        // Fill
        public string FillMikeScenarioResult(MikeScenarioResult mikeScenarioResult, MikeScenarioResultModel mikeScenarioResultModel, ContactOK contactOK)
        {
            mikeScenarioResult.DBCommand            = (int)mikeScenarioResultModel.DBCommand;
            mikeScenarioResult.MikeScenarioTVItemID = mikeScenarioResultModel.MikeScenarioTVItemID;
            mikeScenarioResult.MikeResultsJSON      = mikeScenarioResultModel.MikeResultsJSON;
            mikeScenarioResult.LastUpdateDate_UTC   = DateTime.UtcNow;
            if (contactOK == null)
            {
                mikeScenarioResult.LastUpdateContactTVItemID = 2;
            }
            else
            {
                mikeScenarioResult.LastUpdateContactTVItemID = contactOK.ContactTVItemID;
            }

            return("");
        }
        /// <summary>
        /// Tries to execute the CSSPDB transaction (add/delete/update) on an [MikeScenarioResult](CSSPModels.MikeScenarioResult.html) item
        /// </summary>
        /// <param name="mikeScenarioResult">Is the MikeScenarioResult item the client want to add to CSSPDB. What's important here is the MikeScenarioResultID</param>
        /// <returns>true if MikeScenarioResult item was updated to CSSPDB, false if an error happened during the DB requested transtaction</returns>
        private bool TryToSave(MikeScenarioResult mikeScenarioResult)
        {
            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException ex)
            {
                mikeScenarioResult.ValidationResults = new List <ValidationResult>()
                {
                    new ValidationResult(ex.Message + (ex.InnerException != null ? " Inner: " + ex.InnerException.Message : ""))
                }.AsEnumerable();
                return(false);
            }

            return(true);
        }
Пример #10
0
        // Post AppTask

        // Post Normal
        public MikeScenarioResultModel PostAddMikeScenarioResultDB(MikeScenarioResultModel mikeScenarioResultModel)
        {
            string retStr = MikeScenarioResultModelOK(mikeScenarioResultModel);

            if (!string.IsNullOrWhiteSpace(retStr))
            {
                return(ReturnMikeScenarioResultError(retStr));
            }

            ContactOK contactOK = IsContactOK();

            if (!string.IsNullOrEmpty(contactOK.Error))
            {
                return(ReturnMikeScenarioResultError(contactOK.Error));
            }

            TVItemModel tvItemModelMikeScenarioResult = _TVItemService.GetTVItemModelWithTVItemIDDB(mikeScenarioResultModel.MikeScenarioTVItemID);

            if (!string.IsNullOrWhiteSpace(tvItemModelMikeScenarioResult.Error))
            {
                return(ReturnMikeScenarioResultError(tvItemModelMikeScenarioResult.Error));
            }

            MikeScenarioResult mikeScenarioResultNew = new MikeScenarioResult();

            retStr = FillMikeScenarioResult(mikeScenarioResultNew, mikeScenarioResultModel, contactOK);
            if (!string.IsNullOrWhiteSpace(retStr))
            {
                return(ReturnMikeScenarioResultError(retStr));
            }

            using (TransactionScope ts = new TransactionScope())
            {
                db.MikeScenarioResults.Add(mikeScenarioResultNew);
                retStr = DoAddChanges();
                if (!string.IsNullOrWhiteSpace(retStr))
                {
                    return(ReturnMikeScenarioResultError(retStr));
                }

                ts.Complete();
            }

            return(GetMikeScenarioResultModelWithMikeScenarioResultIDDB(mikeScenarioResultNew.MikeScenarioResultID));
        }
        public void MikeScenarioResult_Controller_GetMikeScenarioResultWithID_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    MikeScenarioResultController mikeScenarioResultController = new MikeScenarioResultController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(mikeScenarioResultController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, mikeScenarioResultController.DatabaseType);

                    MikeScenarioResult mikeScenarioResultFirst = new MikeScenarioResult();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
                    {
                        MikeScenarioResultService mikeScenarioResultService = new MikeScenarioResultService(new Query(), db, ContactID);
                        mikeScenarioResultFirst = (from c in db.MikeScenarioResults select c).FirstOrDefault();
                    }

                    // ok with MikeScenarioResult info
                    IHttpActionResult jsonRet = mikeScenarioResultController.GetMikeScenarioResultWithID(mikeScenarioResultFirst.MikeScenarioResultID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <MikeScenarioResult> Ret = jsonRet as OkNegotiatedContentResult <MikeScenarioResult>;
                    MikeScenarioResult mikeScenarioResultRet           = Ret.Content;
                    Assert.AreEqual(mikeScenarioResultFirst.MikeScenarioResultID, mikeScenarioResultRet.MikeScenarioResultID);

                    BadRequestErrorMessageResult badRequest = jsonRet as BadRequestErrorMessageResult;
                    Assert.IsNull(badRequest);

                    // Not Found
                    IHttpActionResult jsonRet2 = mikeScenarioResultController.GetMikeScenarioResultWithID(0);
                    Assert.IsNotNull(jsonRet2);

                    OkNegotiatedContentResult <MikeScenarioResult> mikeScenarioResultRet2 = jsonRet2 as OkNegotiatedContentResult <MikeScenarioResult>;
                    Assert.IsNull(mikeScenarioResultRet2);

                    NotFoundResult notFoundRequest = jsonRet2 as NotFoundResult;
                    Assert.IsNotNull(notFoundRequest);
                }
            }
        }
        public IHttpActionResult Delete([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.Delete(mikeScenarioResult))
                {
                    return(BadRequest(String.Join("|||", mikeScenarioResult.ValidationResults)));
                }
                else
                {
                    mikeScenarioResult.ValidationResults = null;
                    return(Ok(mikeScenarioResult));
                }
            }
        }
Пример #13
0
        public void GetMikeScenarioResultList_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);
                    MikeScenarioResult mikeScenarioResult = (from c in dbTestDB.MikeScenarioResults select c).FirstOrDefault();
                    Assert.IsNotNull(mikeScenarioResult);

                    List <MikeScenarioResult> mikeScenarioResultDirectQueryList = new List <MikeScenarioResult>();
                    mikeScenarioResultDirectQueryList = (from c in dbTestDB.MikeScenarioResults select c).Take(200).ToList();

                    foreach (string extra in new List <string>()
                    {
                        null, "A", "B", "C", "D", "E"
                    })
                    {
                        mikeScenarioResultService.Query.Extra = extra;

                        if (string.IsNullOrWhiteSpace(extra))
                        {
                            List <MikeScenarioResult> mikeScenarioResultList = new List <MikeScenarioResult>();
                            mikeScenarioResultList = mikeScenarioResultService.GetMikeScenarioResultList().ToList();
                            CheckMikeScenarioResultFields(mikeScenarioResultList);
                        }
                        else
                        {
                            //Assert.AreEqual(true, false);
                        }
                    }
                }
            }
        }
Пример #14
0
        private MikeScenarioResult GetFilledRandomMikeScenarioResult(string OmitPropName)
        {
            MikeScenarioResult mikeScenarioResult = new MikeScenarioResult();

            if (OmitPropName != "MikeScenarioTVItemID")
            {
                mikeScenarioResult.MikeScenarioTVItemID = 51;
            }
            if (OmitPropName != "MikeResultsJSON")
            {
                mikeScenarioResult.MikeResultsJSON = GetRandomString("", 20);
            }
            if (OmitPropName != "LastUpdateDate_UTC")
            {
                mikeScenarioResult.LastUpdateDate_UTC = new DateTime(2005, 3, 6);
            }
            if (OmitPropName != "LastUpdateContactTVItemID")
            {
                mikeScenarioResult.LastUpdateContactTVItemID = 2;
            }

            return(mikeScenarioResult);
        }
Пример #15
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
                }
            }
        }
        public void MikeScenarioResult_Controller_Post_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    MikeScenarioResultController mikeScenarioResultController = new MikeScenarioResultController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(mikeScenarioResultController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, mikeScenarioResultController.DatabaseType);

                    MikeScenarioResult mikeScenarioResultLast = new MikeScenarioResult();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
                    {
                        Query query = new Query();
                        query.Language = LanguageRequest;
                        query.Asc      = "";
                        query.Desc     = "";

                        MikeScenarioResultService mikeScenarioResultService = new MikeScenarioResultService(query, db, ContactID);
                        mikeScenarioResultLast = (from c in db.MikeScenarioResults select c).FirstOrDefault();
                    }

                    // ok with MikeScenarioResult info
                    IHttpActionResult jsonRet = mikeScenarioResultController.GetMikeScenarioResultWithID(mikeScenarioResultLast.MikeScenarioResultID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <MikeScenarioResult> Ret = jsonRet as OkNegotiatedContentResult <MikeScenarioResult>;
                    MikeScenarioResult mikeScenarioResultRet           = Ret.Content;
                    Assert.AreEqual(mikeScenarioResultLast.MikeScenarioResultID, mikeScenarioResultRet.MikeScenarioResultID);

                    BadRequestErrorMessageResult badRequest = jsonRet as BadRequestErrorMessageResult;
                    Assert.IsNull(badRequest);

                    // Post to return CSSPError because MikeScenarioResultID exist
                    IHttpActionResult jsonRet2 = mikeScenarioResultController.Post(mikeScenarioResultRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet2);

                    OkNegotiatedContentResult <MikeScenarioResult> mikeScenarioResultRet2 = jsonRet2 as OkNegotiatedContentResult <MikeScenarioResult>;
                    Assert.IsNull(mikeScenarioResultRet2);

                    BadRequestErrorMessageResult badRequest2 = jsonRet2 as BadRequestErrorMessageResult;
                    Assert.IsNotNull(badRequest2);

                    // Post to return newly added MikeScenarioResult
                    mikeScenarioResultRet.MikeScenarioResultID      = 0;
                    mikeScenarioResultController.Request            = new System.Net.Http.HttpRequestMessage();
                    mikeScenarioResultController.Request.RequestUri = new System.Uri("http://localhost:5000/api/mikeScenarioResult");
                    IHttpActionResult jsonRet3 = mikeScenarioResultController.Post(mikeScenarioResultRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet3);

                    CreatedNegotiatedContentResult <MikeScenarioResult> mikeScenarioResultRet3 = jsonRet3 as CreatedNegotiatedContentResult <MikeScenarioResult>;
                    Assert.IsNotNull(mikeScenarioResultRet3);

                    BadRequestErrorMessageResult badRequest3 = jsonRet3 as BadRequestErrorMessageResult;
                    Assert.IsNull(badRequest3);

                    IHttpActionResult jsonRet4 = mikeScenarioResultController.Delete(mikeScenarioResultRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet4);

                    OkNegotiatedContentResult <MikeScenarioResult> mikeScenarioResultRet4 = jsonRet4 as OkNegotiatedContentResult <MikeScenarioResult>;
                    Assert.IsNotNull(mikeScenarioResultRet4);

                    BadRequestErrorMessageResult badRequest4 = jsonRet4 as BadRequestErrorMessageResult;
                    Assert.IsNull(badRequest4);
                }
            }
        }
        public void MikeScenarioResult_Controller_GetMikeScenarioResultList_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    MikeScenarioResultController mikeScenarioResultController = new MikeScenarioResultController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(mikeScenarioResultController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, mikeScenarioResultController.DatabaseType);

                    MikeScenarioResult mikeScenarioResultFirst = new MikeScenarioResult();
                    int   count = -1;
                    Query query = new Query();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                    {
                        MikeScenarioResultService mikeScenarioResultService = new MikeScenarioResultService(query, db, ContactID);
                        mikeScenarioResultFirst = (from c in db.MikeScenarioResults select c).FirstOrDefault();
                        count = (from c in db.MikeScenarioResults select c).Count();
                        count = (query.Take > count ? count : query.Take);
                    }

                    // ok with MikeScenarioResult info
                    IHttpActionResult jsonRet = mikeScenarioResultController.GetMikeScenarioResultList();
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <List <MikeScenarioResult> > ret = jsonRet as OkNegotiatedContentResult <List <MikeScenarioResult> >;
                    Assert.AreEqual(mikeScenarioResultFirst.MikeScenarioResultID, ret.Content[0].MikeScenarioResultID);
                    Assert.AreEqual((count > query.Take ? query.Take : count), ret.Content.Count);

                    List <MikeScenarioResult> mikeScenarioResultList = new List <MikeScenarioResult>();
                    count = -1;
                    query = new Query();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                    {
                        MikeScenarioResultService mikeScenarioResultService = new MikeScenarioResultService(query, db, ContactID);
                        mikeScenarioResultList = (from c in db.MikeScenarioResults select c).OrderBy(c => c.MikeScenarioResultID).Skip(0).Take(2).ToList();
                        count = (from c in db.MikeScenarioResults select c).Count();
                    }

                    if (count > 0)
                    {
                        query.Skip = 0;
                        query.Take = 5;
                        count      = (query.Take > count ? query.Take : count);

                        // ok with MikeScenarioResult info
                        jsonRet = mikeScenarioResultController.GetMikeScenarioResultList(query.Language.ToString(), query.Skip, query.Take);
                        Assert.IsNotNull(jsonRet);

                        ret = jsonRet as OkNegotiatedContentResult <List <MikeScenarioResult> >;
                        Assert.AreEqual(mikeScenarioResultList[0].MikeScenarioResultID, ret.Content[0].MikeScenarioResultID);
                        Assert.AreEqual((count > query.Take ? query.Take : count), ret.Content.Count);

                        if (count > 1)
                        {
                            query.Skip = 1;
                            query.Take = 5;
                            count      = (query.Take > count ? query.Take : count);

                            // ok with MikeScenarioResult info
                            IHttpActionResult jsonRet2 = mikeScenarioResultController.GetMikeScenarioResultList(query.Language.ToString(), query.Skip, query.Take);
                            Assert.IsNotNull(jsonRet2);

                            OkNegotiatedContentResult <List <MikeScenarioResult> > ret2 = jsonRet2 as OkNegotiatedContentResult <List <MikeScenarioResult> >;
                            Assert.AreEqual(mikeScenarioResultList[1].MikeScenarioResultID, ret2.Content[0].MikeScenarioResultID);
                            Assert.AreEqual((count > query.Take ? query.Take : count), ret2.Content.Count);
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Validate function for all MikeScenarioResultService commands
        /// </summary>
        /// <param name="validationContext">System.ComponentModel.DataAnnotations.ValidationContext (Describes the context in which a validation check is performed.)</param>
        /// <param name="actionDBType">[ActionDBTypeEnum] (CSSPEnums.ActionDBTypeEnum.html) action type to validate</param>
        /// <returns>IEnumerable of ValidationResult (Where ValidationResult is a container for the results of a validation request.)</returns>
        private IEnumerable <ValidationResult> Validate(ValidationContext validationContext, ActionDBTypeEnum actionDBType)
        {
            string             retStr             = "";
            Enums              enums              = new Enums(LanguageRequest);
            MikeScenarioResult mikeScenarioResult = validationContext.ObjectInstance as MikeScenarioResult;

            mikeScenarioResult.HasErrors = false;

            if (actionDBType == ActionDBTypeEnum.Update || actionDBType == ActionDBTypeEnum.Delete)
            {
                if (mikeScenarioResult.MikeScenarioResultID == 0)
                {
                    mikeScenarioResult.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "MikeScenarioResultID"), new[] { "MikeScenarioResultID" }));
                }

                if (!(from c in db.MikeScenarioResults select c).Where(c => c.MikeScenarioResultID == mikeScenarioResult.MikeScenarioResultID).Any())
                {
                    mikeScenarioResult.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "MikeScenarioResult", "MikeScenarioResultID", mikeScenarioResult.MikeScenarioResultID.ToString()), new[] { "MikeScenarioResultID" }));
                }
            }

            TVItem TVItemMikeScenarioTVItemID = (from c in db.TVItems where c.TVItemID == mikeScenarioResult.MikeScenarioTVItemID select c).FirstOrDefault();

            if (TVItemMikeScenarioTVItemID == null)
            {
                mikeScenarioResult.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "MikeScenarioTVItemID", mikeScenarioResult.MikeScenarioTVItemID.ToString()), new[] { "MikeScenarioTVItemID" }));
            }
            else
            {
                List <TVTypeEnum> AllowableTVTypes = new List <TVTypeEnum>()
                {
                    TVTypeEnum.MikeScenario,
                };
                if (!AllowableTVTypes.Contains(TVItemMikeScenarioTVItemID.TVType))
                {
                    mikeScenarioResult.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes._IsNotOfType_, "MikeScenarioTVItemID", "MikeScenario"), new[] { "MikeScenarioTVItemID" }));
                }
            }

            //MikeResultsJSON has no StringLength Attribute

            if (mikeScenarioResult.LastUpdateDate_UTC.Year == 1)
            {
                mikeScenarioResult.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "LastUpdateDate_UTC"), new[] { "LastUpdateDate_UTC" }));
            }
            else
            {
                if (mikeScenarioResult.LastUpdateDate_UTC.Year < 1980)
                {
                    mikeScenarioResult.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "LastUpdateDate_UTC", "1980"), new[] { "LastUpdateDate_UTC" }));
                }
            }

            TVItem TVItemLastUpdateContactTVItemID = (from c in db.TVItems where c.TVItemID == mikeScenarioResult.LastUpdateContactTVItemID select c).FirstOrDefault();

            if (TVItemLastUpdateContactTVItemID == null)
            {
                mikeScenarioResult.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "LastUpdateContactTVItemID", mikeScenarioResult.LastUpdateContactTVItemID.ToString()), new[] { "LastUpdateContactTVItemID" }));
            }
            else
            {
                List <TVTypeEnum> AllowableTVTypes = new List <TVTypeEnum>()
                {
                    TVTypeEnum.Contact,
                };
                if (!AllowableTVTypes.Contains(TVItemLastUpdateContactTVItemID.TVType))
                {
                    mikeScenarioResult.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes._IsNotOfType_, "LastUpdateContactTVItemID", "Contact"), new[] { "LastUpdateContactTVItemID" }));
                }
            }

            retStr = "";      // added to stop compiling CSSPError
            if (retStr != "") // will never be true
            {
                mikeScenarioResult.HasErrors = true;
                yield return(new ValidationResult("AAA", new[] { "AAA" }));
            }
        }
 public MikeScenarioResultTest()
 {
     mikeScenarioResult       = new MikeScenarioResult();
     mikeScenarioResultExtraA = new MikeScenarioResultExtraA();
     mikeScenarioResultExtraB = new MikeScenarioResultExtraB();
 }