Beispiel #1
0
        //returns "MODEL.Language" object if successful/found
        //returns "null" if not
        internal Language findLanguageByLanguageId(int languageId)
        {
            int      result   = (int)CODE.MINUS_ONE;
            Language language = null;

            //validate languageId
            if (
                result == (int)CODE.ZERO ||
                string.IsNullOrWhiteSpace(languageId.ToString()) ||
                !Validate.isAllNumbers(languageId.ToString()) ||
                !Validate.integerIsBiggerThan(languageId, (int)CODE.TRANSLATO_DATABASE_SEED - 1)
                )
            {
                result = (int)CODE.ZERO;
            }
            if (result != (int)CODE.ZERO)//safe to proceed
            {
                ILanguages _DbLanguages = new DbLanguages();

                try
                {
                    using (var trScope = TransactionScopeBuilder.CreateSerializable())
                    {
                        language = _DbLanguages.findLanguageByLanguageId(languageId);

                        trScope.Complete();
                    }
                }
                catch (TransactionAbortedException taEx)
                {
                    result = (int)CODE.ZERO;
                    Log.Add(taEx.ToString());
                }
                catch (ApplicationException aEx)
                {
                    result = (int)CODE.ZERO;
                    Log.Add(aEx.ToString());
                }
                catch (Exception ex)
                {
                    result = (int)CODE.ZERO;
                    Log.Add(ex.ToString());
                }
            }
            else
            {
                result = (int)CODE.ZERO;
            }

            if (result == (int)CODE.ZERO || language == null)
            {
                return(null);
            }
            else
            {
                return(language);
            }
        }
        public void GetLanguagesReturnsValidLanguageCollection()
        {
            var en = Language.Parse("en");
            var da = Language.Parse("da");
            var expected = new LanguageCollection { en, da };
            var sut = new DbLanguages(en, da);

            var actual = sut.GetLanguages();

            actual.ShouldAllBeEquivalentTo(expected);
        }
Beispiel #3
0
        //returns [int >= TRANSLATO_DATABASE_SEED] if successful
        //returns [int < TRANSLATO_DATABASE_SEED] if not
        internal int insertLanguage(Language language)
        {
            int returnCode = (int)CODE.ZERO;
            int result     = (int)CODE.MINUS_ONE;

            //validate languageName
            if (
                result == (int)CODE.ZERO ||
                returnCode != (int)CODE.ZERO ||
                string.IsNullOrWhiteSpace(language.languageName) ||
                !Validate.hasMinLength(language.languageName, 1) ||
                !Validate.hasMaxLength(language.languageName, 15) ||
                !Validate.isAllLetters(language.languageName)
                )
            {
                returnCode = (int)CODE.CTRLANGUAGE_INSERTLANGUAGE_INVALIDLANGUAGENAME; result = (int)CODE.ZERO;
            }
            if (returnCode == (int)CODE.ZERO && result != (int)CODE.ZERO)//safe to proceed
            {
                language.languageName = language.languageName;

                ILanguages _DbLanguages = new DbLanguages();

                try
                {
                    using (var trScope = TransactionScopeBuilder.CreateSerializable())
                    {
                        returnCode = _DbLanguages.insertLanguage(language);

                        trScope.Complete();
                    }
                }
                catch (TransactionAbortedException taEx)
                {
                    returnCode = (int)CODE.CTRLANGUAGE_INSERTLANGUAGE_EXCEPTION;
                    Log.Add(taEx.ToString());
                }
                catch (ApplicationException aEx)
                {
                    returnCode = (int)CODE.CTRLANGUAGE_INSERTLANGUAGE_EXCEPTION;
                    Log.Add(aEx.ToString());
                }
                catch (Exception ex)
                {
                    returnCode = (int)CODE.CTRLANGUAGE_INSERTLANGUAGE_EXCEPTION;
                    Log.Add(ex.ToString());
                }
            }
            else
            {
            }
            return(returnCode);
        }
