Beispiel #1
0
        private SpillLanguage GetFilledRandomSpillLanguage(string OmitPropName)
        {
            SpillLanguage spillLanguage = new SpillLanguage();

            if (OmitPropName != "SpillID")
            {
                spillLanguage.SpillID = 1;
            }
            if (OmitPropName != "Language")
            {
                spillLanguage.Language = LanguageRequest;
            }
            if (OmitPropName != "SpillComment")
            {
                spillLanguage.SpillComment = GetRandomString("", 20);
            }
            if (OmitPropName != "TranslationStatus")
            {
                spillLanguage.TranslationStatus = (TranslationStatusEnum)GetRandomEnumType(typeof(TranslationStatusEnum));
            }
            if (OmitPropName != "LastUpdateDate_UTC")
            {
                spillLanguage.LastUpdateDate_UTC = new DateTime(2005, 3, 6);
            }
            if (OmitPropName != "LastUpdateContactTVItemID")
            {
                spillLanguage.LastUpdateContactTVItemID = 2;
            }

            return(spillLanguage);
        }
Beispiel #2
0
        public SpillLanguageModel PostDeleteSpillLanguageDB(int SpillID, LanguageEnum Language)
        {
            ContactOK contactOK = IsContactOK();

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

            SpillLanguage spillLanguageToDelete = GetSpillLanguageWithSpillIDAndLanguageDB(SpillID, Language);

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

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

                LogModel logModel = _LogService.PostAddLogForObj("SpillLanguages", spillLanguageToDelete.SpillLanguageID, LogCommandEnum.Delete, spillLanguageToDelete);
                if (!string.IsNullOrWhiteSpace(logModel.Error))
                {
                    return(ReturnError(logModel.Error));
                }

                ts.Complete();
            }
            return(ReturnError(""));
        }
Beispiel #3
0
        public SpillLanguage GetSpillLanguageWithSpillIDAndLanguageDB(int SpillID, LanguageEnum Language)
        {
            SpillLanguage spillLanguage = (from c in db.SpillLanguages
                                           where c.SpillID == SpillID &&
                                           c.Language == (int)Language
                                           select c).FirstOrDefault <SpillLanguage>();

            return(spillLanguage);
        }
Beispiel #4
0
        public void SpillLanguage_Controller_Put_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    SpillLanguageController spillLanguageController = new SpillLanguageController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(spillLanguageController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, spillLanguageController.DatabaseType);

                    SpillLanguage spillLanguageLast = new SpillLanguage();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
                    {
                        Query query = new Query();
                        query.Language = LanguageRequest;

                        SpillLanguageService spillLanguageService = new SpillLanguageService(query, db, ContactID);
                        spillLanguageLast = (from c in db.SpillLanguages select c).FirstOrDefault();
                    }

                    // ok with SpillLanguage info
                    IHttpActionResult jsonRet = spillLanguageController.GetSpillLanguageWithID(spillLanguageLast.SpillLanguageID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <SpillLanguage> Ret = jsonRet as OkNegotiatedContentResult <SpillLanguage>;
                    SpillLanguage spillLanguageRet = Ret.Content;
                    Assert.AreEqual(spillLanguageLast.SpillLanguageID, spillLanguageRet.SpillLanguageID);

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

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

                    OkNegotiatedContentResult <SpillLanguage> spillLanguageRet2 = jsonRet2 as OkNegotiatedContentResult <SpillLanguage>;
                    Assert.IsNotNull(spillLanguageRet2);

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

                    // Put to return CSSPError because SpillLanguageID of 0 does not exist
                    spillLanguageRet.SpillLanguageID = 0;
                    IHttpActionResult jsonRet3 = spillLanguageController.Put(spillLanguageRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet3);

                    OkNegotiatedContentResult <SpillLanguage> spillLanguageRet3 = jsonRet3 as OkNegotiatedContentResult <SpillLanguage>;
                    Assert.IsNull(spillLanguageRet3);

                    BadRequestErrorMessageResult badRequest3 = jsonRet3 as BadRequestErrorMessageResult;
                    Assert.IsNotNull(badRequest3);
                }
            }
        }
