//-----------------------------------------------------------------------
//
// Copyright (c) Outercurve Foundation. All rights reserved.
//
//-----------------------------------------------------------------------
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();
}
///
/// Verifies null value encoding
///
[Test]
public void NullValueEncoding() {
Assert.AreEqual("oob", this.encoding.EncodedNullValue);
}
///
/// Verifies decoding "oob" results in a null uri.
///
[Test]
public void DecodeOobToNullUri() {
Assert.IsNull(this.encoding.Decode("oob"));
}
///
/// Verifies that decoding an empty string generates an exception.
///
[Test, ExpectedException(typeof(UriFormatException))]
public void DecodeEmptyStringFails() {
this.encoding.Decode(string.Empty);
}
///
/// Verifies proper decoding/encoding of a Uri
///
[Test]
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);
}
///
/// Verifies failure to decode a relative Uri
///
[Test, ExpectedException(typeof(UriFormatException))]
public void RelativeUriDecodeFails() {
this.encoding.Decode("../a/b");
}
}
}