Example #1
0
        public BoxModelLanguageModel PostDeleteBoxModelLanguageDB(int BoxModelID, LanguageEnum Language)
        {
            ContactOK contactOK = IsContactOK();

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

            BoxModelLanguage boxModelLanguageToDelete = GetBoxModelLanguageWithBoxModelIDAndLanguageDB(BoxModelID, Language);

            if (boxModelLanguageToDelete == null)
            {
                return(ReturnError(string.Format(ServiceRes.CouldNotFind_ToDelete, ServiceRes.BoxModelLanguage)));
            }

            using (TransactionScope ts = new TransactionScope())
            {
                db.BoxModelLanguages.Remove(boxModelLanguageToDelete);
                string retStr = DoDeleteChanges();
                if (!string.IsNullOrWhiteSpace(retStr))
                {
                    return(ReturnError(retStr));
                }

                LogModel logModel = _LogService.PostAddLogForObj("BoxModelLanguages", boxModelLanguageToDelete.BoxModelLanguageID, LogCommandEnum.Delete, boxModelLanguageToDelete);
                if (!string.IsNullOrWhiteSpace(logModel.Error))
                {
                    return(ReturnError(logModel.Error));
                }

                ts.Complete();
            }
            return(ReturnError(""));
        }
Example #2
0
        // Fill
        public string FillBoxModelLanguageModel(BoxModelLanguage boxModelLanguage, BoxModelLanguageModel boxModelLanguageModel, ContactOK contactOK)
        {
            try
            {
                boxModelLanguage.DBCommand          = (int)boxModelLanguageModel.DBCommand;
                boxModelLanguage.BoxModelID         = boxModelLanguageModel.BoxModelID;
                boxModelLanguage.Language           = (int)boxModelLanguageModel.Language;
                boxModelLanguage.ScenarioName       = boxModelLanguageModel.ScenarioName;
                boxModelLanguage.TranslationStatus  = (int)boxModelLanguageModel.TranslationStatus;
                boxModelLanguage.LastUpdateDate_UTC = DateTime.UtcNow;
                if (contactOK == null)
                {
                    boxModelLanguage.LastUpdateContactTVItemID = 2;
                }
                else
                {
                    boxModelLanguage.LastUpdateContactTVItemID = contactOK.ContactTVItemID;
                }
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }

            return("");
        }
        private BoxModelLanguage GetFilledRandomBoxModelLanguage(string OmitPropName)
        {
            BoxModelLanguage boxModelLanguage = new BoxModelLanguage();

            if (OmitPropName != "BoxModelID")
            {
                boxModelLanguage.BoxModelID = 1;
            }
            if (OmitPropName != "Language")
            {
                boxModelLanguage.Language = LanguageRequest;
            }
            if (OmitPropName != "ScenarioName")
            {
                boxModelLanguage.ScenarioName = GetRandomString("", 5);
            }
            if (OmitPropName != "TranslationStatus")
            {
                boxModelLanguage.TranslationStatus = (TranslationStatusEnum)GetRandomEnumType(typeof(TranslationStatusEnum));
            }
            if (OmitPropName != "LastUpdateDate_UTC")
            {
                boxModelLanguage.LastUpdateDate_UTC = new DateTime(2005, 3, 6);
            }
            if (OmitPropName != "LastUpdateContactTVItemID")
            {
                boxModelLanguage.LastUpdateContactTVItemID = 2;
            }

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

                    BoxModelLanguage boxModelLanguageLast = new BoxModelLanguage();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
                    {
                        Query query = new Query();
                        query.Language = LanguageRequest;

                        BoxModelLanguageService boxModelLanguageService = new BoxModelLanguageService(query, db, ContactID);
                        boxModelLanguageLast = (from c in db.BoxModelLanguages select c).FirstOrDefault();
                    }

                    // ok with BoxModelLanguage info
                    IHttpActionResult jsonRet = boxModelLanguageController.GetBoxModelLanguageWithID(boxModelLanguageLast.BoxModelLanguageID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <BoxModelLanguage> Ret = jsonRet as OkNegotiatedContentResult <BoxModelLanguage>;
                    BoxModelLanguage boxModelLanguageRet             = Ret.Content;
                    Assert.AreEqual(boxModelLanguageLast.BoxModelLanguageID, boxModelLanguageRet.BoxModelLanguageID);

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

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

                    OkNegotiatedContentResult <BoxModelLanguage> boxModelLanguageRet2 = jsonRet2 as OkNegotiatedContentResult <BoxModelLanguage>;
                    Assert.IsNotNull(boxModelLanguageRet2);

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

                    // Put to return CSSPError because BoxModelLanguageID of 0 does not exist
                    boxModelLanguageRet.BoxModelLanguageID = 0;
                    IHttpActionResult jsonRet3 = boxModelLanguageController.Put(boxModelLanguageRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet3);

                    OkNegotiatedContentResult <BoxModelLanguage> boxModelLanguageRet3 = jsonRet3 as OkNegotiatedContentResult <BoxModelLanguage>;
                    Assert.IsNull(boxModelLanguageRet3);

                    BadRequestErrorMessageResult badRequest3 = jsonRet3 as BadRequestErrorMessageResult;
                    Assert.IsNotNull(badRequest3);
                }
            }
        }
