コード例 #1
0
        public void InfrastructureLanguageService_PostAddInfrastructureLanguageDB_IsContactOK_Error_Test()
        {
            foreach (CultureInfo culture in setupData.cultureListGood)
            {
                SetupTest(contactModelListGood[0], culture);

                using (TransactionScope ts = new TransactionScope())
                {
                    using (ShimsContext.Create())
                    {
                        SetupShim();
                        LanguageEnum LangToAdd = LanguageEnum.es;

                        string ErrorText = "ErrorText";
                        shimInfrastructureLanguageService.IsContactOK = () =>
                        {
                            return(new ContactOK()
                            {
                                Error = ErrorText
                            });
                        };

                        InfrastructureLanguageModel infrastructureLanguageModelRet = AddInfrastructureLanguageModel(LangToAdd);
                        Assert.AreEqual(ErrorText, infrastructureLanguageModelRet.Error);
                    }
                }
            }
        }
コード例 #2
0
        public void InfrastructureLanguageService_PostUpdateInfrastructureLanguageDB_DoUpdateChanges_Error_Test()
        {
            foreach (CultureInfo culture in setupData.cultureListGood)
            {
                SetupTest(contactModelListGood[0], culture);

                using (TransactionScope ts = new TransactionScope())
                {
                    LanguageEnum LangToAdd = LanguageEnum.es;

                    InfrastructureLanguageModel infrastructureLanguageModelRet = AddInfrastructureLanguageModel(LangToAdd);
                    Assert.AreEqual("", infrastructureLanguageModelRet.Error);

                    using (ShimsContext.Create())
                    {
                        SetupShim();
                        FillInfrastructureLanguageModel(infrastructureLanguageModelRet);

                        string ErrorText = "ErrorText";
                        shimInfrastructureLanguageService.DoUpdateChanges = () =>
                        {
                            return(ErrorText);
                        };

                        InfrastructureLanguageModel infrastructureLanguageModelRet2 = UpdateInfrastructureLanguageModel(infrastructureLanguageModelRet);
                        Assert.AreEqual(ErrorText, infrastructureLanguageModelRet2.Error);
                    }
                }
            }
        }
コード例 #3
0
        public void InfrastructureLanguageService_PostAddInfrastructureLanguageDB_Add_Error_Test()
        {
            foreach (CultureInfo culture in setupData.cultureListGood)
            {
                SetupTest(contactModelListGood[0], culture);

                using (TransactionScope ts = new TransactionScope())
                {
                    using (ShimsContext.Create())
                    {
                        SetupShim();
                        LanguageEnum LangToAdd = LanguageEnum.es;

                        //string ErrorText = "ErrorText";
                        shimInfrastructureLanguageService.FillInfrastructureLanguageInfrastructureLanguageInfrastructureLanguageModelContactOK = (a, b, c) =>
                        {
                            return("");
                        };

                        InfrastructureLanguageModel infrastructureLanguageModelRet = AddInfrastructureLanguageModel(LangToAdd);
                        Assert.IsTrue(infrastructureLanguageModelRet.Error.StartsWith(string.Format(ServiceRes.CouldNotAddError_, "").Substring(0, 10)));
                    }
                }
            }
        }
コード例 #4
0
        public void InfrastructureLanguageService_PostUpdateInfrastructureLanguageDB_GetInfrastructureLanguageWithInfrastructureIDAndLanguageDB_Error_Test()
        {
            foreach (CultureInfo culture in setupData.cultureListGood)
            {
                SetupTest(contactModelListGood[0], culture);

                using (TransactionScope ts = new TransactionScope())
                {
                    LanguageEnum LangToAdd = LanguageEnum.es;

                    InfrastructureLanguageModel infrastructureLanguageModelRet = AddInfrastructureLanguageModel(LangToAdd);
                    Assert.AreEqual("", infrastructureLanguageModelRet.Error);

                    using (ShimsContext.Create())
                    {
                        SetupShim();
                        FillInfrastructureLanguageModel(infrastructureLanguageModelRet);

                        //string ErrorText = "ErrorText";
                        shimInfrastructureLanguageService.GetInfrastructureLanguageWithInfrastructureIDAndLanguageDBInt32LanguageEnum = (a, b) =>
                        {
                            return(null);
                        };

                        InfrastructureLanguageModel infrastructureLanguageModelRet2 = UpdateInfrastructureLanguageModel(infrastructureLanguageModelRet);
                        Assert.AreEqual(string.Format(ServiceRes.CouldNotFind_ToUpdate, ServiceRes.InfrastructureLanguage), infrastructureLanguageModelRet2.Error);
                    }
                }
            }
        }
