public void TestArgumentExceptions() { AuthenticationResults authres; var buffer = new byte[16]; Assert.Throws <ArgumentNullException> (() => new AuthenticationResults(null)); Assert.Throws <ArgumentNullException> (() => new AuthenticationMethodResult(null)); Assert.Throws <ArgumentNullException> (() => new AuthenticationMethodResult(null, "result")); Assert.Throws <ArgumentNullException> (() => new AuthenticationMethodResult("method", null)); Assert.Throws <ArgumentNullException> (() => new AuthenticationMethodProperty(null, "property", "value")); Assert.Throws <ArgumentNullException> (() => new AuthenticationMethodProperty("ptype", null, "value")); Assert.Throws <ArgumentNullException> (() => new AuthenticationMethodProperty("ptype", "Property", null)); Assert.Throws <ArgumentNullException> (() => AuthenticationResults.Parse(null)); Assert.Throws <ArgumentNullException> (() => AuthenticationResults.Parse(null, 0, 0)); Assert.Throws <ArgumentOutOfRangeException> (() => AuthenticationResults.Parse(buffer, -1, 0)); Assert.Throws <ArgumentOutOfRangeException> (() => AuthenticationResults.Parse(buffer, 0, -1)); Assert.Throws <ArgumentNullException> (() => AuthenticationResults.TryParse(null, out authres)); Assert.Throws <ArgumentNullException> (() => AuthenticationResults.TryParse(null, 0, 0, out authres)); Assert.Throws <ArgumentOutOfRangeException> (() => AuthenticationResults.TryParse(buffer, -1, 0, out authres)); Assert.Throws <ArgumentOutOfRangeException> (() => AuthenticationResults.TryParse(buffer, 0, -1, out authres)); }
static void AssertParseFailure(string input, int tokenIndex, int errorIndex) { var buffer = Encoding.ASCII.GetBytes(input); Assert.IsFalse(AuthenticationResults.TryParse(buffer, out AuthenticationResults authres)); try { AuthenticationResults.Parse(buffer); Assert.Fail("Expected parse error."); } catch (ParseException ex) { Assert.AreEqual(tokenIndex, ex.TokenIndex, "TokenIndex"); Assert.AreEqual(errorIndex, ex.ErrorIndex, "ErrorIndex"); } try { AuthenticationResults.Parse(buffer, 0, buffer.Length); Assert.Fail("Expected parse error."); } catch (ParseException ex) { Assert.AreEqual(tokenIndex, ex.TokenIndex, "TokenIndex"); Assert.AreEqual(errorIndex, ex.ErrorIndex, "ErrorIndex"); } }