예제 #1
0
        public void Init()
        {
            var loggerStub          = Substitute.For <ILog>();
            var strategyFactoryStub = Substitute.For <ITranslationStrategyFactory>();

            _strategyStub = Substitute.For <ITranslationStrategy>();
            strategyFactoryStub.CreateForMethod(Arg.Is("leetspeak")).Returns(_strategyStub);
            strategyFactoryStub.CreateForMethod(Arg.Is("NotExistingMethod")).Returns((ITranslationStrategy)null);

            _service = new TranslationService(strategyFactoryStub, loggerStub);
        }
예제 #2
0
        /// <summary>
        /// Transforms the passed text into a friendly url (slug)
        /// using the provided Separator and the provided Strategy or Strategies.
        /// </summary>
        /// <param name="text">The text to be translated.</param>
        /// <param name="separator">The separator to be used when encoutering whitespaces.</param>
        /// <param name="strategy">The strategy or strategies to provide extra transformations.</param>
        /// <returns>The text transformed into a friendly url (slug) using the provided separator and strategies.</returns>
        /// <exception cref="ArgumentNullException">Thrown when text is null.</exception>
        public static string ToSlug(this string text, string separator, ITranslationStrategy strategy)
        {
            if (text == null)
            {
                throw new ArgumentNullException(nameof(text));
            }

            return(text
                   .Split()
                   .Where(t => t.Length != 0)
                   .Select(t => strategy.Translate(t))
                   .Join(separator));
        }
예제 #3
0
 public GoogleTranslationService(ITranslationStrategy translationStrategy)
 {
     _translationStrategy = translationStrategy;
 }
예제 #4
0
 public static string Translate(string phrase,
                                ITranslationStrategy strategy)
 {
     return(strategy.Translate(phrase));
 }
예제 #5
0
 /// <summary>
 /// Transforms the passed text into a friendly url (slug)
 /// using the default Separator "-" and the provided Strategy or Strategies.
 /// </summary>
 /// <param name="text">The text to be translated.</param>
 /// <param name="strategy">The strategy or strategies to provide extra transformations.</param>
 /// <returns>The text transformed into a friendly url (slug) using the provided separator.</returns>
 /// <exception cref="ArgumentNullException">Thrown when text is null.</exception>
 public static string ToSlug(this string text, ITranslationStrategy strategy) => ToSlug(text, DefaultSeparator, strategy);