diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/DotNetOpenAuth.Test/OpenId/IdentifierTests.cs | 16 | ||||
-rw-r--r-- | src/DotNetOpenAuth/OpenId/Identifier.cs | 6 |
2 files changed, 21 insertions, 1 deletions
diff --git a/src/DotNetOpenAuth.Test/OpenId/IdentifierTests.cs b/src/DotNetOpenAuth.Test/OpenId/IdentifierTests.cs index 2b012dd..53df6c8 100644 --- a/src/DotNetOpenAuth.Test/OpenId/IdentifierTests.cs +++ b/src/DotNetOpenAuth.Test/OpenId/IdentifierTests.cs @@ -19,6 +19,22 @@ namespace DotNetOpenAuth.Test.OpenId { private string xri = "=arnott*andrew"; [TestMethod] + public void TryParseNoThrow() { + Identifier id; + Assert.IsFalse(Identifier.TryParse(null, out id)); + Assert.IsFalse(Identifier.TryParse("", out id)); + } + + [TestMethod] + public void TryParse() { + Identifier id; + Assert.IsTrue(Identifier.TryParse("http://host/path", out id)); + Assert.AreEqual("http://host/path", id.ToString()); + Assert.IsTrue(Identifier.TryParse("=arnott", out id)); + Assert.AreEqual("=arnott", id.ToString()); + } + + [TestMethod] public void Parse() { Assert.IsInstanceOfType(Identifier.Parse(this.uri), typeof(UriIdentifier)); Assert.IsInstanceOfType(Identifier.Parse(this.xri), typeof(XriIdentifier)); diff --git a/src/DotNetOpenAuth/OpenId/Identifier.cs b/src/DotNetOpenAuth/OpenId/Identifier.cs index 53f5094..1b9570e 100644 --- a/src/DotNetOpenAuth/OpenId/Identifier.cs +++ b/src/DotNetOpenAuth/OpenId/Identifier.cs @@ -114,7 +114,11 @@ namespace DotNetOpenAuth.OpenId { /// True if the operation was successful. False if the string was not a valid OpenId Identifier. /// </returns> public static bool TryParse(string value, out Identifier result) { - Contract.Requires(!string.IsNullOrEmpty(value)); + if (string.IsNullOrEmpty(value)) { + result = null; + return false; + } + if (IsValid(value)) { result = Parse(value); return true; |