Example #5
0
        public BoxModelLanguage GetBoxModelLanguageWithBoxModelIDAndLanguageDB(int BoxModelID, LanguageEnum Language)
        {
            BoxModelLanguage boxModelLanguage = (from c in db.BoxModelLanguages
                                                 where c.BoxModelID == BoxModelID &&
                                                 c.Language == (int)Language
                                                 select c).FirstOrDefault <BoxModelLanguage>();

            return(boxModelLanguage);
        }
        public void BoxModelLanguage_CRUD_Test()
        {
            foreach (CultureInfo culture in AllowableCulture)
            {
                ChangeCulture(culture);

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

                    BoxModelLanguage boxModelLanguage = GetFilledRandomBoxModelLanguage("");

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

                    count = boxModelLanguageService.GetBoxModelLanguageList().Count();

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

                    boxModelLanguageService.Add(boxModelLanguage);
                    if (boxModelLanguage.HasErrors)
                    {
                        Assert.AreEqual("", boxModelLanguage.ValidationResults.FirstOrDefault().ErrorMessage);
                    }
                    Assert.AreEqual(true, boxModelLanguageService.GetBoxModelLanguageList().Where(c => c == boxModelLanguage).Any());
                    boxModelLanguageService.Update(boxModelLanguage);
                    if (boxModelLanguage.HasErrors)
                    {
                        Assert.AreEqual("", boxModelLanguage.ValidationResults.FirstOrDefault().ErrorMessage);
                    }
                    Assert.AreEqual(count + 1, boxModelLanguageService.GetBoxModelLanguageList().Count());
                    boxModelLanguageService.Delete(boxModelLanguage);
                    if (boxModelLanguage.HasErrors)
                    {
                        Assert.AreEqual("", boxModelLanguage.ValidationResults.FirstOrDefault().ErrorMessage);
                    }
                    Assert.AreEqual(count, boxModelLanguageService.GetBoxModelLanguageList().Count());
                }
            }
        }