Beispiel #4
0
        public void GetLanguagesReturnsValidLanguageCollection()
        {
            var en       = Language.Parse("en");
            var da       = Language.Parse("da");
            var expected = new LanguageCollection {
                en, da
            };
            var sut = new DbLanguages(en, da);

            var actual = sut.GetLanguages();

            actual.ShouldAllBeEquivalentTo(expected);
        }
 public void GetLanguagesReturnsLanguagesIfSwitched(
     SwitchingLanguageDataProvider sut,
     CallContext context)
 {
     var en = Language.Parse("en");
     var da = Language.Parse("da");
     var contextLanguages = new DbLanguages(en, da);
     using (new Switcher<DbLanguages>(contextLanguages))
     {
         sut.GetLanguages(context)
             .ShouldAllBeEquivalentTo(new[] { en, da });
     }
 }
        public void GetLanguagesReturnsLanguagesIfSwitched(
            SwitchingLanguageDataProvider sut,
            CallContext context)
        {
            var en = Language.Parse("en");
            var da = Language.Parse("da");
            var contextLanguages = new DbLanguages(en, da);

            using (new Switcher <DbLanguages>(contextLanguages))
            {
                sut.GetLanguages(context)
                .ShouldAllBeEquivalentTo(new[] { en, da });
            }
        }
        //returns [int >= TRANSLATO_DATABASE_SEED] if successful
        //returns [int < TRANSLATO_DATABASE_SEED] if not
        internal int insertLanguage(Language language)
        {
            int returnCode = (int)CODE.ZERO;
            int result = (int)CODE.MINUS_ONE;

            //validate languageName
            if (
                result == (int)CODE.ZERO ||
                returnCode != (int)CODE.ZERO ||
                string.IsNullOrWhiteSpace(language.languageName) ||
                !Validate.hasMinLength(language.languageName, 1) ||
                !Validate.hasMaxLength(language.languageName, 15) ||
                !Validate.isAllLetters(language.languageName)
               ) { returnCode = (int)CODE.CTRLANGUAGE_INSERTLANGUAGE_INVALIDLANGUAGENAME; result = (int)CODE.ZERO; }
            if (returnCode == (int)CODE.ZERO && result != (int)CODE.ZERO)//safe to proceed
            {
                language.languageName = language.languageName;

                ILanguages _DbLanguages = new DbLanguages();

                try
                {
                    using (var trScope = TransactionScopeBuilder.CreateSerializable())
                    {
                        returnCode = _DbLanguages.insertLanguage(language);

                        trScope.Complete();
                    }
                }
                catch (TransactionAbortedException taEx)
                {
                    returnCode = (int)CODE.CTRLANGUAGE_INSERTLANGUAGE_EXCEPTION;
                    Log.Add(taEx.ToString());
                }
                catch (ApplicationException aEx)
                {
                    returnCode = (int)CODE.CTRLANGUAGE_INSERTLANGUAGE_EXCEPTION;
                    Log.Add(aEx.ToString());
                }
                catch (Exception ex)
                {
                    returnCode = (int)CODE.CTRLANGUAGE_INSERTLANGUAGE_EXCEPTION;
                    Log.Add(ex.ToString());
                }
            }
            else { }
            return returnCode;
        }
        //LAYER_Class_NameOfTheMethod_TestedScenario_ExpectedBehaviour
        public void DAL_ILanguage_InsertLanguage_InsertLanguage_LanguageIsInserted()
        {
            //arrange
            int languageId = 1;
            string languageName = "English";
            Language language_m1 = new Language(
                languageId,
                languageName
                );
            ILanguages _DbLanguages = new DbLanguages();

            //act
            int result = _DbLanguages.insertLanguage(language_m1);

            //assert
            Assert.IsTrue(result>=(int)ENUM.CODE.TRANSLATO_DATABASE_SEED,"language not inserted");
        }
        //LAYER_Class_NameOfTheMethod_TestedScenario_ExpectedBehaviour
        public void DAL_ILanguage_InsertLanguage_InsertLanguage_LanguageIsInserted()
        {
            //arrange
            int      languageId   = 1;
            string   languageName = "English";
            Language language_m1  = new Language(
                languageId,
                languageName
                );
            ILanguages _DbLanguages = new DbLanguages();

            //act
            int result = _DbLanguages.insertLanguage(language_m1);

            //assert
            Assert.IsTrue(result >= (int)ENUM.CODE.TRANSLATO_DATABASE_SEED, "language not inserted");
        }
        //returns "MODEL.Language" object if successful/found
        //returns "null" if not
        internal Language findLanguageByLanguageId(int languageId)
        {
            int result = (int)CODE.MINUS_ONE;
            Language language = null;

            //validate languageId
            if (
                result == (int)CODE.ZERO ||
                string.IsNullOrWhiteSpace(languageId.ToString()) ||
                !Validate.isAllNumbers(languageId.ToString()) ||
                !Validate.integerIsBiggerThan(languageId, (int)CODE.TRANSLATO_DATABASE_SEED - 1)
               ) { result = (int)CODE.ZERO; }
            if (result != (int)CODE.ZERO)//safe to proceed
            {
                ILanguages _DbLanguages = new DbLanguages();

                try
                {
                    using (var trScope = TransactionScopeBuilder.CreateSerializable())
                    {
                        language = _DbLanguages.findLanguageByLanguageId(languageId);

                        trScope.Complete();
                    }
                }
                catch (TransactionAbortedException taEx)
                {
                    result = (int)CODE.ZERO;
                    Log.Add(taEx.ToString());
                }
                catch (ApplicationException aEx)
                {
                    result = (int)CODE.ZERO;
                    Log.Add(aEx.ToString());
                }
                catch (Exception ex)
                {
                    result = (int)CODE.ZERO;
                    Log.Add(ex.ToString());
                }
            }
            else { result = (int)CODE.ZERO; }

            if (result == (int)CODE.ZERO || language == null) { return null; }
            else { return language; }
        }