Beispiel #5
0
        public void SpillLanguage_CRUD_Test()
        {
            foreach (CultureInfo culture in AllowableCulture)
            {
                ChangeCulture(culture);

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

                    SpillLanguage spillLanguage = GetFilledRandomSpillLanguage("");

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

                    count = spillLanguageService.GetSpillLanguageList().Count();

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

                    spillLanguageService.Add(spillLanguage);
                    if (spillLanguage.HasErrors)
                    {
                        Assert.AreEqual("", spillLanguage.ValidationResults.FirstOrDefault().ErrorMessage);
                    }
                    Assert.AreEqual(true, spillLanguageService.GetSpillLanguageList().Where(c => c == spillLanguage).Any());
                    spillLanguageService.Update(spillLanguage);
                    if (spillLanguage.HasErrors)
                    {
                        Assert.AreEqual("", spillLanguage.ValidationResults.FirstOrDefault().ErrorMessage);
                    }
                    Assert.AreEqual(count + 1, spillLanguageService.GetSpillLanguageList().Count());
                    spillLanguageService.Delete(spillLanguage);
                    if (spillLanguage.HasErrors)
                    {
                        Assert.AreEqual("", spillLanguage.ValidationResults.FirstOrDefault().ErrorMessage);
                    }
                    Assert.AreEqual(count, spillLanguageService.GetSpillLanguageList().Count());
                }
            }
        }
Beispiel #6
0
        // Post
        public SpillLanguageModel PostAddSpillLanguageDB(SpillLanguageModel spillLanguageModel)
        {
            string retStr = SpillLanguageModelOK(spillLanguageModel);

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

            ContactOK contactOK = IsContactOK();

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

            SpillLanguageModel spillLanguageModelExist = GetSpillLanguageModelWithSpillIDAndLanguageDB(spillLanguageModel.SpillID, spillLanguageModel.Language);

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

            SpillLanguage spillLanguageNew = new SpillLanguage();

            retStr = FillSpillLanguage(spillLanguageNew, spillLanguageModel, contactOK);
            if (!string.IsNullOrWhiteSpace(retStr))
            {
                return(ReturnError(retStr));
            }

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

                LogModel logModel = _LogService.PostAddLogForObj("SpillLanguages", spillLanguageNew.SpillLanguageID, LogCommandEnum.Add, spillLanguageNew);
                if (!string.IsNullOrWhiteSpace(logModel.Error))
                {
                    return(ReturnError(logModel.Error));
                }

                ts.Complete();
            }
            return(GetSpillLanguageModelWithSpillIDAndLanguageDB(spillLanguageNew.SpillID, spillLanguageModel.Language));
        }
        public IHttpActionResult GetSpillLanguageWithID([FromUri] int SpillLanguageID, [FromUri] string lang = "en", [FromUri] string extra = "")
        {
            using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
            {
                SpillLanguageService spillLanguageService = new SpillLanguageService(new Query()
                {
                    Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en)
                }, db, ContactID);

                spillLanguageService.Query = spillLanguageService.FillQuery(typeof(SpillLanguage), lang, 0, 1, "", "", extra);

                if (spillLanguageService.Query.Extra == "A")
                {
                    SpillLanguageExtraA spillLanguageExtraA = new SpillLanguageExtraA();
                    spillLanguageExtraA = spillLanguageService.GetSpillLanguageExtraAWithSpillLanguageID(SpillLanguageID);

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

                    return(Ok(spillLanguageExtraA));
                }
                else if (spillLanguageService.Query.Extra == "B")
                {
                    SpillLanguageExtraB spillLanguageExtraB = new SpillLanguageExtraB();
                    spillLanguageExtraB = spillLanguageService.GetSpillLanguageExtraBWithSpillLanguageID(SpillLanguageID);

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

                    return(Ok(spillLanguageExtraB));
                }
                else
                {
                    SpillLanguage spillLanguage = new SpillLanguage();
                    spillLanguage = spillLanguageService.GetSpillLanguageWithSpillLanguageID(SpillLanguageID);

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

                    return(Ok(spillLanguage));
                }
            }
        }
Beispiel #8
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);
            spillService          = new SpillService((culture.TwoLetterISOLanguageName == "fr" ? LanguageEnum.fr : LanguageEnum.en), user);
            spillLanguageService  = new SpillLanguageService((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);
            spillLanguageModelNew = new SpillLanguageModel();
            spillLanguage         = new SpillLanguage();
            spillServiceTest      = new SpillServiceTest();
            spillServiceTest.SetupTest(contactModelToDo, culture);
        }
