public void SpecificCulture_ShouldReturn_LocalizedResource(
            double value,
            RelativeTimeUnitValues unit,
            IntlStyleValues style,
            RelativeTimeNumericValues numericFormat,
            string expected)
        {
            string localized = this.Fixture.Formatter.Format(
                value,
                new CultureInfo("fr"),
                unit,
                style,
                numericFormat);

            Assert.Equal(expected, localized);
        }
        public void CurrentCulture_ShouldReturn_LocalizedResource(
            double value,
            RelativeTimeUnitValues unit,
            IntlStyleValues style,
            RelativeTimeNumericValues numericFormat,
            string expected)
        {
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en");
            string localized = this.Fixture.Formatter.Format(
                value,
                unit,
                style,
                numericFormat);

            Assert.Equal(expected, localized);
        }
Пример #3
0
 /// <summary>
 /// Format the current value to a localized relative time using the specified <see cref="CultureInfo"/>
 /// </summary>
 /// <param name="value">The value to format</param>
 /// <param name="culture">The <see cref="CultureInfo"/> to use</param>
 /// <param name="unit">The <see cref="RelativeTimeUnitValues"/> used for formatting, default: RelativeTimeUnitValues.Second</param>
 /// <param name="style">The <see cref="IntlStyleValues"/> used for formatting, default: IntlStyleValues.Long</param>
 /// <param name="numericFormat">The <see cref="RelativeTimeNumericValues"/> used for formatting, default: RelativeTimeNumericValues.Always</param>
 /// <returns>The relative time localized resource of the specified value</returns>
 /// <exception cref="ArgumentException"></exception>
 /// <exception cref="ArgumentNullException"></exception>
 /// <exception cref="CultureNotFoundException"></exception>
 /// <exception cref="NotImplementedException"></exception>
 public string Format(
     double value,
     CultureInfo culture,
     RelativeTimeUnitValues unit             = RelativeTimeUnitValues.Second,
     IntlStyleValues style                   = IntlStyleValues.Long,
     RelativeTimeNumericValues numericFormat = RelativeTimeNumericValues.Always)
 {
     return(unit switch
     {
         RelativeTimeUnitValues.Unknown => throw new ArgumentException("RelativeTimeUnitValues.Unknown is not supported", nameof(unit)),
         _ => style switch
         {
             IntlStyleValues.Unknown => throw new ArgumentException("IntlStyleValues.Unknown is not supported", nameof(style)),
             _ => numericFormat switch
             {
                 RelativeTimeNumericValues.Unknown => throw new ArgumentException("RelativeTimeNumericValues.Unknown is not supported", nameof(unit)),
                 _ => this.FormatInternal(value, culture, unit, style, numericFormat)
             }
         }
     });
Пример #4
0
 /// <summary>
 /// Format the current value to a localized relative time using <see cref="CultureInfo.CurrentCulture"/>
 /// </summary>
 /// <param name="value">The value to format</param>
 /// <param name="unit">The <see cref="RelativeTimeUnitValues"/> used for formatting, default: RelativeTimeUnitValues.Second</param>
 /// <param name="style">The <see cref="IntlStyleValues"/> used for formatting, default: IntlStyleValues.Long</param>
 /// <param name="numericFormat">The <see cref="RelativeTimeNumericValues"/> used for formatting, default: RelativeTimeNumericValues.Always</param>
 /// <returns>The relative time localized resource of the specified value</returns>
 /// <exception cref="ArgumentException"></exception>
 /// <exception cref="ArgumentNullException"></exception>
 /// <exception cref="CultureNotFoundException"></exception>
 /// <exception cref="NotImplementedException"></exception>
 public string Format(
     double value,
     RelativeTimeUnitValues unit             = RelativeTimeUnitValues.Second,
     IntlStyleValues style                   = IntlStyleValues.Long,
     RelativeTimeNumericValues numericFormat = RelativeTimeNumericValues.Always)
 => this.Format(value, CultureInfo.CurrentCulture, unit, style, numericFormat);