コード例 #5
0
        private InfrastructureLanguageModel AddInfrastructureLanguageModel(LanguageEnum LangToAdd)
        {
            InfrastructureModel infrastructureModel = infrastructureServiceTest.AddInfrastructureModel();

            if (!string.IsNullOrWhiteSpace(infrastructureModel.Error))
            {
                return(new InfrastructureLanguageModel()
                {
                    Error = infrastructureModel.Error
                });
            }

            infrastructureLanguageModelNew.InfrastructureID = infrastructureModel.InfrastructureID;
            FillInfrastructureLanguageModel(infrastructureLanguageModelNew);

            InfrastructureLanguageModel infrastructureLanguagModelRet = infrastructureLanguageService.PostAddInfrastructureLanguageDB(infrastructureLanguageModelNew);

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

            CompareInfrastructureLanguageModels(infrastructureLanguageModelNew, infrastructureLanguagModelRet);

            return(infrastructureLanguagModelRet);
        }
コード例 #6
0
        // Check
        public string InfrastructureLanguageModelOK(InfrastructureLanguageModel infrastructureLanguageModel)
        {
            string retStr = FieldCheckNotZeroInt(infrastructureLanguageModel.InfrastructureID, ServiceRes.InfrastructureID);

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

            retStr = _BaseEnumService.LanguageOK(infrastructureLanguageModel.Language);
            if (!string.IsNullOrWhiteSpace(retStr))
            {
                return(retStr);
            }

            retStr = FieldCheckIfNotNullMaxLengthString(infrastructureLanguageModel.Comment, ServiceRes.Comment, 10000);
            if (!string.IsNullOrWhiteSpace(retStr))
            {
                return(retStr);
            }

            retStr = _BaseEnumService.DBCommandOK(infrastructureLanguageModel.DBCommand);
            if (!string.IsNullOrWhiteSpace(retStr))
            {
                return(retStr);
            }

            return("");
        }
コード例 #7
0
        public InfrastructureLanguageModel GetInfrastructureLanguageModelWithInfrastructureIDAndLanguageDB(int InfrastructureID, LanguageEnum Language)
        {
            InfrastructureLanguageModel infrastructureLanguageModel = (from c in db.InfrastructureLanguages
                                                                       where c.InfrastructureID == InfrastructureID &&
                                                                       c.Language == (int)Language
                                                                       select new InfrastructureLanguageModel
            {
                Error = "",
                InfrastructureLanguageID = c.InfrastructureLanguageID,
                DBCommand = (DBCommandEnum)c.DBCommand,
                InfrastructureID = c.InfrastructureID,
                Language = (LanguageEnum)c.Language,
                Comment = c.Comment,
                TranslationStatus = (TranslationStatusEnum)c.TranslationStatus,
                LastUpdateDate_UTC = c.LastUpdateDate_UTC,
                LastUpdateContactTVItemID = c.LastUpdateContactTVItemID,
            }).FirstOrDefault <InfrastructureLanguageModel>();

            if (infrastructureLanguageModel == null)
            {
                return(ReturnError(string.Format(ServiceRes.CouldNotFind_With_Equal_, ServiceRes.InfrastructureLanguage, ServiceRes.InfrastructureID + "," + ServiceRes.Language, InfrastructureID.ToString() + "," + Language)));
            }

            return(infrastructureLanguageModel);
        }
