public void RespondTooManyValues() { var req = new AttributeRequest(); req.TypeUri = "http://someType"; req.Count = 1; req.Respond("value1", "value2"); }
public void RespondNull() { var req = new AttributeRequest(); req.TypeUri = "http://someType"; req.Count = 1; req.Respond(null); }
public void CtorFull() { var req = new AttributeRequest(WellKnownAttributes.Contact.Email, true, 5); Assert.AreEqual(WellKnownAttributes.Contact.Email, req.TypeUri); Assert.IsTrue(req.IsRequired); Assert.AreEqual(5, req.Count); }
public void CtorDefault() { AttributeRequest req = new AttributeRequest(); Assert.AreEqual(1, req.Count); Assert.IsNull(req.TypeUri); Assert.IsFalse(req.IsRequired); }
/// <summary> /// Used by the Relying Party to add a request for the values of a given attribute. /// </summary> public void AddAttribute(AttributeRequest attribute) { if (attribute == null) throw new ArgumentNullException("attribute"); if (containsAttribute(attribute.TypeUri)) throw new ArgumentException( string.Format(CultureInfo.CurrentCulture, Strings.AttributeAlreadyAdded, attribute.TypeUri), "attribute"); attributesRequested.Add(attribute); }
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.Count); Assert.AreEqual("value", resp.Values[0]); }
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.Count); Assert.AreEqual("value1", resp.Values[0]); Assert.AreEqual("value2", resp.Values[1]); }
/// <summary> /// Used by the Relying Party to add a request for the values of a given attribute. /// </summary> public void AddAttribute(AttributeRequest attribute) { if (attribute == null) { throw new ArgumentNullException("attribute"); } if (containsAttribute(attribute.TypeUri)) { throw new ArgumentException( string.Format(CultureInfo.CurrentCulture, Strings.AttributeAlreadyAdded, attribute.TypeUri), "attribute"); } attributesRequested.Add(attribute); }
bool IExtensionRequest.Deserialize(IDictionary <string, string> fields, DotNetOpenId.Provider.IRequest request, string typeUri) { if (fields == null) { return(false); } string mode; fields.TryGetValue("mode", out mode); if (mode != Mode) { return(false); } string updateUrl; fields.TryGetValue("update_url", out updateUrl); Uri updateUri; if (Uri.TryCreate(updateUrl, UriKind.Absolute, out updateUri)) { UpdateUrl = updateUri; } string requiredAliasString, optionalAliasString; fields.TryGetValue("if_available", out optionalAliasString); fields.TryGetValue("required", out requiredAliasString); var requiredAliases = parseAliasList(requiredAliasString); var optionalAliases = parseAliasList(optionalAliasString); // if an alias shows up in both lists, an exception will result implicitly. var allAliases = new List <string>(requiredAliases.Count + optionalAliases.Count); allAliases.AddRange(requiredAliases); allAliases.AddRange(optionalAliases); if (allAliases.Count == 0) { Logger.Error("Attribute Exchange extension did not provide any aliases in the if_available or required lists."); return(false); } AliasManager aliasManager = new AliasManager(); foreach (var alias in allAliases) { string attributeTypeUri; if (fields.TryGetValue("type." + alias, out attributeTypeUri)) { aliasManager.SetAlias(alias, attributeTypeUri); AttributeRequest att = new AttributeRequest { TypeUri = attributeTypeUri, IsRequired = requiredAliases.Contains(alias), }; string countString; if (fields.TryGetValue("count." + alias, out countString)) { if (countString == "unlimited") { att.Count = int.MaxValue; } else { int count; if (int.TryParse(countString, out count) && count > 0) { att.Count = count; } else { Logger.Error("count." + alias + " could not be parsed into a positive integer."); } } } else { att.Count = 1; } AddAttribute(att); } else { Logger.Error("Type URI definition of alias " + alias + " is missing."); } } return(true); }
public void SetCountNegative() { var req = new AttributeRequest(); req.Count = -1; }
public void SetCountZero() { var req = new AttributeRequest(); req.Count = 0; }
bool IExtensionRequest.Deserialize(IDictionary<string, string> fields, DotNetOpenId.Provider.IRequest request, string typeUri) { if (fields == null) return false; string mode; fields.TryGetValue("mode", out mode); if (mode != Mode) return false; string updateUrl; fields.TryGetValue("update_url", out updateUrl); Uri updateUri; if (Uri.TryCreate(updateUrl, UriKind.Absolute, out updateUri)) UpdateUrl = updateUri; string requiredAliasString, optionalAliasString; fields.TryGetValue("if_available", out optionalAliasString); fields.TryGetValue("required", out requiredAliasString); var requiredAliases = parseAliasList(requiredAliasString); var optionalAliases = parseAliasList(optionalAliasString); // if an alias shows up in both lists, an exception will result implicitly. var allAliases = new List<string>(requiredAliases.Count + optionalAliases.Count); allAliases.AddRange(requiredAliases); allAliases.AddRange(optionalAliases); if (allAliases.Count == 0) { Logger.Error("Attribute Exchange extension did not provide any aliases in the if_available or required lists."); return false; } AliasManager aliasManager = new AliasManager(); foreach (var alias in allAliases) { string attributeTypeUri; if (fields.TryGetValue("type." + alias, out attributeTypeUri)) { aliasManager.SetAlias(alias, attributeTypeUri); AttributeRequest att = new AttributeRequest { TypeUri = attributeTypeUri, IsRequired = requiredAliases.Contains(alias), }; string countString; if (fields.TryGetValue("count." + alias, out countString)) { if (countString == "unlimited") att.Count = int.MaxValue; else { int count; if (int.TryParse(countString, out count) && count > 0) { att.Count = count; } else { Logger.Error("count." + alias + " could not be parsed into a positive integer."); } } } else { att.Count = 1; } AddAttribute(att); } else { Logger.Error("Type URI definition of alias " + alias + " is missing."); } } return true; }