예제 #1
0
        public void ExportTestEnum_ContainsTranslationsForEachEntry()
        {
            var catalog = DoExport(typeof(TestEnum));

            Assert.True(HasTranslation(catalog, TranslationAttribute.GetValue(TestEnum.FirstValue)));
            Assert.True(HasTranslation(catalog, TranslationAttribute.GetValue(TestEnum.SecondValue)));
            Assert.True(HasTranslation(catalog, TranslationAttribute.GetValue(TestEnum.ThirdValue)));
        }
예제 #2
0
        public void ExportThisAssembly_ContainsTranslations()
        {
            var catalog     = ExportCurrentAssembly();
            var translation = new TestTranslation();

            Assert.Equal(9, catalog.Entries.Count);

            Assert.True(HasTranslation(catalog, translation.Title));
            Assert.True(HasTranslation(catalog, TranslationAttribute.GetValue(TestEnum.FirstValue)));
        }
예제 #3
0
        public void WhenProfileInvalid_DisplaysErrorMessage()
        {
            var expectedError = ErrorCode.Smtp_NoPasswordSpecified;

            _smtpAction.ProcessJob(Arg.Any <Job>()).Returns(x => new ActionResult(expectedError));
            var assistant = BuildAssistant();

            assistant.SendTestMail(_profile, _accounts);

            _interactionRequest.AssertWasRaised <MessageInteraction>();
            var messageInteraction = _interactionRequest.AssertWasRaised <MessageInteraction>();

            Assert.AreEqual(_translation.SendTestMail, messageInteraction.Title);
            Assert.AreEqual(TranslationAttribute.GetValue(expectedError), messageInteraction.Text);
            Assert.AreEqual(MessageIcon.Error, messageInteraction.Icon);
        }
예제 #4
0
        public void WhenSendingMailFails_ShowsErrorMessage()
        {
            var expectedError = ErrorCode.Smtp_AuthenticationDenied;

            _smtpAction.ProcessJob(Arg.Any <Job>()).Returns(new ActionResult(expectedError));
            var assistant = BuildAssistant();

            assistant.SendTestMail(_profile, _accounts);

            _interactionRequest.AssertWasRaised <MessageInteraction>();

            var messageInteraction = _interactionRequest.AssertWasRaised <MessageInteraction>();

            Assert.AreEqual(_translation.SendTestMail, messageInteraction.Title);
            Assert.AreEqual(TranslationAttribute.GetValue(expectedError), messageInteraction.Text);
            Assert.AreEqual(MessageIcon.Error, messageInteraction.Icon);
        }
예제 #5
0
        public void WhenSendingMailFails_ShowsErrorMessage()
        {
            var translation   = new SmtpSettingsAndActionControlTranslation();
            var expectedError = ErrorCode.Smtp_AuthenticationDenied;

            _smtpAction.ProcessJob(Arg.Any <Job>()).Returns(new ActionResult(expectedError));
            var assistant = BuildAssistant();

            assistant.SendTestMail(_profile, new Accounts());

            _interactionInvoker.Received().Invoke(Arg.Any <MessageInteraction>());

            var messageInteraction =
                _interactions.Where(x => x is MessageInteraction).Cast <MessageInteraction>().First();

            Assert.AreEqual(translation.SendTestMail, messageInteraction.Title);
            Assert.AreEqual(TranslationAttribute.GetValue(expectedError), messageInteraction.Text);
            Assert.AreEqual(MessageIcon.Error, messageInteraction.Icon);
        }
예제 #6
0
        public void WhenProfileInvalid_DisplaysErrorMessage()
        {
            var translation   = new SmtpSettingsAndActionControlTranslation();
            var expectedError = ErrorCode.Smtp_NoPasswordSpecified;

            _smtpAction.Check(_profile, Arg.Any <Accounts>()).Returns(x => new ActionResult(expectedError));
            var assistant = BuildAssistant();

            assistant.SendTestMail(_profile, new Accounts());

            _interactionInvoker.Received().Invoke(Arg.Any <MessageInteraction>());

            var messageInteraction =
                _interactions.Where(x => x is MessageInteraction).Cast <MessageInteraction>().First();

            var errorCodeInt = (int)expectedError;

            Assert.AreEqual(translation.SendTestMail, messageInteraction.Title);
            Assert.AreEqual(TranslationAttribute.GetValue(expectedError), messageInteraction.Text);
            Assert.AreEqual(MessageIcon.Error, messageInteraction.Icon);
        }
예제 #7
0
        /// <summary>
        /// Obtém a tradução de um item do enum
        /// </summary>
        /// <typeparam name="TEnum">Tipo do enum que será traduzido</typeparam>
        /// <param name="enumValue">Item que será traduzido</param>
        /// <param name="resManager">Repositório com as traduções</param>
        /// <param name="culture">Idioma utilizado para a tradução</param>
        /// <returns></returns>
        private static string GetTranslation <TEnum>(TEnum enumValue, ResourceManager resManager, CultureInfo culture)
        {
            Type   enumType = typeof(TEnum);
            string enumName = Enum.GetName(enumType, enumValue);

            TranslationAttribute att = (TranslationAttribute)Attribute.GetCustomAttribute(enumType.GetField(enumName), typeof(TranslationAttribute));

            if (att != null)
            {
                if (att.Displayable)
                {
                    return(resManager.GetString(att.ResourceName, culture));
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(enumName);
            }
        }
예제 #8
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var sourceType = value.GetType();

            if (!sourceType.IsEnum)
            {
                throw new InvalidOperationException("The target must be an enum");
            }

            if (_translationFactory?.TranslationSource == null)
            {
                return(null);
            }

            try
            {
                return(_translationFactory.TranslationSource.GetTranslation(TranslationAttribute.GetValue(value)));
            }
            catch
            {
                return(value.ToString());
            }
        }