blob: 01e2fdca19ca920eb342b410cc9339e194c77f68 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
//-----------------------------------------------------------------------
// <copyright file="IdentifierTests.cs" company="Andrew Arnott">
// Copyright (c) Andrew Arnott. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
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<UriIdentifier>(Identifier.Parse(this.uri));
Assert.IsInstanceOf<XriIdentifier>(Identifier.Parse(this.xri));
}
/// <summary>
/// Tests conformance with 2.0 spec section 7.2#2
/// </summary>
[TestCase]
public void ParseEndUserSuppliedXriIdentifer() {
List<char> symbols = new List<char>(XriIdentifier.GlobalContextSymbols);
symbols.Add('(');
List<string> prefixes = new List<string>();
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<XriIdentifier>(id);
}
}
/// <summary>
/// Verifies conformance with 2.0 spec section 7.2#3
/// </summary>
[TestCase]
public void ParseEndUserSuppliedUriIdentifier() {
// verify a fully-qualified Uri
var id = Identifier.Parse(this.uri);
Assert.IsInstanceOf<UriIdentifier>(id);
Assert.AreEqual(this.uri, ((UriIdentifier)id).Uri.AbsoluteUri);
// verify an HTTPS Uri
id = Identifier.Parse(this.uriHttps);
Assert.IsInstanceOf<UriIdentifier>(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<UriIdentifier>(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);
}
}
}
|