System.Tests.StringTests.Substring_Invalid C# (CSharp) Method

Substring_Invalid() private method

private Substring_Invalid ( ) : void
return void
        public static void Substring_Invalid()
        {
            // Start index < 0
            Assert.Throws<ArgumentOutOfRangeException>("startIndex", () => "foo".Substring(-1));
            Assert.Throws<ArgumentOutOfRangeException>("startIndex", () => "foo".Substring(-1, 0));

            // Start index > string.Length
            Assert.Throws<ArgumentOutOfRangeException>("startIndex", () => "foo".Substring(4));
            Assert.Throws<ArgumentOutOfRangeException>("startIndex", () => "foo".Substring(4, 0));

            // Length < 0 or length > string.Length
            Assert.Throws<ArgumentOutOfRangeException>("length", () => "foo".Substring(0, -1));
            Assert.Throws<ArgumentOutOfRangeException>("length", () => "foo".Substring(0, 4));

            // Start index + length > string.Length
            Assert.Throws<ArgumentOutOfRangeException>("length", () => "foo".Substring(3, 2));
            Assert.Throws<ArgumentOutOfRangeException>("length", () => "foo".Substring(2, 2));
        }
StringTests