Example #7
0
        // Post
        public BoxModelLanguageModel PostAddBoxModelLanguageDB(BoxModelLanguageModel boxModelLanguageModel)
        {
            string retStr = BoxModelLanguageModelOK(boxModelLanguageModel);

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

            ContactOK contactOK = IsContactOK();

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

            BoxModelLanguageModel boxModelLanguageModelExist = GetBoxModelLanguageModelWithBoxModelIDAndLanguageDB(boxModelLanguageModel.BoxModelID, boxModelLanguageModel.Language);

            if (string.IsNullOrWhiteSpace(boxModelLanguageModelExist.Error))
            {
                return(ReturnError(string.Format(ServiceRes._AlreadyExists, ServiceRes.BoxModelLanguage)));
            }

            BoxModelLanguage boxModelLanguageNew = new BoxModelLanguage();

            retStr = FillBoxModelLanguageModel(boxModelLanguageNew, boxModelLanguageModel, contactOK);
            if (!string.IsNullOrWhiteSpace(retStr))
            {
                return(ReturnError(retStr));
            }

            using (TransactionScope ts = new TransactionScope())
            {
                db.BoxModelLanguages.Add(boxModelLanguageNew);
                retStr = DoAddChanges();
                if (!string.IsNullOrWhiteSpace(retStr))
                {
                    return(ReturnError(retStr));
                }

                LogModel logModel = _LogService.PostAddLogForObj("BoxModelLanguages", boxModelLanguageNew.BoxModelLanguageID, LogCommandEnum.Add, boxModelLanguageNew);
                if (!string.IsNullOrWhiteSpace(logModel.Error))
                {
                    return(ReturnError(logModel.Error));
                }

                ts.Complete();
            }
            return(GetBoxModelLanguageModelWithBoxModelIDAndLanguageDB(boxModelLanguageNew.BoxModelID, (LanguageEnum)boxModelLanguageNew.Language));
        }
        public IHttpActionResult GetBoxModelLanguageWithID([FromUri] int BoxModelLanguageID, [FromUri] string lang = "en", [FromUri] string extra = "")
        {
            using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
            {
                BoxModelLanguageService boxModelLanguageService = new BoxModelLanguageService(new Query()
                {
                    Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en)
                }, db, ContactID);

                boxModelLanguageService.Query = boxModelLanguageService.FillQuery(typeof(BoxModelLanguage), lang, 0, 1, "", "", extra);

                if (boxModelLanguageService.Query.Extra == "A")
                {
                    BoxModelLanguageExtraA boxModelLanguageExtraA = new BoxModelLanguageExtraA();
                    boxModelLanguageExtraA = boxModelLanguageService.GetBoxModelLanguageExtraAWithBoxModelLanguageID(BoxModelLanguageID);

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

                    return(Ok(boxModelLanguageExtraA));
                }
                else if (boxModelLanguageService.Query.Extra == "B")
                {
                    BoxModelLanguageExtraB boxModelLanguageExtraB = new BoxModelLanguageExtraB();
                    boxModelLanguageExtraB = boxModelLanguageService.GetBoxModelLanguageExtraBWithBoxModelLanguageID(BoxModelLanguageID);

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

                    return(Ok(boxModelLanguageExtraB));
                }
                else
                {
                    BoxModelLanguage boxModelLanguage = new BoxModelLanguage();
                    boxModelLanguage = boxModelLanguageService.GetBoxModelLanguageWithBoxModelLanguageID(BoxModelLanguageID);

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

                    return(Ok(boxModelLanguage));
                }
            }
        }
Example #9
0
        public BoxModelLanguageModel PostUpdateBoxModelLanguageDB(BoxModelLanguageModel boxModelLanguageModel)
        {
            string retStr = BoxModelLanguageModelOK(boxModelLanguageModel);

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

            ContactOK contactOK = IsContactOK();

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

            BoxModelLanguage boxModelLanguageToUpdate = GetBoxModelLanguageWithBoxModelIDAndLanguageDB(boxModelLanguageModel.BoxModelID, boxModelLanguageModel.Language);

            if (boxModelLanguageToUpdate == null)
            {
                return(ReturnError(string.Format(ServiceRes.CouldNotFind_ToUpdate, ServiceRes.BoxModelLanguage)));
            }

            retStr = FillBoxModelLanguageModel(boxModelLanguageToUpdate, boxModelLanguageModel, contactOK);
            if (!string.IsNullOrWhiteSpace(retStr))
            {
                return(ReturnError(retStr));
            }

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

                LogModel logModel = _LogService.PostAddLogForObj("BoxModelLanguages", boxModelLanguageToUpdate.BoxModelLanguageID, LogCommandEnum.Change, boxModelLanguageToUpdate);
                if (!string.IsNullOrWhiteSpace(logModel.Error))
                {
                    return(ReturnError(logModel.Error));
                }

                ts.Complete();
            }

            return(GetBoxModelLanguageModelWithBoxModelIDAndLanguageDB(boxModelLanguageToUpdate.BoxModelID, (LanguageEnum)boxModelLanguageToUpdate.Language));
        }
