public void TestExpansion_Formattable() { StringMaker sm; string expected; string actual; Formattable o = default; for (int capacity = 0; capacity < 20; capacity++) { #if PUBLIC_STRINGMAKER sm = new StringMaker(capacity); sm.Append(o); actual = sm.ExtractString(); expected = string.Format("{0}", o); Assert.Equal(expected, actual); sm.Dispose(); #endif for (int width = -10; width < 10; width++) { sm = new StringMaker(capacity); sm.Append(o, string.Empty, null, width); actual = sm.ExtractString(); expected = string.Format(string.Format("{{0,{0}}}", width), o); Assert.Equal(expected, actual); sm.Dispose(); } } #if PUBLIC_STRINGMAKER sm = new StringMaker(Array.Empty <char>(), true); sm.Append(o); Assert.True(sm.Overflowed); Assert.Equal(string.Empty, sm.ExtractString()); sm.Dispose(); #endif sm = new StringMaker(Array.Empty <char>(), true); sm.Append(o, string.Empty, null, 0); Assert.True(sm.Overflowed); Assert.Equal(string.Empty, sm.ExtractSpan().ToString()); Assert.Equal(string.Empty, sm.ExtractString()); sm.Dispose(); }
private string createLink(string format, int amountCents) { if (amountCents <= 0) { throw new ArgumentOutOfRangeException("amountCents", "must be positive"); } if (string.IsNullOrEmpty(format)) { throw new NotSupportedException(""); } var param = new Formattable[] { new Formattable(UserName), new Formattable((amountCents / 100d).ToString("0.00")), }; return(string.Format(format, param)); }