diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2009-05-20 20:39:47 -0700 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2009-05-20 20:39:47 -0700 |
commit | 1ab57fa25cf59319e83e473d36bc1a2783a31279 (patch) | |
tree | 4fa215b41d3c9d9465d408556e9c5e7c14f13684 /src | |
parent | 79d8b894198fad9c96a29e18bd5b60e3f3048fae (diff) | |
download | DotNetOpenAuth-1ab57fa25cf59319e83e473d36bc1a2783a31279.zip DotNetOpenAuth-1ab57fa25cf59319e83e473d36bc1a2783a31279.tar.gz DotNetOpenAuth-1ab57fa25cf59319e83e473d36bc1a2783a31279.tar.bz2 |
Added FetchResponse.GetAttributeValue(string) method.
Resolves Trac issue #67.
Diffstat (limited to 'src')
-rw-r--r-- | src/DotNetOpenAuth.Test/OpenId/Extensions/AttributeExchange/FetchResponseTests.cs | 16 | ||||
-rw-r--r-- | src/DotNetOpenAuth/OpenId/Extensions/AttributeExchange/FetchResponse.cs | 22 |
2 files changed, 38 insertions, 0 deletions
diff --git a/src/DotNetOpenAuth.Test/OpenId/Extensions/AttributeExchange/FetchResponseTests.cs b/src/DotNetOpenAuth.Test/OpenId/Extensions/AttributeExchange/FetchResponseTests.cs index d467186..0221ff4 100644 --- a/src/DotNetOpenAuth.Test/OpenId/Extensions/AttributeExchange/FetchResponseTests.cs +++ b/src/DotNetOpenAuth.Test/OpenId/Extensions/AttributeExchange/FetchResponseTests.cs @@ -40,6 +40,22 @@ namespace DotNetOpenId.Test.OpenId.Extensions { } [TestMethod] + public void GetAttributeValue() { + var response = new FetchResponse(); + + // Verify that null is returned if the attribute is absent. + Assert.IsNull(response.GetAttributeValue("http://someattribute")); + + // Now add an attribute with no values. + response.Attributes.Add(new AttributeValues("http://someattribute2")); + Assert.IsNull(response.GetAttributeValue("http://someattribute2")); + + // Now add an attribute with many values. + response.Attributes.Add(new AttributeValues("http://someattribute3", "a", "b", "c")); + Assert.AreEqual("a", response.GetAttributeValue("http://someattribute3")); + } + + [TestMethod] public void EqualityTests() { var response1 = new FetchResponse(); var response2 = new FetchResponse(); diff --git a/src/DotNetOpenAuth/OpenId/Extensions/AttributeExchange/FetchResponse.cs b/src/DotNetOpenAuth/OpenId/Extensions/AttributeExchange/FetchResponse.cs index 9413e2f..36c4d7c 100644 --- a/src/DotNetOpenAuth/OpenId/Extensions/AttributeExchange/FetchResponse.cs +++ b/src/DotNetOpenAuth/OpenId/Extensions/AttributeExchange/FetchResponse.cs @@ -81,6 +81,28 @@ namespace DotNetOpenAuth.OpenId.Extensions.AttributeExchange { } /// <summary> + /// Gets the first attribute value provided for a given attribute Type URI. + /// </summary> + /// <param name="typeUri"> + /// The type URI of the attribute. + /// Usually a constant from <see cref="WellKnownAttributes"/>.</param> + /// <returns> + /// The first value provided for the attribute, or <c>null</c> if the attribute is missing or no values were provided. + /// </returns> + /// <remarks> + /// This is meant as a helper method for the common case of just wanting one attribute value. + /// For greater flexibility or to retrieve more than just the first value for an attribute, + /// use the <see cref="Attributes"/> collection directly. + /// </remarks> + public string GetAttributeValue(string typeUri) { + if (this.Attributes.Contains(typeUri)) { + return this.Attributes[typeUri].Values.FirstOrDefault(); + } else { + return null; + }; + } + + /// <summary> /// Determines whether the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>. /// </summary> /// <param name="obj">The <see cref="T:System.Object"/> to compare with the current <see cref="T:System.Object"/>.</param> |