コード例 #8
0
        private void FillInfrastructureLanguageModel(InfrastructureLanguageModel infrastructureLanguageModel)
        {
            infrastructureLanguageModel.InfrastructureID  = infrastructureLanguageModel.InfrastructureID;
            infrastructureLanguageModel.Language          = LanguageEnum.es;
            infrastructureLanguageModel.Comment           = randomService.RandomString("Busy Text", 20);
            infrastructureLanguageModel.TranslationStatus = TranslationStatusEnum.Translated;

            Assert.IsTrue(infrastructureLanguageModel.InfrastructureID != 0);
            Assert.IsTrue(infrastructureLanguageModel.Language == LanguageEnum.es);
            Assert.IsTrue(infrastructureLanguageModel.Comment.Length == 20);
            Assert.IsTrue(infrastructureLanguageModel.TranslationStatus == TranslationStatusEnum.Translated);
        }
コード例 #9
0
        // Post
        public InfrastructureLanguageModel PostAddInfrastructureLanguageDB(InfrastructureLanguageModel infrastructureLanguageModel)
        {
            string retStr = InfrastructureLanguageModelOK(infrastructureLanguageModel);

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

            ContactOK contactOK = IsContactOK();

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

            InfrastructureLanguageModel infrastructureLanguageModelExist = GetInfrastructureLanguageModelWithInfrastructureIDAndLanguageDB(infrastructureLanguageModel.InfrastructureID, infrastructureLanguageModel.Language);

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

            InfrastructureLanguage infrastructureLanguageNew = new InfrastructureLanguage();

            retStr = FillInfrastructureLanguage(infrastructureLanguageNew, infrastructureLanguageModel, contactOK);
            if (!string.IsNullOrWhiteSpace(retStr))
            {
                return(ReturnError(retStr));
            }

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

                LogModel logModel = _LogService.PostAddLogForObj("InfrastructureLanguages", infrastructureLanguageNew.InfrastructureLanguageID, LogCommandEnum.Add, infrastructureLanguageNew);
                if (!string.IsNullOrWhiteSpace(logModel.Error))
                {
                    return(ReturnError(logModel.Error));
                }

                ts.Complete();
            }
            return(GetInfrastructureLanguageModelWithInfrastructureIDAndLanguageDB(infrastructureLanguageNew.InfrastructureID, infrastructureLanguageModel.Language));
        }
コード例 #10
0
        public void InfrastructureLanguageService_ReturnError_Test()
        {
            foreach (CultureInfo culture in setupData.cultureListGood)
            {
                SetupTest(contactModelListGood[0], culture);

                using (TransactionScope ts = new TransactionScope())
                {
                    string ErrorText = "ErrorText";
                    InfrastructureLanguageModel infrastructureLanguageModelRet = infrastructureLanguageService.ReturnError(ErrorText);

                    Assert.AreEqual(ErrorText, infrastructureLanguageModelRet.Error);
                }
            }
        }
コード例 #11
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);
            infrastructureLanguageService = new InfrastructureLanguageService((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);
            infrastructureLanguageModelNew = new InfrastructureLanguageModel();
            infrastructureLanguage         = new InfrastructureLanguage();
            infrastructureServiceTest      = new InfrastructureServiceTest();
            infrastructureServiceTest.SetupTest(contactModelToDo, culture);
        }
コード例 #12
0
        private InfrastructureLanguageModel UpdateInfrastructureLanguageModel(InfrastructureLanguageModel infrastructureLanguageModelRet)
        {
            FillInfrastructureLanguageModel(infrastructureLanguageModelRet);

            InfrastructureLanguageModel infrastructureLanguageModelRet2 = infrastructureLanguageService.PostUpdateInfrastructureLanguageDB(infrastructureLanguageModelRet);

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

            Assert.IsNotNull(infrastructureLanguageModelRet2);
            CompareInfrastructureLanguageModels(infrastructureLanguageModelRet, infrastructureLanguageModelRet2);

            return(infrastructureLanguageModelRet2);
        }