Beispiel #9
0
        public SpillLanguageModel PostUpdateSpillLanguageDB(SpillLanguageModel spillLanguageModel)
        {
            string retStr = SpillLanguageModelOK(spillLanguageModel);

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

            ContactOK contactOK = IsContactOK();

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

            SpillLanguage spillLanguageToUpdate = GetSpillLanguageWithSpillIDAndLanguageDB(spillLanguageModel.SpillID, spillLanguageModel.Language);

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

            retStr = FillSpillLanguage(spillLanguageToUpdate, spillLanguageModel, 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("SpillLanguages", spillLanguageToUpdate.SpillLanguageID, LogCommandEnum.Change, spillLanguageToUpdate);
                if (!string.IsNullOrWhiteSpace(logModel.Error))
                {
                    return(ReturnError(logModel.Error));
                }

                ts.Complete();
            }
            return(GetSpillLanguageModelWithSpillIDAndLanguageDB(spillLanguageToUpdate.SpillID, spillLanguageModel.Language));
        }
Beispiel #10
0
        /// <summary>
        /// Updates an [SpillLanguage](CSSPModels.SpillLanguage.html) item in CSSPDB
        /// </summary>
        /// <param name="spillLanguage">Is the SpillLanguage item the client want to add to CSSPDB. What's important here is the SpillLanguageID</param>
        /// <returns>true if SpillLanguage item was updated to CSSPDB, false if an error happened during the DB requested transtaction</returns>
        public bool Update(SpillLanguage spillLanguage)
        {
            spillLanguage.ValidationResults = Validate(new ValidationContext(spillLanguage), ActionDBTypeEnum.Update);
            if (spillLanguage.ValidationResults.Count() > 0)
            {
                return(false);
            }

            db.SpillLanguages.Update(spillLanguage);

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

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

            return(true);
        }
Beispiel #12
0
        // Fill
        public string FillSpillLanguage(SpillLanguage spillLanguageNew, SpillLanguageModel spillLanguageModel, ContactOK contactOK)
        {
            spillLanguageNew.DBCommand          = (int)spillLanguageModel.DBCommand;
            spillLanguageNew.SpillID            = spillLanguageModel.SpillID;
            spillLanguageNew.Language           = (int)spillLanguageModel.Language;
            spillLanguageNew.TranslationStatus  = (int)spillLanguageModel.TranslationStatus;
            spillLanguageNew.SpillComment       = spillLanguageModel.SpillComment;
            spillLanguageNew.LastUpdateDate_UTC = DateTime.UtcNow;
            if (contactOK == null)
            {
                spillLanguageNew.LastUpdateContactTVItemID = 2;
            }
            else
            {
                spillLanguageNew.LastUpdateContactTVItemID = contactOK.ContactTVItemID;
            }

            return("");
        }
Beispiel #13
0
        public void SpillLanguage_Controller_GetSpillLanguageWithID_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    SpillLanguageController spillLanguageController = new SpillLanguageController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(spillLanguageController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, spillLanguageController.DatabaseType);

                    SpillLanguage spillLanguageFirst = new SpillLanguage();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
                    {
                        SpillLanguageService spillLanguageService = new SpillLanguageService(new Query(), db, ContactID);
                        spillLanguageFirst = (from c in db.SpillLanguages select c).FirstOrDefault();
                    }

                    // ok with SpillLanguage info
                    IHttpActionResult jsonRet = spillLanguageController.GetSpillLanguageWithID(spillLanguageFirst.SpillLanguageID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <SpillLanguage> Ret = jsonRet as OkNegotiatedContentResult <SpillLanguage>;
                    SpillLanguage spillLanguageRet = Ret.Content;
                    Assert.AreEqual(spillLanguageFirst.SpillLanguageID, spillLanguageRet.SpillLanguageID);

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

                    // Not Found
                    IHttpActionResult jsonRet2 = spillLanguageController.GetSpillLanguageWithID(0);
                    Assert.IsNotNull(jsonRet2);

                    OkNegotiatedContentResult <SpillLanguage> spillLanguageRet2 = jsonRet2 as OkNegotiatedContentResult <SpillLanguage>;
                    Assert.IsNull(spillLanguageRet2);

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

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

                using (TransactionScope ts = new TransactionScope())
                {
                    SpillModel spillModelRet = spillServiceTest.AddSpillModel();

                    LanguageEnum LangToAdd = LanguageEnum.es;

                    SpillLanguageModel spillLanguageModelRet = AddSpillLanguageModel(LangToAdd, spillModelRet);

                    SpillLanguage spillLanguageRet2 = spillLanguageService.GetSpillLanguageWithSpillIDAndLanguageDB(spillLanguageModelRet.SpillID, LangToAdd);
                    Assert.AreEqual(spillLanguageModelRet.SpillID, spillLanguageRet2.SpillID);
                    Assert.AreEqual(spillLanguageModelRet.Language, (LanguageEnum)spillLanguageRet2.Language);
                    Assert.AreEqual(LangToAdd, (LanguageEnum)spillLanguageRet2.Language);
                }
            }
        }
