public void Contains_WithAttribute_AttributeSpecified_Found() { var exemption = Tuple.Create("foo", new AttributeCollection(Tuple.Create("Assembly", "A"))); var exemptions = new ExemptionCollection(exemption); Assert.True(exemptions.Contains("foo", new AttributeCollection(Tuple.Create("Assembly", "A")))); }
public void Contains_WithAttributes_WrongAttributesSpecified_NotFound(string name1, string value1, string name2, string value2) { var exemption = Tuple.Create("foo", new AttributeCollection(Tuple.Create("Assembly", "A"), Tuple.Create("Parameter", "B"))); var exemptions = new ExemptionCollection(exemption); Assert.False(exemptions.Contains("foo", new AttributeCollection(Tuple.Create(name1, value1), Tuple.Create(name2, value2)))); }
public void Contains_WithAttribute_WrongAttributeSpecified_NotFound(string name, string value) { var exemption = Tuple.Create("foo", new AttributeCollection(Tuple.Create("Assembly", "A"))); var exemptions = new ExemptionCollection(exemption); Assert.False(exemptions.Contains("foo", new AttributeCollection(Tuple.Create(name, value)))); }
public void Contains_WithAttributes_LessAttributesSpecified_NotFound() { var exemption = Tuple.Create("foo", new AttributeCollection(Tuple.Create("Assembly", "A"), Tuple.Create("Parameter", "B"))); var exemptions = new ExemptionCollection(exemption); Assert.False(exemptions.Contains("foo", new AttributeCollection(Tuple.Create("Assembly", "A")))); }
public void Contains_WithAttributes_MoreAttributesSpecified_Found() { var exemption = Tuple.Create("foo", new AttributeCollection(Tuple.Create("Assembly", "A"), Tuple.Create("Parameter", "B"))); var exemptions = new ExemptionCollection(exemption); Assert.True(exemptions.Contains("foo", new AttributeCollection(Tuple.Create("Assembly", "A"), Tuple.Create("Parameter", "B"), Tuple.Create("Namespace", "C")))); }
public void Contains_WithAttributes_AllAttributesSpecified_Found() { var exemption = Tuple.Create("foo", new AttributeCollection(Tuple.Create("Assembly", "A"), Tuple.Create("Parameter", "B"))); var exemptions = new ExemptionCollection(exemption); Assert.True(exemptions.Contains("foo", new AttributeCollection(Tuple.Create("Assembly", "A"), Tuple.Create("Parameter", "B")))); Assert.True(exemptions.Contains("foo", new AttributeCollection(Tuple.Create("Parameter", "B"), Tuple.Create("Assembly", "A")))); // order doesn't matter }
public void Add_SingleValue_OneExemption() { var exemptions = new ExemptionCollection(); exemptions.Add("foo"); Assert.Single(exemptions); }
public void Add_DuplicateValues_MixedCase_OneExemption() { var exemptions = new ExemptionCollection(); exemptions.Add("foo"); exemptions.Add("FOO"); Assert.Single(exemptions); }
public void Add_DistinctValues_MultipleExemptions() { const int ExpectedCount = 2; var exemptions = new ExemptionCollection(); exemptions.Add("foo"); exemptions.Add("bar"); Assert.Equal(ExpectedCount, exemptions.Count); }
public void Add_DuplicateValues_DuplicateAttributes_OneExemptionWithOneAttribute() { var exemptions = new ExemptionCollection(); exemptions.Add("foo", new AttributeCollection(Tuple.Create("Assembly", "A"))); exemptions.Add("foo", new AttributeCollection(Tuple.Create("Assembly", "A"))); Assert.Single(exemptions); Assert.Single(exemptions["foo"]); }
public void Add_DuplicateValues_DistinctAttributeNames_OneExemptionWithOneAttribute() { var exemptions = new ExemptionCollection(); exemptions.Add("foo", new AttributeCollection(Tuple.Create("Assembly", "A"))); exemptions.Add("foo", new AttributeCollection(Tuple.Create("Parameter", "B"))); var attributes = exemptions["foo"]; Assert.Single(exemptions); Assert.Single(attributes); Assert.DoesNotContain("Assembly", attributes.Names); Assert.Contains("Parameter", attributes.Names); Assert.Single(attributes["Parameter"]); }
private static void LoadScopeAndOrInvocationExemptions( IEnumerable <XElement> exemptionNodes, ExemptionCollection scopeExemptions, ExemptionCollection invocationExemptions) { // Type and member exemptions will, by default, apply to both scopes and invocations. // This method allows users to specify an "AppliesTo" attribute to control whether an // exemption applies to only one or the other. foreach (var exemption in exemptionNodes) { var appliesAttribute = exemption.Attribute("AppliesTo"); if (appliesAttribute != null) { var attributePairs = exemption.Attributes() .Where(x => x != appliesAttribute) .Select(x => Tuple.Create(x.Name.LocalName, x.Value)).ToArray(); AttributeCollection attributes = null; if (attributePairs.Length > 0) { attributes = new AttributeCollection(attributePairs); } if (string.Equals(appliesAttribute.Value, "Scope", StringComparison.OrdinalIgnoreCase)) { scopeExemptions.Add(exemption.Value, attributes); } else { invocationExemptions.Add(exemption.Value, attributes); } } else { var exemptions = new[] { exemption }; scopeExemptions.UnionWith(exemptions); invocationExemptions.UnionWith(exemptions); } } }
private bool IsSymbolExempt(ISymbol symbol, ExemptionCollection exemptions, params Tuple <string, string>[] additionalAttributes) { if (symbol == null) { return(false); } var attributes = DefaultAttributes; foreach (var additionalAttribute in additionalAttributes) { attributes.Add(additionalAttribute.Item1, additionalAttribute.Item2); } var symbolName = symbol.GetFullName(); if (exemptions.Contains(symbolName, attributes) || exemptions.Matches(symbolName, attributes)) { return(true); } return(false); }
public void Contains_NoAttribute_MixedCase_Found() { var exemptions = new ExemptionCollection("foo"); Assert.True(exemptions.Contains("FOO")); }
public void Matches_WithAttribute_MoreAttributesSpecified_Found() { var exemptions = new ExemptionCollection(Tuple.Create("*", new AttributeCollection(Tuple.Create("Assembly", "A")))); Assert.True(exemptions.Matches("foo", new AttributeCollection(Tuple.Create("Assembly", "A"), Tuple.Create("Parameter", "B")))); }
public void Matches_WithAttribute_LessAttributesSpecified_NotFound() { var exemptions = new ExemptionCollection(Tuple.Create("*", new AttributeCollection(Tuple.Create("Assembly", "A")))); Assert.False(exemptions.Matches("foo")); }
public void Matches_NoAttribute_Found(string pattern) { var exemptions = new ExemptionCollection(pattern); Assert.True(exemptions.Matches("foo")); }
public void Contains_WithMultiValuedAttribute_WrongValueSpecified_NotFound() { var exemptions = new ExemptionCollection(Tuple.Create("foo", new AttributeCollection(Tuple.Create("Assembly", "A|B")))); Assert.False(exemptions.Contains("foo", new AttributeCollection(Tuple.Create("Assembly", "D")))); }
public void Contains_WithMultiValuedAttribute_ValueNotSpecified_Found() { var exemptions = new ExemptionCollection(Tuple.Create("foo", new AttributeCollection(Tuple.Create("Assembly", "A|B")))); Assert.True(exemptions.Contains("foo", new AttributeCollection(Tuple.Create("Assembly", "A")))); }