コード例 #13
0
        public InfrastructureLanguageModel PostUpdateInfrastructureLanguageDB(InfrastructureLanguageModel infrastructureLanguageModel)
        {
            string retStr = InfrastructureLanguageModelOK(infrastructureLanguageModel);

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

            ContactOK contactOK = IsContactOK();

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

            InfrastructureLanguage infrastructureLanguageToUpdate = GetInfrastructureLanguageWithInfrastructureIDAndLanguageDB(infrastructureLanguageModel.InfrastructureID, infrastructureLanguageModel.Language);

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

            retStr = FillInfrastructureLanguage(infrastructureLanguageToUpdate, infrastructureLanguageModel, 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("InfrastructureLanguages", infrastructureLanguageToUpdate.InfrastructureLanguageID, LogCommandEnum.Change, infrastructureLanguageToUpdate);
                if (!string.IsNullOrWhiteSpace(logModel.Error))
                {
                    return(ReturnError(logModel.Error));
                }

                ts.Complete();
            }
            return(GetInfrastructureLanguageModelWithInfrastructureIDAndLanguageDB(infrastructureLanguageToUpdate.InfrastructureID, (LanguageEnum)infrastructureLanguageToUpdate.Language));
        }
コード例 #14
0
        public void InfrastructureLanguageService_PostAddInfrastructureLanguageDB_UserEmailNotValidated_Test()
        {
            foreach (CultureInfo culture in setupData.cultureListGood)
            {
                SetupTest(contactModelListGood[2], culture);

                using (TransactionScope ts = new TransactionScope())
                {
                    LanguageEnum LangToAdd = LanguageEnum.es;

                    InfrastructureLanguageModel infrastructureLanguageModelRet = AddInfrastructureLanguageModel(LangToAdd);

                    // Assert 1
                    Assert.AreEqual(ServiceRes.EmailRequiresValidation, infrastructureLanguageModelRet.Error);
                }
            }
        }
コード例 #15
0
        public void InfrastructureLanguageService_PostAddInfrastructureLanguageDB_BadUser_Test()
        {
            foreach (CultureInfo culture in setupData.cultureListGood)
            {
                SetupTest(contactModelListBad[0], culture);

                using (TransactionScope ts = new TransactionScope())
                {
                    LanguageEnum LangToAdd = LanguageEnum.es;

                    InfrastructureLanguageModel infrastructureLanguageModelRet = AddInfrastructureLanguageModel(LangToAdd);

                    // Assert 1
                    Assert.AreEqual(ServiceRes.NeedToBeLoggedIn, infrastructureLanguageModelRet.Error);
                }
            }
        }
コード例 #16
0
        public void InfrastructureLanguageService_GetInfrastructureModelCountDB_Test()
        {
            foreach (CultureInfo culture in setupData.cultureListGood)
            {
                SetupTest(contactModelListGood[0], culture);

                using (TransactionScope ts = new TransactionScope())
                {
                    LanguageEnum LangToAdd = LanguageEnum.es;

                    InfrastructureLanguageModel infrastructureModelLanguageRet = AddInfrastructureLanguageModel(LangToAdd);

                    int infrastructureCount = infrastructureLanguageService.GetInfrastructureLanguageModelCountDB();
                    Assert.AreEqual(testDBService.Count + 3, infrastructureCount);
                }
            }
        }
コード例 #17
0
        public void InfrastructureLanguageService_GetInfrastructureLanguageWithInfrastructureIDAndLanguageDB_Test()
        {
            foreach (CultureInfo culture in setupData.cultureListGood)
            {
                SetupTest(contactModelListGood[0], culture);

                using (TransactionScope ts = new TransactionScope())
                {
                    LanguageEnum LangToAdd = LanguageEnum.es;

                    InfrastructureLanguageModel infrastructureLanguageModelRet = AddInfrastructureLanguageModel(LangToAdd);
                    Assert.AreEqual("", infrastructureLanguageModelRet.Error);

                    InfrastructureLanguage infrastructureLanguageRet2 = infrastructureLanguageService.GetInfrastructureLanguageWithInfrastructureIDAndLanguageDB(infrastructureLanguageModelRet.InfrastructureID, LangToAdd);
                    Assert.AreEqual(infrastructureLanguageModelRet.InfrastructureID, infrastructureLanguageRet2.InfrastructureID);
                    Assert.AreEqual(infrastructureLanguageModelRet.Language, (LanguageEnum)infrastructureLanguageRet2.Language);
                    Assert.AreEqual(LangToAdd, (LanguageEnum)infrastructureLanguageRet2.Language);
                }
            }
        }
