diff options
Diffstat (limited to 'src/DotNetOpenId.Test/Extensions')
4 files changed, 159 insertions, 4 deletions
diff --git a/src/DotNetOpenId.Test/Extensions/AttributeExchangeFetchRequestTests.cs b/src/DotNetOpenId.Test/Extensions/AttributeExchangeFetchRequestTests.cs new file mode 100644 index 0000000..3095b02 --- /dev/null +++ b/src/DotNetOpenId.Test/Extensions/AttributeExchangeFetchRequestTests.cs @@ -0,0 +1,73 @@ +using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using NUnit.Framework;
+using DotNetOpenId.Extensions;
+
+namespace DotNetOpenId.Test.Extensions {
+ [TestFixture]
+ public class AttributeExchangeFetchRequestTests {
+ [Test, ExpectedException(typeof(ArgumentNullException))]
+ public void AddAttributeRequestNull() {
+ new AttributeExchangeFetchRequest().AddAttribute(null);
+ }
+
+ [Test]
+ public void AddAttributeRequest() {
+ var req = new AttributeExchangeFetchRequest();
+ req.AddAttribute(new AttributeRequest() { TypeUri = "http://someUri" });
+ }
+
+ [Test]
+ public void AddAttributeRequestStrangeUri() {
+ var req = new AttributeExchangeFetchRequest();
+ req.AddAttribute(new AttributeRequest() { TypeUri = "=someUri*who*knows*but*this*is*legal" });
+ }
+
+ [Test, ExpectedException(typeof(ArgumentException))]
+ public void AddAttributeRequestAgain() {
+ var req = new AttributeExchangeFetchRequest();
+ req.AddAttribute(new AttributeRequest() { TypeUri = "http://UriTwice" });
+ req.AddAttribute(new AttributeRequest() { TypeUri = "http://UriTwice" });
+ }
+
+ [Test]
+ public void RespondSimpleValue() {
+ var req = new AttributeRequest();
+ req.TypeUri = "http://someType";
+ var resp = req.Respond("value");
+ Assert.AreEqual(req.TypeUri, resp.TypeUri);
+ Assert.AreEqual(1, resp.Values.Length);
+ Assert.AreEqual("value", resp.Values[0]);
+ }
+
+ [Test]
+ public void RespondTwoValues() {
+ var req = new AttributeRequest();
+ req.TypeUri = "http://someType";
+ req.Count = 2;
+ var resp = req.Respond("value1", "value2");
+ Assert.AreEqual(req.TypeUri, resp.TypeUri);
+ Assert.AreEqual(2, resp.Values.Length);
+ Assert.AreEqual("value1", resp.Values[0]);
+ Assert.AreEqual("value2", resp.Values[1]);
+ }
+
+ [Test, ExpectedException(typeof(ArgumentException))]
+ public void RespondTooManyValues() {
+ var req = new AttributeRequest();
+ req.TypeUri = "http://someType";
+ req.Count = 1;
+ req.Respond("value1", "value2");
+ }
+
+ [Test, ExpectedException(typeof(ArgumentNullException))]
+ public void RespondNull() {
+ var req = new AttributeRequest();
+ req.TypeUri = "http://someType";
+ req.Count = 1;
+ req.Respond(null);
+ }
+ }
+}
diff --git a/src/DotNetOpenId.Test/Extensions/AttributeExchangeFetchResponseTests.cs b/src/DotNetOpenId.Test/Extensions/AttributeExchangeFetchResponseTests.cs new file mode 100644 index 0000000..14533ce --- /dev/null +++ b/src/DotNetOpenId.Test/Extensions/AttributeExchangeFetchResponseTests.cs @@ -0,0 +1,52 @@ +using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using NUnit.Framework;
+using DotNetOpenId.Extensions;
+
+namespace DotNetOpenId.Test.Extensions {
+ [TestFixture]
+ public class AttributeExchangeFetchResponseTests {
+ [Test]
+ public void AddAttribute() {
+ var response = new AttributeExchangeFetchResponse();
+ response.AddAttribute(new AttributeResponse {
+ TypeUri = "http://someattribute",
+ Values = new[] { "Value1" },
+ });
+ }
+
+ [Test]
+ public void AddTwoAttributes() {
+ var response = new AttributeExchangeFetchResponse();
+ response.AddAttribute(new AttributeResponse {
+ TypeUri = "http://someattribute",
+ Values = new[] { "Value1" },
+ });
+ response.AddAttribute(new AttributeResponse {
+ TypeUri = "http://someOtherAttribute",
+ Values = new[] { "Value2" },
+ });
+ }
+
+ [Test, ExpectedException(typeof(ArgumentException))]
+ public void AddAttributeTwice() {
+ var response = new AttributeExchangeFetchResponse();
+ response.AddAttribute(new AttributeResponse {
+ TypeUri = "http://someattribute",
+ Values = new[] { "Value1" },
+ });
+ response.AddAttribute(new AttributeResponse {
+ TypeUri = "http://someattribute",
+ Values = new[] { "Value1" },
+ });
+ }
+
+ [Test, ExpectedException(typeof(ArgumentNullException))]
+ public void AddAttributeNull() {
+ var response = new AttributeExchangeFetchResponse();
+ response.AddAttribute(null);
+ }
+ }
+}
diff --git a/src/DotNetOpenId.Test/Extensions/AttributeExchangeTests.cs b/src/DotNetOpenId.Test/Extensions/AttributeExchangeTests.cs index c216fd1..ab28784 100644 --- a/src/DotNetOpenId.Test/Extensions/AttributeExchangeTests.cs +++ b/src/DotNetOpenId.Test/Extensions/AttributeExchangeTests.cs @@ -9,6 +9,9 @@ using DotNetOpenId.Extensions; namespace DotNetOpenId.Test.Extensions {
[TestFixture]
public class AttributeExchangeTests : ExtensionTestBase {
+ const string nicknameTypeUri = "http://axschema.org/namePerson/friendly";
+ const string emailTypeUri = "http://axschema.org/contact/email";
+
[Test]
public void None() {
var fetchResponse = ParameterizedTest<AttributeExchangeFetchResponse>(
@@ -22,9 +25,36 @@ namespace DotNetOpenId.Test.Extensions { [Test]
public void Fetch() {
var request = new AttributeExchangeFetchRequest();
+ request.AddAttribute(new AttributeRequest { TypeUri = nicknameTypeUri });
+ request.AddAttribute(new AttributeRequest { TypeUri = emailTypeUri, Count = int.MaxValue });
+ var response = ParameterizedTest<AttributeExchangeFetchResponse>(
+ TestSupport.GetIdentityUrl(TestSupport.Scenarios.ExtensionFullCooperation, Version), request);
+ Assert.IsNotNull(response);
+ var att = response.GetAttribute(nicknameTypeUri);
+ Assert.IsNotNull(att);
+ Assert.AreEqual(nicknameTypeUri, att.TypeUri);
+ Assert.AreEqual(1, att.Values.Length);
+ Assert.AreEqual("Andrew", att.Values[0]);
+ att = response.GetAttribute(emailTypeUri);
+ Assert.IsNotNull(att);
+ Assert.AreEqual(emailTypeUri, att.TypeUri);
+ Assert.AreEqual(2, att.Values.Length);
+ Assert.AreEqual("a@a.com", att.Values[0]);
+ Assert.AreEqual("b@b.com", att.Values[1]);
+ }
+
+ [Test]
+ public void FetchLimitEmails() {
+ var request = new AttributeExchangeFetchRequest();
+ request.AddAttribute(new AttributeRequest { TypeUri = emailTypeUri, Count = 1 });
var response = ParameterizedTest<AttributeExchangeFetchResponse>(
TestSupport.GetIdentityUrl(TestSupport.Scenarios.ExtensionFullCooperation, Version), request);
Assert.IsNotNull(response);
+ var att = response.GetAttribute(emailTypeUri);
+ Assert.IsNotNull(att);
+ Assert.AreEqual(emailTypeUri, att.TypeUri);
+ Assert.AreEqual(1, att.Values.Length);
+ Assert.AreEqual("a@a.com", att.Values[0]);
}
[Test]
diff --git a/src/DotNetOpenId.Test/Extensions/ExtensionTestBase.cs b/src/DotNetOpenId.Test/Extensions/ExtensionTestBase.cs index adb93bb..3f14253 100644 --- a/src/DotNetOpenId.Test/Extensions/ExtensionTestBase.cs +++ b/src/DotNetOpenId.Test/Extensions/ExtensionTestBase.cs @@ -11,12 +11,12 @@ using System.Diagnostics; namespace DotNetOpenId.Test.Extensions {
public class ExtensionTestBase {
- protected IRelyingPartyApplicationStore Store;
+ protected IRelyingPartyApplicationStore AppStore;
protected const ProtocolVersion Version = ProtocolVersion.V20;
[SetUp]
public virtual void Setup() {
- Store = new ApplicationMemoryStore();
+ AppStore = new ApplicationMemoryStore();
}
protected T ParameterizedTest<T>(Identifier identityUrl, IExtensionRequest extensionArgs)
@@ -24,7 +24,7 @@ namespace DotNetOpenId.Test.Extensions { Debug.Assert(identityUrl != null);
var returnTo = TestSupport.GetFullUrl(TestSupport.ConsumerPage);
var realm = new Realm(TestSupport.GetFullUrl(TestSupport.ConsumerPage).AbsoluteUri);
- var consumer = new OpenIdRelyingParty(Store, null);
+ var consumer = new OpenIdRelyingParty(AppStore, null);
var request = consumer.CreateRequest(identityUrl, realm, returnTo);
if (extensionArgs != null)
extensionArgs.AddToRequest(request);
@@ -46,7 +46,7 @@ namespace DotNetOpenId.Test.Extensions { }
throw;
}
- consumer = new OpenIdRelyingParty(Store, redirectUrl);
+ consumer = new OpenIdRelyingParty(AppStore, redirectUrl);
Assert.AreEqual(AuthenticationStatus.Authenticated, consumer.Response.Status);
Assert.AreEqual(identityUrl, consumer.Response.ClaimedIdentifier);
T r = new T();
|