Beispiel #16
0
        public void GetSpillLanguageList_Test()
        {
            foreach (CultureInfo culture in AllowableCulture)
            {
                ChangeCulture(culture);

                using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                {
                    SpillLanguageService spillLanguageService = new SpillLanguageService(new Query()
                    {
                        Lang = culture.TwoLetterISOLanguageName
                    }, dbTestDB, ContactID);
                    SpillLanguage spillLanguage = (from c in dbTestDB.SpillLanguages select c).FirstOrDefault();
                    Assert.IsNotNull(spillLanguage);

                    List <SpillLanguage> spillLanguageDirectQueryList = new List <SpillLanguage>();
                    spillLanguageDirectQueryList = (from c in dbTestDB.SpillLanguages select c).Take(200).ToList();

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

                        if (string.IsNullOrWhiteSpace(extra))
                        {
                            List <SpillLanguage> spillLanguageList = new List <SpillLanguage>();
                            spillLanguageList = spillLanguageService.GetSpillLanguageList().ToList();
                            CheckSpillLanguageFields(spillLanguageList);
                        }
                        else
                        {
                            //Assert.AreEqual(true, false);
                        }
                    }
                }
            }
        }
Beispiel #17
0
        public void SpillLanguage_Controller_Post_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    SpillLanguageController spillLanguageController = new SpillLanguageController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(spillLanguageController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, spillLanguageController.DatabaseType);

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

                        SpillLanguageService spillLanguageService = new SpillLanguageService(query, db, ContactID);
                        spillLanguageLast = (from c in db.SpillLanguages select c).FirstOrDefault();
                    }

                    // ok with SpillLanguage info
                    IHttpActionResult jsonRet = spillLanguageController.GetSpillLanguageWithID(spillLanguageLast.SpillLanguageID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <SpillLanguage> Ret = jsonRet as OkNegotiatedContentResult <SpillLanguage>;
                    SpillLanguage spillLanguageRet = Ret.Content;
                    Assert.AreEqual(spillLanguageLast.SpillLanguageID, spillLanguageRet.SpillLanguageID);

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

                    // Post to return CSSPError because SpillLanguageID exist
                    IHttpActionResult jsonRet2 = spillLanguageController.Post(spillLanguageRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet2);

                    OkNegotiatedContentResult <SpillLanguage> spillLanguageRet2 = jsonRet2 as OkNegotiatedContentResult <SpillLanguage>;
                    Assert.IsNull(spillLanguageRet2);

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

                    // Post to return newly added SpillLanguage
                    spillLanguageRet.SpillLanguageID           = 0;
                    spillLanguageController.Request            = new System.Net.Http.HttpRequestMessage();
                    spillLanguageController.Request.RequestUri = new System.Uri("http://localhost:5000/api/spillLanguage");
                    IHttpActionResult jsonRet3 = spillLanguageController.Post(spillLanguageRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet3);

                    CreatedNegotiatedContentResult <SpillLanguage> spillLanguageRet3 = jsonRet3 as CreatedNegotiatedContentResult <SpillLanguage>;
                    Assert.IsNotNull(spillLanguageRet3);

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

                    IHttpActionResult jsonRet4 = spillLanguageController.Delete(spillLanguageRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet4);

                    OkNegotiatedContentResult <SpillLanguage> spillLanguageRet4 = jsonRet4 as OkNegotiatedContentResult <SpillLanguage>;
                    Assert.IsNotNull(spillLanguageRet4);

                    BadRequestErrorMessageResult badRequest4 = jsonRet4 as BadRequestErrorMessageResult;
                    Assert.IsNull(badRequest4);
                }
            }
        }