コード例 #18
0
        public void InfrastructureLanguageService_PostAddInfrastructureLanguageDB_Good_Test()
        {
            foreach (CultureInfo culture in setupData.cultureListGood)
            {
                SetupTest(contactModelListGood[0], culture);

                using (TransactionScope ts = new TransactionScope())
                {
                    LanguageEnum LangToAdd = LanguageEnum.es;

                    InfrastructureLanguageModel infrastructureLanguageModelRet = AddInfrastructureLanguageModel(LangToAdd);
                    Assert.AreEqual("", infrastructureLanguageModelRet.Error);

                    InfrastructureLanguageModel infrastructureLanguageModelRet2 = UpdateInfrastructureLanguageModel(infrastructureLanguageModelRet);
                    Assert.AreEqual("", infrastructureLanguageModelRet2.Error);

                    InfrastructureLanguageModel infrastructureLanguageModelRet3 = infrastructureLanguageService.PostDeleteInfrastructureLanguageDB(infrastructureLanguageModelRet2.InfrastructureID, LangToAdd);
                    Assert.AreEqual("", infrastructureLanguageModelRet3.Error);
                }
            }
        }
コード例 #19
0
        public void InfrastructureLanguageService_PostAddInfrastructureLanguageDB_GetInfrastructureLanguageModelWithInfrastructureIDAndLanguageDB_Error_Test()
        {
            foreach (CultureInfo culture in setupData.cultureListGood)
            {
                SetupTest(contactModelListGood[0], culture);

                using (TransactionScope ts = new TransactionScope())
                {
                    using (ShimsContext.Create())
                    {
                        SetupShim();
                        LanguageEnum LangToAdd = LanguageEnum.es;

                        //string ErrorText = "ErrorText";
                        shimInfrastructureLanguageService.GetInfrastructureLanguageModelWithInfrastructureIDAndLanguageDBInt32LanguageEnum = (a, b) =>
                        {
                            return(new InfrastructureLanguageModel());
                        };
                        InfrastructureLanguageModel infrastructureLanguageModelRet = AddInfrastructureLanguageModel(LangToAdd);
                        Assert.AreEqual(string.Format(ServiceRes._AlreadyExists, ServiceRes.InfrastructureLanguage), infrastructureLanguageModelRet.Error);
                    }
                }
            }
        }
コード例 #20
0
 private void CompareInfrastructureLanguageModels(InfrastructureLanguageModel infrastructureLanguageModelNew, InfrastructureLanguageModel infrastructureLanguageModelRet)
 {
     Assert.AreEqual(infrastructureLanguageModelNew.Language, infrastructureLanguageModelRet.Language);
     Assert.AreEqual(infrastructureLanguageModelNew.Comment, infrastructureLanguageModelRet.Comment);
 }
コード例 #21
0
        // Fill
        public string FillInfrastructureLanguage(InfrastructureLanguage infrastructureLanguageNew, InfrastructureLanguageModel infrastructureLanguageModel, ContactOK contactOK)
        {
            infrastructureLanguageNew.DBCommand          = (int)infrastructureLanguageModel.DBCommand;
            infrastructureLanguageNew.InfrastructureID   = infrastructureLanguageModel.InfrastructureID;
            infrastructureLanguageNew.Language           = (int)infrastructureLanguageModel.Language;
            infrastructureLanguageNew.TranslationStatus  = (int)infrastructureLanguageModel.TranslationStatus;
            infrastructureLanguageNew.Comment            = infrastructureLanguageModel.Comment;
            infrastructureLanguageNew.LastUpdateDate_UTC = DateTime.UtcNow;
            if (contactOK == null)
            {
                infrastructureLanguageNew.LastUpdateContactTVItemID = 2;
            }
            else
            {
                infrastructureLanguageNew.LastUpdateContactTVItemID = contactOK.ContactTVItemID;
            }

            return("");
        }