public static void Parse_Invalid(string value, NumberStyles style, IFormatProvider provider, Type exceptionType) { bool isDefaultProvider = provider == null || provider == NumberFormatInfo.InvariantInfo; if (provider == null) { provider = NumberFormatInfo.InvariantInfo; } decimal result; if ((style & ~NumberStyles.Integer) == 0 && style != NumberStyles.None && (style & NumberStyles.AllowLeadingWhite) == (style & NumberStyles.AllowTrailingWhite)) { // Use Parse(string) or Parse(string, IFormatProvider) if (isDefaultProvider) { //Assert.IsFalse(Decimal2.TryParse(value, out result)); //Assert.AreEqual(default(decimal), result); //AssertExtensions.Throws(exceptionType, () => Decimal2.Parse(value)); } AssertExtensions.Throws(exceptionType, () => Decimal2.Parse(value, provider)); } // Use Parse(string, NumberStyles, IFormatProvider) Assert.IsFalse(Decimal2.TryParse(value, style, provider, out result)); Assert.AreEqual(default(decimal), result); AssertExtensions.Throws(exceptionType, () => Decimal2.Parse(value, style, provider)); if (isDefaultProvider) { // Use Parse(string, NumberStyles) or Parse(string, NumberStyles, IFormatProvider) Assert.IsFalse(Decimal2.TryParse(value, style, NumberFormatInfo.InvariantInfo, out result)); Assert.AreEqual(default(decimal), result); //AssertExtensions.Throws(exceptionType, () => Decimal2.Parse(value, style)); AssertExtensions.Throws(exceptionType, () => Decimal2.Parse(value, style, NumberFormatInfo.InvariantInfo)); } }
public static void Parse(string value, NumberStyles style, IFormatProvider provider, decimal expected) { bool isDefaultProvider = provider == null || provider == NumberFormatInfo.InvariantInfo; if (provider == null) { provider = NumberFormatInfo.InvariantInfo; } decimal result; if ((style & ~NumberStyles.Integer) == 0 && style != NumberStyles.None) { // Use Parse(string) or Parse(string, IFormatProvider) if (isDefaultProvider) { Assert.IsTrue(Decimal2.TryParse(value, out result)); Assert.AreEqual(expected, result); Assert.AreEqual(expected, Decimal2.Parse(value)); } Assert.AreEqual(expected, Decimal2.Parse(value, provider)); } // Use Parse(string, NumberStyles, IFormatProvider) Assert.IsTrue(Decimal2.TryParse(value, style, provider, out result), "Error parsing: {0}", value); Assert.AreEqual(expected, result); Assert.AreEqual(expected, Decimal2.Parse(value, style, provider)); if (isDefaultProvider) { // Use Parse(string, NumberStyles) or Parse(string, NumberStyles, IFormatProvider) Assert.IsTrue(Decimal2.TryParse(value, style, NumberFormatInfo.InvariantInfo, out result)); Assert.AreEqual(expected, result); //Assert.AreEqual(expected, Decimal2.Parse(value, style)); Assert.AreEqual(expected, Decimal2.Parse(value, style, NumberFormatInfo.InvariantInfo)); } }