Exemplo n.º 1
0
 public void Apply_NullTokens_ThrowsArugmentNullException()
 {
     ExceptionAssert.CatchArgumentNullException(() =>
     {
         StringFormatter.Apply(Int32.MinValue, "0", CultureInfo.InvariantCulture, null);
     },
                                                "tokens");
 }
Exemplo n.º 2
0
 public void Apply_InvalidFormat_ThrowsFormatException()
 {
     Assert.Catch <FormatException>(() =>
     {
         StringFormatter.Apply(Int32.MinValue, "\\", CultureInfo.InvariantCulture, new Dictionary <char, Func <Int32, IFormatProvider, string> >());
     },
                                    "Input string was not in a correct format.");
 }
Exemplo n.º 3
0
 public void Apply_NullFormatProvider_ThrowsArugmentNullException()
 {
     ExceptionAssert.CatchArgumentNullException(() =>
     {
         StringFormatter.Apply(Int32.MinValue, "0", null, null);
     },
                                                "formatProvider");
 }
Exemplo n.º 4
0
 public void Apply_NullFormat_ThrowsArugmentNullException()
 {
     ExceptionAssert.CatchArgumentNullException(() =>
     {
         StringFormatter.Apply <object>(new object(), null, null, null);
     },
                                                "format");
 }
Exemplo n.º 5
0
 public void Apply_StringEmptyFormat_ThrowsArugmentException()
 {
     ExceptionAssert.CatchArgumentException(() =>
     {
         StringFormatter.Apply(new object(), string.Empty, null, null);
     },
                                            "format",
                                            "Value cannot be an empty string.");
 }
Exemplo n.º 6
0
        /// <summary>Returns a formatted <see cref="string"/> that represents the current month.</summary>
        /// <param name="format">
        /// The format that this describes the formatting.
        /// </param>
        /// <param name="formatProvider">
        /// The format provider.
        /// </param>
        /// <remarks>
        /// The formats:
        ///
        /// f: as full name.
        /// s: as short name.
        /// M: as number with leading zero.
        /// m: as number without leading zero.
        /// </remarks>
        public string ToString(string format, IFormatProvider formatProvider)
        {
            string formatted;

            if (StringFormatter.TryApplyCustomFormatter(format, this, formatProvider, out formatted))
            {
                return(formatted);
            }
            // Apply the format.
            return(StringFormatter.Apply(this, string.IsNullOrEmpty(format) ? "M" : format, formatProvider ?? CultureInfo.CurrentCulture, FormatTokens));
        }
Exemplo n.º 7
0
 /// <summary>Returns a formatted <see cref="string"/> that represents the current IBAN.</summary>
 /// <param name="format">
 /// The format that this describes the formatting.
 /// </param>
 /// <param name="formatProvider">
 /// The format provider.
 /// </param>
 /// <remarks>
 /// The formats:
 ///
 /// u: as unformatted lowercase.
 /// U: as unformatted uppercase.
 /// f: as formatted lowercase.
 /// F: as formatted uppercase.
 /// </remarks>
 public string ToString(string format, IFormatProvider formatProvider)
 {
     if (StringFormatter.TryApplyCustomFormatter(format, this, formatProvider, out string formatted))
     {
         return(formatted);
     }
     // If no format specified, use the default format.
     if (string.IsNullOrEmpty(format))
     {
         return(ToUnformattedString());
     }
     // Apply the format.
     return(StringFormatter.Apply(this, format, formatProvider, FormatTokens));
 }
Exemplo n.º 8
0
        /// <summary>Returns a formatted <see cref="string"/> that represents the current week date.</summary>
        /// <param name="format">
        /// The format that this describes the formatting.
        /// </param>
        /// <param name="formatProvider">
        /// The format provider.
        /// </param>
        /// <remarks>
        /// The formats:
        ///
        /// y: as year.
        /// w: as week with leading zero.
        /// W: as week without leading zero.
        /// d: as day.
        /// </remarks>
        public string ToString(string format, IFormatProvider formatProvider)
        {
            if (StringFormatter.TryApplyCustomFormatter(format, this, formatProvider, out string formatted))
            {
                return(formatted);
            }

            // If no format specified, use the default format.
            if (string.IsNullOrEmpty(format))
            {
                format = @"y-\Ww-d";
            }

            // Apply the format.
            return(StringFormatter.Apply(this, format, formatProvider ?? CultureInfo.InvariantCulture, FormatTokens));
        }