/// <summary> /// Combines an array of strings into a localized List string using the specified <see cref="CultureInfo"/> /// </summary> /// <param name="culture">A <see cref="CultureInfo"/></param> /// <param name="type">A <see cref="ListTypeValues"/></param> /// <param name="style">A <see cref="IntlStyleValues"/></param> /// <param name="values">An array of strings</param> /// <returns>A localized List string</returns> /// <exception cref="ArgumentNullException"></exception> /// <exception cref="ArgumentException"></exception> public string Format( CultureInfo culture, ListTypeValues type = ListTypeValues.Conjunction, IntlStyleValues style = IntlStyleValues.Long, params string[] values) { return(values switch { null => throw new ArgumentNullException(nameof(values), "values is null"), string[] v when v.Length == 0 => string.Empty, string[] v when v.Length == 1 => v[0], _ => type switch { ListTypeValues.Unknown => throw new ArgumentException("ListTypeValues.Unknown is not supported", nameof(type)), _ => style switch { IntlStyleValues.Unknown => throw new ArgumentException("IntlStyleValues.Unknown is not supported", nameof(style)), _ => this.FormatInternal(culture, type, style, values) } } });
public void FormatValues_WithCulture_WithTypeAndStyle_ShouldReturn_ExpectedValue(string expected, ListTypeValues listType, IntlStyleValues intStyle, params string[] values) { string formatted = this.Fixture.Formatter.Format(new CultureInfo("en"), listType, intStyle, values); Assert.Equal(expected, formatted); }
public void FormatValues_WithoutCulture_WithType_ShouldReturn_ExpectedValue(string expected, ListTypeValues listType, params string[] values) { Thread.CurrentThread.CurrentCulture = new CultureInfo("en"); string formatted = this.Fixture.Formatter.Format(listType, values); Assert.Equal(expected, formatted); }
/// <summary> /// Combines an array of strings into a localized List string using the specified <see cref="CultureInfo"/> /// </summary> /// <param name="culture">A <see cref="CultureInfo"/></param> /// <param name="type">A <see cref="ListTypeValues"/></param> /// <param name="values">An array of strings</param> /// <returns>A localized List string</returns> /// <exception cref="ArgumentNullException"></exception> /// <exception cref="ArgumentException"></exception> public string Format( CultureInfo culture, ListTypeValues type = ListTypeValues.Conjunction, params string[] values) => this.Format(culture, type, IntlStyleValues.Long, values);
/// <summary> /// Combines an array of strings into a localized List string using the <see cref="CultureInfo.CurrentCulture"/> /// </summary> /// <param name="type">A <see cref="ListTypeValues"/></param> /// <param name="style">A <see cref="IntlStyleValues"/></param> /// <param name="values">An array of strings</param> /// <returns>A localized List string</returns> /// <exception cref="ArgumentNullException"></exception> /// <exception cref="ArgumentException"></exception> public string Format( ListTypeValues type = ListTypeValues.Conjunction, IntlStyleValues style = IntlStyleValues.Long, params string[] values) => this.Format(CultureInfo.CurrentCulture, type, style, values);