Beispiel #18
0
        public void SpillLanguage_Controller_GetSpillLanguageList_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    SpillLanguageController spillLanguageController = new SpillLanguageController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(spillLanguageController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, spillLanguageController.DatabaseType);

                    SpillLanguage spillLanguageFirst = new SpillLanguage();
                    int           count = -1;
                    Query         query = new Query();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                    {
                        SpillLanguageService spillLanguageService = new SpillLanguageService(query, db, ContactID);
                        spillLanguageFirst = (from c in db.SpillLanguages select c).FirstOrDefault();
                        count = (from c in db.SpillLanguages select c).Count();
                        count = (query.Take > count ? count : query.Take);
                    }

                    // ok with SpillLanguage info
                    IHttpActionResult jsonRet = spillLanguageController.GetSpillLanguageList();
                    Assert.IsNotNull(jsonRet);

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

                    List <SpillLanguage> spillLanguageList = new List <SpillLanguage>();
                    count = -1;
                    query = new Query();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                    {
                        SpillLanguageService spillLanguageService = new SpillLanguageService(query, db, ContactID);
                        spillLanguageList = (from c in db.SpillLanguages select c).OrderBy(c => c.SpillLanguageID).Skip(0).Take(2).ToList();
                        count             = (from c in db.SpillLanguages select c).Count();
                    }

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

                        // ok with SpillLanguage info
                        jsonRet = spillLanguageController.GetSpillLanguageList(query.Language.ToString(), query.Skip, query.Take);
                        Assert.IsNotNull(jsonRet);

                        ret = jsonRet as OkNegotiatedContentResult <List <SpillLanguage> >;
                        Assert.AreEqual(spillLanguageList[0].SpillLanguageID, ret.Content[0].SpillLanguageID);
                        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 SpillLanguage info
                            IHttpActionResult jsonRet2 = spillLanguageController.GetSpillLanguageList(query.Language.ToString(), query.Skip, query.Take);
                            Assert.IsNotNull(jsonRet2);

                            OkNegotiatedContentResult <List <SpillLanguage> > ret2 = jsonRet2 as OkNegotiatedContentResult <List <SpillLanguage> >;
                            Assert.AreEqual(spillLanguageList[1].SpillLanguageID, ret2.Content[0].SpillLanguageID);
                            Assert.AreEqual((count > query.Take ? query.Take : count), ret2.Content.Count);
                        }
                    }
                }
            }
        }
