summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.Test/OAuth/ChannelElements/UriOrOobEncodingTests.cs
blob: 715669ab10365a28358f2ba7f6bf731597622cc2 (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
//-----------------------------------------------------------------------
// <copyright file="UriOrOobEncodingTests.cs" company="Andrew Arnott">
//     Copyright (c) Andrew Arnott. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace DotNetOpenAuth.Test.OAuth.ChannelElements {
	using System;
	using System.Collections.Generic;
	using System.Linq;
	using System.Text;
	using DotNetOpenAuth.OAuth.ChannelElements;
	using NUnit.Framework;

	[TestFixture]
	public class UriOrOobEncodingTests : TestBase {
		private UriOrOobEncoding encoding;

		[SetUp]
		public void Setup() {
			this.encoding = new UriOrOobEncoding();
		}

		/// <summary>
		/// Verifies null value encoding
		/// </summary>
		[TestCase]
		public void NullValueEncoding() {
			Assert.AreEqual("oob", this.encoding.EncodedNullValue);
		}

		/// <summary>
		/// Verifies decoding "oob" results in a null uri.
		/// </summary>
		[TestCase]
		public void DecodeOobToNullUri() {
			Assert.IsNull(this.encoding.Decode("oob"));
		}

		/// <summary>
		/// Verifies that decoding an empty string generates an exception.
		/// </summary>
		[TestCase, ExpectedException(typeof(UriFormatException))]
		public void DecodeEmptyStringFails() {
			this.encoding.Decode(string.Empty);
		}

		/// <summary>
		/// Verifies proper decoding/encoding of a Uri
		/// </summary>
		[TestCase]
		public void UriEncodeDecode() {
			Uri original = new Uri("http://somehost/p?q=a#frag");
			string encodedValue = this.encoding.Encode(original);
			Assert.AreEqual(original.AbsoluteUri, encodedValue);
			Uri decoded = (Uri)this.encoding.Decode(encodedValue);
			Assert.AreEqual(original, decoded);
		}

		/// <summary>
		/// Verifies failure to decode a relative Uri
		/// </summary>
		[TestCase, ExpectedException(typeof(UriFormatException))]
		public void RelativeUriDecodeFails() {
			this.encoding.Decode("../a/b");
		}
	}
}