Example #10
0
        public void SetupTest(ContactModel contactModelToDo, CultureInfo culture)
        {
            Thread.CurrentThread.CurrentCulture   = culture;
            Thread.CurrentThread.CurrentUICulture = culture;

            contactModel             = contactModelToDo;
            user                     = new GenericPrincipal(new GenericIdentity(contactModel.LoginEmail, "Forms"), null);
            boxModelService          = new BoxModelService((culture.TwoLetterISOLanguageName == "fr" ? LanguageEnum.fr : LanguageEnum.en), user);
            boxModelLanguageService  = new BoxModelLanguageService((culture.TwoLetterISOLanguageName == "fr" ? LanguageEnum.fr : LanguageEnum.en), user);
            testDBService            = new TestDBService((culture.TwoLetterISOLanguageName == "fr" ? LanguageEnum.fr : LanguageEnum.en), user, TableName, Plurial);
            randomService            = new RandomService((culture.TwoLetterISOLanguageName == "fr" ? LanguageEnum.fr : LanguageEnum.en), user);
            boxModelLanguageModelNew = new BoxModelLanguageModel();
            boxModelLanguage         = new BoxModelLanguage();
            boxModelServiceTest      = new BoxModelServiceTest();
            boxModelServiceTest.SetupTest(contactModelToDo, culture);
        }
Example #11
0
        /// <summary>
        /// Tries to execute the CSSPDB transaction (add/delete/update) on an [BoxModelLanguage](CSSPModels.BoxModelLanguage.html) item
        /// </summary>
        /// <param name="boxModelLanguage">Is the BoxModelLanguage item the client want to add to CSSPDB. What's important here is the BoxModelLanguageID</param>
        /// <returns>true if BoxModelLanguage item was updated to CSSPDB, false if an error happened during the DB requested transtaction</returns>
        private bool TryToSave(BoxModelLanguage boxModelLanguage)
        {
            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException ex)
            {
                boxModelLanguage.ValidationResults = new List <ValidationResult>()
                {
                    new ValidationResult(ex.Message + (ex.InnerException != null ? " Inner: " + ex.InnerException.Message : ""))
                }.AsEnumerable();
                return(false);
            }

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

            db.BoxModelLanguages.Update(boxModelLanguage);

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

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

                    BoxModelLanguage boxModelLanguageFirst = new BoxModelLanguage();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
                    {
                        BoxModelLanguageService boxModelLanguageService = new BoxModelLanguageService(new Query(), db, ContactID);
                        boxModelLanguageFirst = (from c in db.BoxModelLanguages select c).FirstOrDefault();
                    }

                    // ok with BoxModelLanguage info
                    IHttpActionResult jsonRet = boxModelLanguageController.GetBoxModelLanguageWithID(boxModelLanguageFirst.BoxModelLanguageID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <BoxModelLanguage> Ret = jsonRet as OkNegotiatedContentResult <BoxModelLanguage>;
                    BoxModelLanguage boxModelLanguageRet             = Ret.Content;
                    Assert.AreEqual(boxModelLanguageFirst.BoxModelLanguageID, boxModelLanguageRet.BoxModelLanguageID);

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

                    // Not Found
                    IHttpActionResult jsonRet2 = boxModelLanguageController.GetBoxModelLanguageWithID(0);
                    Assert.IsNotNull(jsonRet2);

                    OkNegotiatedContentResult <BoxModelLanguage> boxModelLanguageRet2 = jsonRet2 as OkNegotiatedContentResult <BoxModelLanguage>;
                    Assert.IsNull(boxModelLanguageRet2);

                    NotFoundResult notFoundRequest = jsonRet2 as NotFoundResult;
                    Assert.IsNotNull(notFoundRequest);
                }
            }
        }
        public IHttpActionResult Delete([FromBody] BoxModelLanguage boxModelLanguage, [FromUri] string lang = "en")
        {
            using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
            {
                BoxModelLanguageService boxModelLanguageService = new BoxModelLanguageService(new Query()
                {
                    Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en)
                }, db, ContactID);

                if (!boxModelLanguageService.Delete(boxModelLanguage))
                {
                    return(BadRequest(String.Join("|||", boxModelLanguage.ValidationResults)));
                }
                else
                {
                    boxModelLanguage.ValidationResults = null;
                    return(Ok(boxModelLanguage));
                }
            }
        }