Beispiel #19
0
        /// <summary>
        /// Validate function for all SpillLanguageService 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);
            SpillLanguage spillLanguage = validationContext.ObjectInstance as SpillLanguage;

            spillLanguage.HasErrors = false;

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

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

            Spill SpillSpillID = (from c in db.Spills where c.SpillID == spillLanguage.SpillID select c).FirstOrDefault();

            if (SpillSpillID == null)
            {
                spillLanguage.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "Spill", "SpillID", spillLanguage.SpillID.ToString()), new[] { "SpillID" }));
            }

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

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

            //SpillComment has no StringLength Attribute

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

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

            if (TVItemLastUpdateContactTVItemID == null)
            {
                spillLanguage.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "LastUpdateContactTVItemID", spillLanguage.LastUpdateContactTVItemID.ToString()), new[] { "LastUpdateContactTVItemID" }));
            }
            else
            {
                List <TVTypeEnum> AllowableTVTypes = new List <TVTypeEnum>()
                {
                    TVTypeEnum.Contact,
                };
                if (!AllowableTVTypes.Contains(TVItemLastUpdateContactTVItemID.TVType))
                {
                    spillLanguage.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
            {
                spillLanguage.HasErrors = true;
                yield return(new ValidationResult("AAA", new[] { "AAA" }));
            }
        }
 public SpillLanguageTest()
 {
     spillLanguage       = new SpillLanguage();
     spillLanguageExtraA = new SpillLanguageExtraA();
     spillLanguageExtraB = new SpillLanguageExtraB();
 }
Beispiel #21
0
        public void SpillLanguage_Properties_Test()
        {
            foreach (CultureInfo culture in AllowableCulture)
            {
                ChangeCulture(culture);

                using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                {
                    SpillLanguageService spillLanguageService = new SpillLanguageService(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 = spillLanguageService.GetSpillLanguageList().Count();

                    SpillLanguage spillLanguage = GetFilledRandomSpillLanguage("");

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


                    // -----------------------------------
                    // [Key]
                    // Is NOT Nullable
                    // spillLanguage.SpillLanguageID   (Int32)
                    // -----------------------------------

                    spillLanguage = null;
                    spillLanguage = GetFilledRandomSpillLanguage("");
                    spillLanguage.SpillLanguageID = 0;
                    spillLanguageService.Update(spillLanguage);
                    Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "SpillLanguageID"), spillLanguage.ValidationResults.FirstOrDefault().ErrorMessage);

                    spillLanguage = null;
                    spillLanguage = GetFilledRandomSpillLanguage("");
                    spillLanguage.SpillLanguageID = 10000000;
                    spillLanguageService.Update(spillLanguage);
                    Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "SpillLanguage", "SpillLanguageID", spillLanguage.SpillLanguageID.ToString()), spillLanguage.ValidationResults.FirstOrDefault().ErrorMessage);


                    // -----------------------------------
                    // Is NOT Nullable
                    // [CSSPExist(ExistTypeName = "Spill", ExistPlurial = "s", ExistFieldID = "SpillID", AllowableTVtypeList = )]
                    // spillLanguage.SpillID   (Int32)
                    // -----------------------------------

                    spillLanguage         = null;
                    spillLanguage         = GetFilledRandomSpillLanguage("");
                    spillLanguage.SpillID = 0;
                    spillLanguageService.Add(spillLanguage);
                    Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "Spill", "SpillID", spillLanguage.SpillID.ToString()), spillLanguage.ValidationResults.FirstOrDefault().ErrorMessage);


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

                    spillLanguage          = null;
                    spillLanguage          = GetFilledRandomSpillLanguage("");
                    spillLanguage.Language = (LanguageEnum)1000000;
                    spillLanguageService.Add(spillLanguage);
                    Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "Language"), spillLanguage.ValidationResults.FirstOrDefault().ErrorMessage);


                    // -----------------------------------
                    // Is NOT Nullable
                    // spillLanguage.SpillComment   (String)
                    // -----------------------------------

                    spillLanguage = null;
                    spillLanguage = GetFilledRandomSpillLanguage("SpillComment");
                    Assert.AreEqual(false, spillLanguageService.Add(spillLanguage));
                    Assert.AreEqual(1, spillLanguage.ValidationResults.Count());
                    Assert.IsTrue(spillLanguage.ValidationResults.Where(c => c.ErrorMessage == string.Format(CSSPServicesRes._IsRequired, "SpillComment")).Any());
                    Assert.AreEqual(null, spillLanguage.SpillComment);
                    Assert.AreEqual(count, spillLanguageService.GetSpillLanguageList().Count());


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

                    spillLanguage = null;
                    spillLanguage = GetFilledRandomSpillLanguage("");
                    spillLanguage.TranslationStatus = (TranslationStatusEnum)1000000;
                    spillLanguageService.Add(spillLanguage);
                    Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "TranslationStatus"), spillLanguage.ValidationResults.FirstOrDefault().ErrorMessage);


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

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

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

                    spillLanguage = null;
                    spillLanguage = GetFilledRandomSpillLanguage("");
                    spillLanguage.LastUpdateContactTVItemID = 0;
                    spillLanguageService.Add(spillLanguage);
                    Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "LastUpdateContactTVItemID", spillLanguage.LastUpdateContactTVItemID.ToString()), spillLanguage.ValidationResults.FirstOrDefault().ErrorMessage);

                    spillLanguage = null;
                    spillLanguage = GetFilledRandomSpillLanguage("");
                    spillLanguage.LastUpdateContactTVItemID = 1;
                    spillLanguageService.Add(spillLanguage);
                    Assert.AreEqual(string.Format(CSSPServicesRes._IsNotOfType_, "LastUpdateContactTVItemID", "Contact"), spillLanguage.ValidationResults.FirstOrDefault().ErrorMessage);


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

                    // No testing requied

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

                    // No testing requied
                }
            }
        }