예제 #1
0
 public void AddAttributeByValue()
 {
     var req = new StoreRequest();
     AttributeValues value = new AttributeValues();
     req.Attributes.Add(value);
     Assert.AreSame(value, req.Attributes.Single());
 }
예제 #2
0
        /// <summary>
        /// Deserializes attribute values from an incoming set of message data.
        /// </summary>
        /// <param name="fields">The data coming in with the message.</param>
        /// <returns>The attribute values found in the message.</returns>
        internal static IEnumerable <AttributeValues> DeserializeAttributes(IDictionary <string, string> fields)
        {
            AliasManager aliasManager = ParseAliases(fields);

            foreach (string alias in aliasManager.Aliases)
            {
                AttributeValues att       = new AttributeValues(aliasManager.ResolveAlias(alias));
                int             count     = 1;
                bool            countSent = false;
                string          countString;
                if (fields.TryGetValue("count." + alias, out countString))
                {
                    if (!int.TryParse(countString, out count) || count < 0)
                    {
                        Logger.OpenId.ErrorFormat("Failed to parse count.{0} value to a non-negative integer.", alias);
                        continue;
                    }
                    countSent = true;
                }
                if (countSent)
                {
                    for (int i = 1; i <= count; i++)
                    {
                        string value;
                        if (fields.TryGetValue(string.Format(CultureInfo.InvariantCulture, "value.{0}.{1}", alias, i), out value))
                        {
                            att.Values.Add(value);
                        }
                        else
                        {
                            Logger.OpenId.ErrorFormat("Missing value for attribute '{0}'.", att.TypeUri);
                            continue;
                        }
                    }
                }
                else
                {
                    string value;
                    if (fields.TryGetValue("value." + alias, out value))
                    {
                        att.Values.Add(value);
                    }
                    else
                    {
                        Logger.OpenId.ErrorFormat("Missing value for attribute '{0}'.", att.TypeUri);
                        continue;
                    }
                }
                yield return(att);
            }
        }
		public void Ctor() {
			var att = new AttributeValues();
			Assert.IsNull(att.TypeUri);
			Assert.IsNotNull(att.Values);
			Assert.AreEqual(0, att.Values.Count);

			att = new AttributeValues("http://att");
			Assert.AreEqual("http://att", att.TypeUri);
			Assert.IsNotNull(att.Values);
			Assert.AreEqual(0, att.Values.Count);

			att = new AttributeValues("http://att", "value1", "value2");
			Assert.AreEqual("http://att", att.TypeUri);
			Assert.IsNotNull(att.Values);
			Assert.AreEqual(2, att.Values.Count);
			Assert.AreEqual("value1", att.Values[0]);
			Assert.AreEqual("value2", att.Values[1]);
		}
		public async Task Store() {
			var request = new StoreRequest();
			var newAttribute = new AttributeValues(
				IncrementingAttribute,
				"val" + (this.incrementingAttributeValue++).ToString(),
				"val" + (this.incrementingAttributeValue++).ToString());
			request.Attributes.Add(newAttribute);

			var successResponse = new StoreResponse();
			successResponse.Succeeded = true;

			await this.RoundtripAsync(Protocol.Default, new[] { request }, new[] { successResponse });

			var failureResponse = new StoreResponse();
			failureResponse.Succeeded = false;
			failureResponse.FailureReason = "Some error";

			await this.RoundtripAsync(Protocol.Default, new[] { request }, new[] { failureResponse });
		}
		public void EqualityTests() {
			var att1 = new AttributeValues();
			var att2 = new AttributeValues();
			Assert.AreEqual(att1, att2);

			att1.TypeUri = "http://att1";
			Assert.AreNotEqual(att1, att2);
			att2.TypeUri = "http://att1";
			Assert.AreEqual(att1, att2);

			att1.Values.Add("value1");
			Assert.AreNotEqual(att1, att2);
			att2.Values.Add("value1");
			Assert.AreEqual(att1, att2);

			// Values that are out of order should not be considered equal.
			att1.Values.Add("value2");
			att2.Values.Insert(0, "value2");
			Assert.AreNotEqual(att1, att2);
		}
        public void Store()
        {
            var request = new StoreRequest();
            var newAttribute = new AttributeValues(
                IncrementingAttribute,
                "val" + (incrementingAttributeValue++).ToString(),
                "val" + (incrementingAttributeValue++).ToString());
            request.Attributes.Add(newAttribute);

            var successResponse = new StoreResponse();
            successResponse.Succeeded = true;

            ExtensionTestUtilities.Roundtrip(Protocol.Default, new[] { request }, new[] { successResponse });

            var failureResponse = new StoreResponse();
            failureResponse.Succeeded = false;
            failureResponse.FailureReason = "Some error";

            ExtensionTestUtilities.Roundtrip(Protocol.Default, new[] { request }, new[] { failureResponse });
        }
예제 #7
0
        /// <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>
        /// <returns>
        /// true if the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>; otherwise, false.
        /// </returns>
        /// <exception cref="T:System.NullReferenceException">
        /// The <paramref name="obj"/> parameter is null.
        /// </exception>
        public override bool Equals(object obj)
        {
            AttributeValues other = obj as AttributeValues;

            if (other == null)
            {
                return(false);
            }

            if (this.TypeUri != other.TypeUri)
            {
                return(false);
            }

            if (!MessagingUtilities.AreEquivalent <string>(this.Values, other.Values))
            {
                return(false);
            }

            return(true);
        }
예제 #8
0
 /// <summary>
 /// Deserializes attribute values from an incoming set of message data.
 /// </summary>
 /// <param name="fields">The data coming in with the message.</param>
 /// <returns>The attribute values found in the message.</returns>
 internal static IEnumerable<AttributeValues> DeserializeAttributes(IDictionary<string, string> fields)
 {
     AliasManager aliasManager = ParseAliases(fields);
     foreach (string alias in aliasManager.Aliases) {
         AttributeValues att = new AttributeValues(aliasManager.ResolveAlias(alias));
         int count = 1;
         bool countSent = false;
         string countString;
         if (fields.TryGetValue("count." + alias, out countString)) {
             if (!int.TryParse(countString, out count) || count <= 0) {
                 Logger.OpenId.ErrorFormat("Failed to parse count.{0} value to a positive integer.", alias);
                 continue;
             }
             countSent = true;
         }
         if (countSent) {
             for (int i = 1; i <= count; i++) {
                 string value;
                 if (fields.TryGetValue(string.Format(CultureInfo.InvariantCulture, "value.{0}.{1}", alias, i), out value)) {
                     att.Values.Add(value);
                 } else {
                     Logger.OpenId.ErrorFormat("Missing value for attribute '{0}'.", att.TypeUri);
                     continue;
                 }
             }
         } else {
             string value;
             if (fields.TryGetValue("value." + alias, out value)) {
                 att.Values.Add(value);
             } else {
                 Logger.OpenId.ErrorFormat("Missing value for attribute '{0}'.", att.TypeUri);
                 continue;
             }
         }
         yield return att;
     }
 }
예제 #9
0
 /// <summary>
 /// Adds a given attribute with one or more values to the request for storage.
 /// Applicable to Relying Parties only.
 /// </summary>
 /// <param name="attribute">The attribute values.</param>
 public void AddAttribute(AttributeValues attribute)
 {
     ErrorUtilities.VerifyArgumentNotNull(attribute, "attribute");
     ErrorUtilities.VerifyArgumentNamed(!this.ContainsAttribute(attribute.TypeUri), "attribute", OpenIdStrings.AttributeAlreadyAdded, attribute.TypeUri);
     this.attributesProvided.Add(attribute);
 }