Example #15
0
        public void BoxModelLanguageService_GetBoxModelLanguageWithBoxModelIDAndLanguageDB_Test()
        {
            foreach (CultureInfo culture in setupData.cultureListGood)
            {
                SetupTest(contactModelListGood[0], culture);

                using (TransactionScope ts = new TransactionScope())
                {
                    BoxModelModel boxModelModelRet = boxModelServiceTest.AddBoxModelModel();

                    LanguageEnum LangToAdd = LanguageEnum.es;

                    BoxModelLanguageModel boxModelLanguageModelRet = AddBoxModelLanguageModel(LangToAdd, boxModelModelRet);

                    BoxModelLanguage boxModelLanguageRet2 = boxModelLanguageService.GetBoxModelLanguageWithBoxModelIDAndLanguageDB(boxModelLanguageModelRet.BoxModelID, LangToAdd);

                    Assert.AreEqual(boxModelLanguageModelRet.BoxModelID, boxModelLanguageRet2.BoxModelID);
                    Assert.AreEqual(boxModelLanguageModelRet.Language, (LanguageEnum)boxModelLanguageRet2.Language);
                    Assert.AreEqual(LangToAdd, (LanguageEnum)boxModelLanguageRet2.Language);
                }
            }
        }
        public void GetBoxModelLanguageList_Test()
        {
            foreach (CultureInfo culture in AllowableCulture)
            {
                ChangeCulture(culture);

                using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                {
                    BoxModelLanguageService boxModelLanguageService = new BoxModelLanguageService(new Query()
                    {
                        Lang = culture.TwoLetterISOLanguageName
                    }, dbTestDB, ContactID);
                    BoxModelLanguage boxModelLanguage = (from c in dbTestDB.BoxModelLanguages select c).FirstOrDefault();
                    Assert.IsNotNull(boxModelLanguage);

                    List <BoxModelLanguage> boxModelLanguageDirectQueryList = new List <BoxModelLanguage>();
                    boxModelLanguageDirectQueryList = (from c in dbTestDB.BoxModelLanguages select c).Take(200).ToList();

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

                        if (string.IsNullOrWhiteSpace(extra))
                        {
                            List <BoxModelLanguage> boxModelLanguageList = new List <BoxModelLanguage>();
                            boxModelLanguageList = boxModelLanguageService.GetBoxModelLanguageList().ToList();
                            CheckBoxModelLanguageFields(boxModelLanguageList);
                        }
                        else
                        {
                            //Assert.AreEqual(true, false);
                        }
                    }
                }
            }
        }
