//----------------------------------------------------------------------- // // Copyright (c) Andrew Arnott. All rights reserved. // //----------------------------------------------------------------------- namespace DotNetOpenAuth.Test.OpenId { using System; using System.Collections.Generic; using System.Linq; using DotNetOpenAuth.OpenId; using NUnit.Framework; [TestFixture] public class IdentifierTests { private string uri = "http://www.yahoo.com/"; private string uriNoScheme = "www.yahoo.com"; private string uriHttps = "https://www.yahoo.com/"; private string xri = "=arnott*andrew"; [TestCase] public void TryParseNoThrow() { Identifier id; Assert.IsFalse(Identifier.TryParse(null, out id)); Assert.IsFalse(Identifier.TryParse(string.Empty, out id)); } [TestCase] 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()); } [TestCase] public void Parse() { Assert.IsInstanceOf(Identifier.Parse(this.uri)); Assert.IsInstanceOf(Identifier.Parse(this.xri)); } /// /// Tests conformance with 2.0 spec section 7.2#2 /// [TestCase] public void ParseEndUserSuppliedXriIdentifer() { List symbols = new List(XriIdentifier.GlobalContextSymbols); symbols.Add('('); List prefixes = new List(); prefixes.AddRange(symbols.Select(s => s.ToString())); prefixes.AddRange(symbols.Select(s => "xri://" + s.ToString())); foreach (string prefix in prefixes) { var id = Identifier.Parse(prefix + "andrew"); Assert.IsInstanceOf(id); } } /// /// Verifies conformance with 2.0 spec section 7.2#3 /// [TestCase] public void ParseEndUserSuppliedUriIdentifier() { // verify a fully-qualified Uri var id = Identifier.Parse(this.uri); Assert.IsInstanceOf(id); Assert.AreEqual(this.uri, ((UriIdentifier)id).Uri.AbsoluteUri); // verify an HTTPS Uri id = Identifier.Parse(this.uriHttps); Assert.IsInstanceOf(id); Assert.AreEqual(this.uriHttps, ((UriIdentifier)id).Uri.AbsoluteUri); // verify that if the scheme is missing it is added automatically id = Identifier.Parse(this.uriNoScheme); Assert.IsInstanceOf(id); Assert.AreEqual(this.uri, ((UriIdentifier)id).Uri.AbsoluteUri); } [TestCase, ExpectedException(typeof(ArgumentException))] public void ParseNull() { Identifier.Parse(null); } [TestCase, ExpectedException(typeof(ArgumentException))] public void ParseEmpty() { Identifier.Parse(string.Empty); } } }