summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.Test
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2009-06-06 08:39:47 -0700
committerAndrew Arnott <andrewarnott@gmail.com>2009-06-06 08:39:47 -0700
commitddf0b1632e9ccceca514bfee6f65c5786b078dcd (patch)
treefe6bad5c1b34d29c849b13d5b2ef3e30aec7b1a6 /src/DotNetOpenAuth.Test
parent63daff25f5ea47e6bd7826c21fe2ba9905185e8c (diff)
downloadDotNetOpenAuth-ddf0b1632e9ccceca514bfee6f65c5786b078dcd.zip
DotNetOpenAuth-ddf0b1632e9ccceca514bfee6f65c5786b078dcd.tar.gz
DotNetOpenAuth-ddf0b1632e9ccceca514bfee6f65c5786b078dcd.tar.bz2
Added tests for the UriOrOobEncoding class.
Diffstat (limited to 'src/DotNetOpenAuth.Test')
-rw-r--r--src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj1
-rw-r--r--src/DotNetOpenAuth.Test/OAuth/ChannelElements/UriOrOobEncodingTests.cs68
2 files changed, 69 insertions, 0 deletions
diff --git a/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj b/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj
index 591c442..bfc6253 100644
--- a/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj
+++ b/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj
@@ -167,6 +167,7 @@
<Compile Include="OAuth\ChannelElements\OAuthChannelTests.cs" />
<Compile Include="OAuth\ChannelElements\PlaintextSigningBindingElementTest.cs" />
<Compile Include="OAuth\ChannelElements\SigningBindingElementBaseTests.cs" />
+ <Compile Include="OAuth\ChannelElements\UriOrOobEncodingTests.cs" />
<Compile Include="OAuth\ConsumerDescription.cs" />
<Compile Include="OAuth\ProtocolTests.cs" />
<Compile Include="OAuth\ServiceProviderDescriptionTests.cs" />
diff --git a/src/DotNetOpenAuth.Test/OAuth/ChannelElements/UriOrOobEncodingTests.cs b/src/DotNetOpenAuth.Test/OAuth/ChannelElements/UriOrOobEncodingTests.cs
new file mode 100644
index 0000000..6616cc3
--- /dev/null
+++ b/src/DotNetOpenAuth.Test/OAuth/ChannelElements/UriOrOobEncodingTests.cs
@@ -0,0 +1,68 @@
+//-----------------------------------------------------------------------
+// <copyright file="UriOrOobEncoderTests.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 Microsoft.VisualStudio.TestTools.UnitTesting;
+ using DotNetOpenAuth.OAuth.ChannelElements;
+
+ [TestClass]
+ public class UriOrOobEncodingTests : TestBase {
+ private UriOrOobEncoding encoding;
+
+ [TestInitialize]
+ public void Setup() {
+ this.encoding = new UriOrOobEncoding();
+ }
+
+ /// <summary>
+ /// Verifies encoding null URIs results in the value "oob".
+ /// </summary>
+ [TestMethod]
+ public void EncodeNullValueToOob() {
+ Assert.AreEqual("oob", this.encoding.Encode(null));
+ }
+
+ /// <summary>
+ /// Verifies decoding "oob" results in a null uri.
+ /// </summary>
+ [TestMethod]
+ public void DecodeOobToNullUri() {
+ Assert.IsNull(this.encoding.Decode("oob"));
+ }
+
+ /// <summary>
+ /// Verifies that decoding an empty string generates an exception.
+ /// </summary>
+ [TestMethod, ExpectedException(typeof(UriFormatException))]
+ public void DecodeEmptyStringFails() {
+ this.encoding.Decode(string.Empty);
+ }
+
+ /// <summary>
+ /// Verifies proper decoding/encoding of a Uri
+ /// </summary>
+ [TestMethod]
+ 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>
+ [TestMethod, ExpectedException(typeof(UriFormatException))]
+ public void RelativeUriDecodeFails() {
+ this.encoding.Decode("../a/b");
+ }
+ }
+}