Example #17
0
        /// <summary>
        /// Validate function for all BoxModelLanguageService 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);
            BoxModelLanguage boxModelLanguage = validationContext.ObjectInstance as BoxModelLanguage;

            boxModelLanguage.HasErrors = false;

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

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

            BoxModel BoxModelBoxModelID = (from c in db.BoxModels where c.BoxModelID == boxModelLanguage.BoxModelID select c).FirstOrDefault();

            if (BoxModelBoxModelID == null)
            {
                boxModelLanguage.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "BoxModel", "BoxModelID", boxModelLanguage.BoxModelID.ToString()), new[] { "BoxModelID" }));
            }

            retStr = enums.EnumTypeOK(typeof(LanguageEnum), (int?)boxModelLanguage.Language);
            if (!string.IsNullOrWhiteSpace(retStr))
            {
                boxModelLanguage.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "Language"), new[] { "Language" }));
            }

            if (string.IsNullOrWhiteSpace(boxModelLanguage.ScenarioName))
            {
                boxModelLanguage.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "ScenarioName"), new[] { "ScenarioName" }));
            }

            if (!string.IsNullOrWhiteSpace(boxModelLanguage.ScenarioName) && boxModelLanguage.ScenarioName.Length > 250)
            {
                boxModelLanguage.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "ScenarioName", "250"), new[] { "ScenarioName" }));
            }

            retStr = enums.EnumTypeOK(typeof(TranslationStatusEnum), (int?)boxModelLanguage.TranslationStatus);
            if (!string.IsNullOrWhiteSpace(retStr))
            {
                boxModelLanguage.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "TranslationStatus"), new[] { "TranslationStatus" }));
            }

            if (boxModelLanguage.LastUpdateDate_UTC.Year == 1)
            {
                boxModelLanguage.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "LastUpdateDate_UTC"), new[] { "LastUpdateDate_UTC" }));
            }
            else
            {
                if (boxModelLanguage.LastUpdateDate_UTC.Year < 1980)
                {
                    boxModelLanguage.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 == boxModelLanguage.LastUpdateContactTVItemID select c).FirstOrDefault();

            if (TVItemLastUpdateContactTVItemID == null)
            {
                boxModelLanguage.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "LastUpdateContactTVItemID", boxModelLanguage.LastUpdateContactTVItemID.ToString()), new[] { "LastUpdateContactTVItemID" }));
            }
            else
            {
                List <TVTypeEnum> AllowableTVTypes = new List <TVTypeEnum>()
                {
                    TVTypeEnum.Contact,
                };
                if (!AllowableTVTypes.Contains(TVItemLastUpdateContactTVItemID.TVType))
                {
                    boxModelLanguage.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
            {
                boxModelLanguage.HasErrors = true;
                yield return(new ValidationResult("AAA", new[] { "AAA" }));
            }
        }
Example #18
0
 public BoxModelLanguageTest()
 {
     boxModelLanguage       = new BoxModelLanguage();
     boxModelLanguageExtraA = new BoxModelLanguageExtraA();
     boxModelLanguageExtraB = new BoxModelLanguageExtraB();
 }
        public void BoxModelLanguage_Controller_GetBoxModelLanguageList_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    BoxModelLanguageController boxModelLanguageController = new BoxModelLanguageController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(boxModelLanguageController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, boxModelLanguageController.DatabaseType);

                    BoxModelLanguage boxModelLanguageFirst = new BoxModelLanguage();
                    int   count = -1;
                    Query query = new Query();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                    {
                        BoxModelLanguageService boxModelLanguageService = new BoxModelLanguageService(query, db, ContactID);
                        boxModelLanguageFirst = (from c in db.BoxModelLanguages select c).FirstOrDefault();
                        count = (from c in db.BoxModelLanguages select c).Count();
                        count = (query.Take > count ? count : query.Take);
                    }

                    // ok with BoxModelLanguage info
                    IHttpActionResult jsonRet = boxModelLanguageController.GetBoxModelLanguageList();
                    Assert.IsNotNull(jsonRet);

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

                    List <BoxModelLanguage> boxModelLanguageList = new List <BoxModelLanguage>();
                    count = -1;
                    query = new Query();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                    {
                        BoxModelLanguageService boxModelLanguageService = new BoxModelLanguageService(query, db, ContactID);
                        boxModelLanguageList = (from c in db.BoxModelLanguages select c).OrderBy(c => c.BoxModelLanguageID).Skip(0).Take(2).ToList();
                        count = (from c in db.BoxModelLanguages select c).Count();
                    }

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

                        // ok with BoxModelLanguage info
                        jsonRet = boxModelLanguageController.GetBoxModelLanguageList(query.Language.ToString(), query.Skip, query.Take);
                        Assert.IsNotNull(jsonRet);

                        ret = jsonRet as OkNegotiatedContentResult <List <BoxModelLanguage> >;
                        Assert.AreEqual(boxModelLanguageList[0].BoxModelLanguageID, ret.Content[0].BoxModelLanguageID);
                        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 BoxModelLanguage info
                            IHttpActionResult jsonRet2 = boxModelLanguageController.GetBoxModelLanguageList(query.Language.ToString(), query.Skip, query.Take);
                            Assert.IsNotNull(jsonRet2);

                            OkNegotiatedContentResult <List <BoxModelLanguage> > ret2 = jsonRet2 as OkNegotiatedContentResult <List <BoxModelLanguage> >;
                            Assert.AreEqual(boxModelLanguageList[1].BoxModelLanguageID, ret2.Content[0].BoxModelLanguageID);
                            Assert.AreEqual((count > query.Take ? query.Take : count), ret2.Content.Count);
                        }
                    }
                }
            }
        }
        public void BoxModelLanguage_Controller_Post_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    BoxModelLanguageController boxModelLanguageController = new BoxModelLanguageController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(boxModelLanguageController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, boxModelLanguageController.DatabaseType);

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

                        BoxModelLanguageService boxModelLanguageService = new BoxModelLanguageService(query, db, ContactID);
                        boxModelLanguageLast = (from c in db.BoxModelLanguages select c).FirstOrDefault();
                    }

                    // ok with BoxModelLanguage info
                    IHttpActionResult jsonRet = boxModelLanguageController.GetBoxModelLanguageWithID(boxModelLanguageLast.BoxModelLanguageID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <BoxModelLanguage> Ret = jsonRet as OkNegotiatedContentResult <BoxModelLanguage>;
                    BoxModelLanguage boxModelLanguageRet             = Ret.Content;
                    Assert.AreEqual(boxModelLanguageLast.BoxModelLanguageID, boxModelLanguageRet.BoxModelLanguageID);

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

                    // Post to return CSSPError because BoxModelLanguageID exist
                    IHttpActionResult jsonRet2 = boxModelLanguageController.Post(boxModelLanguageRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet2);

                    OkNegotiatedContentResult <BoxModelLanguage> boxModelLanguageRet2 = jsonRet2 as OkNegotiatedContentResult <BoxModelLanguage>;
                    Assert.IsNull(boxModelLanguageRet2);

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

                    // Post to return newly added BoxModelLanguage
                    boxModelLanguageRet.BoxModelLanguageID        = 0;
                    boxModelLanguageController.Request            = new System.Net.Http.HttpRequestMessage();
                    boxModelLanguageController.Request.RequestUri = new System.Uri("http://localhost:5000/api/boxModelLanguage");
                    IHttpActionResult jsonRet3 = boxModelLanguageController.Post(boxModelLanguageRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet3);

                    CreatedNegotiatedContentResult <BoxModelLanguage> boxModelLanguageRet3 = jsonRet3 as CreatedNegotiatedContentResult <BoxModelLanguage>;
                    Assert.IsNotNull(boxModelLanguageRet3);

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

                    IHttpActionResult jsonRet4 = boxModelLanguageController.Delete(boxModelLanguageRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet4);

                    OkNegotiatedContentResult <BoxModelLanguage> boxModelLanguageRet4 = jsonRet4 as OkNegotiatedContentResult <BoxModelLanguage>;
                    Assert.IsNotNull(boxModelLanguageRet4);

                    BadRequestErrorMessageResult badRequest4 = jsonRet4 as BadRequestErrorMessageResult;
                    Assert.IsNull(badRequest4);
                }
            }
        }
        public void BoxModelLanguage_Properties_Test()
        {
            foreach (CultureInfo culture in AllowableCulture)
            {
                ChangeCulture(culture);

                using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                {
                    BoxModelLanguageService boxModelLanguageService = new BoxModelLanguageService(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 = boxModelLanguageService.GetBoxModelLanguageList().Count();

                    BoxModelLanguage boxModelLanguage = GetFilledRandomBoxModelLanguage("");

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


                    // -----------------------------------
                    // [Key]
                    // Is NOT Nullable
                    // boxModelLanguage.BoxModelLanguageID   (Int32)
                    // -----------------------------------

                    boxModelLanguage = null;
                    boxModelLanguage = GetFilledRandomBoxModelLanguage("");
                    boxModelLanguage.BoxModelLanguageID = 0;
                    boxModelLanguageService.Update(boxModelLanguage);
                    Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "BoxModelLanguageID"), boxModelLanguage.ValidationResults.FirstOrDefault().ErrorMessage);

                    boxModelLanguage = null;
                    boxModelLanguage = GetFilledRandomBoxModelLanguage("");
                    boxModelLanguage.BoxModelLanguageID = 10000000;
                    boxModelLanguageService.Update(boxModelLanguage);
                    Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "BoxModelLanguage", "BoxModelLanguageID", boxModelLanguage.BoxModelLanguageID.ToString()), boxModelLanguage.ValidationResults.FirstOrDefault().ErrorMessage);


                    // -----------------------------------
                    // Is NOT Nullable
                    // [CSSPExist(ExistTypeName = "BoxModel", ExistPlurial = "s", ExistFieldID = "BoxModelID", AllowableTVtypeList = )]
                    // boxModelLanguage.BoxModelID   (Int32)
                    // -----------------------------------

                    boxModelLanguage            = null;
                    boxModelLanguage            = GetFilledRandomBoxModelLanguage("");
                    boxModelLanguage.BoxModelID = 0;
                    boxModelLanguageService.Add(boxModelLanguage);
                    Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "BoxModel", "BoxModelID", boxModelLanguage.BoxModelID.ToString()), boxModelLanguage.ValidationResults.FirstOrDefault().ErrorMessage);


                    // -----------------------------------
                    // Is NOT Nullable
                    // [CSSPEnumType]
                    // boxModelLanguage.Language   (LanguageEnum)
                    // -----------------------------------

                    boxModelLanguage          = null;
                    boxModelLanguage          = GetFilledRandomBoxModelLanguage("");
                    boxModelLanguage.Language = (LanguageEnum)1000000;
                    boxModelLanguageService.Add(boxModelLanguage);
                    Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "Language"), boxModelLanguage.ValidationResults.FirstOrDefault().ErrorMessage);


                    // -----------------------------------
                    // Is NOT Nullable
                    // [StringLength(250))]
                    // boxModelLanguage.ScenarioName   (String)
                    // -----------------------------------

                    boxModelLanguage = null;
                    boxModelLanguage = GetFilledRandomBoxModelLanguage("ScenarioName");
                    Assert.AreEqual(false, boxModelLanguageService.Add(boxModelLanguage));
                    Assert.AreEqual(1, boxModelLanguage.ValidationResults.Count());
                    Assert.IsTrue(boxModelLanguage.ValidationResults.Where(c => c.ErrorMessage == string.Format(CSSPServicesRes._IsRequired, "ScenarioName")).Any());
                    Assert.AreEqual(null, boxModelLanguage.ScenarioName);
                    Assert.AreEqual(count, boxModelLanguageService.GetBoxModelLanguageList().Count());

                    boxModelLanguage = null;
                    boxModelLanguage = GetFilledRandomBoxModelLanguage("");
                    boxModelLanguage.ScenarioName = GetRandomString("", 251);
                    Assert.AreEqual(false, boxModelLanguageService.Add(boxModelLanguage));
                    Assert.AreEqual(string.Format(CSSPServicesRes._MaxLengthIs_, "ScenarioName", "250"), boxModelLanguage.ValidationResults.FirstOrDefault().ErrorMessage);
                    Assert.AreEqual(count, boxModelLanguageService.GetBoxModelLanguageList().Count());

                    // -----------------------------------
                    // Is NOT Nullable
                    // [CSSPEnumType]
                    // boxModelLanguage.TranslationStatus   (TranslationStatusEnum)
                    // -----------------------------------

                    boxModelLanguage = null;
                    boxModelLanguage = GetFilledRandomBoxModelLanguage("");
                    boxModelLanguage.TranslationStatus = (TranslationStatusEnum)1000000;
                    boxModelLanguageService.Add(boxModelLanguage);
                    Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "TranslationStatus"), boxModelLanguage.ValidationResults.FirstOrDefault().ErrorMessage);


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

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

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

                    boxModelLanguage = null;
                    boxModelLanguage = GetFilledRandomBoxModelLanguage("");
                    boxModelLanguage.LastUpdateContactTVItemID = 0;
                    boxModelLanguageService.Add(boxModelLanguage);
                    Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "LastUpdateContactTVItemID", boxModelLanguage.LastUpdateContactTVItemID.ToString()), boxModelLanguage.ValidationResults.FirstOrDefault().ErrorMessage);

                    boxModelLanguage = null;
                    boxModelLanguage = GetFilledRandomBoxModelLanguage("");
                    boxModelLanguage.LastUpdateContactTVItemID = 1;
                    boxModelLanguageService.Add(boxModelLanguage);
                    Assert.AreEqual(string.Format(CSSPServicesRes._IsNotOfType_, "LastUpdateContactTVItemID", "Contact"), boxModelLanguage.ValidationResults.FirstOrDefault().ErrorMessage);


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

                    // No testing requied

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

                    // No testing requied
                }
            }
        }