コード例 #1
0
        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"))));
        }
コード例 #2
0
        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))));
        }
コード例 #3
0
        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))));
        }
コード例 #4
0
        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"))));
        }
コード例 #5
0
        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"))));
        }
コード例 #6
0
        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
        }
コード例 #7
0
        public void Add_SingleValue_OneExemption()
        {
            var exemptions = new ExemptionCollection();

            exemptions.Add("foo");

            Assert.Single(exemptions);
        }
コード例 #8
0
        public void Add_DuplicateValues_MixedCase_OneExemption()
        {
            var exemptions = new ExemptionCollection();

            exemptions.Add("foo");
            exemptions.Add("FOO");

            Assert.Single(exemptions);
        }
コード例 #9
0
        public void Add_DistinctValues_MultipleExemptions()
        {
            const int ExpectedCount = 2;
            var       exemptions    = new ExemptionCollection();

            exemptions.Add("foo");
            exemptions.Add("bar");

            Assert.Equal(ExpectedCount, exemptions.Count);
        }
コード例 #10
0
        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"]);
        }
コード例 #11
0
        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"]);
        }
コード例 #12
0
        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);
                }
            }
        }
コード例 #13
0
        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);
        }
コード例 #14
0
        public void Contains_NoAttribute_MixedCase_Found()
        {
            var exemptions = new ExemptionCollection("foo");

            Assert.True(exemptions.Contains("FOO"));
        }
コード例 #15
0
        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"))));
        }
コード例 #16
0
        public void Matches_WithAttribute_LessAttributesSpecified_NotFound()
        {
            var exemptions = new ExemptionCollection(Tuple.Create("*", new AttributeCollection(Tuple.Create("Assembly", "A"))));

            Assert.False(exemptions.Matches("foo"));
        }
コード例 #17
0
        public void Matches_NoAttribute_Found(string pattern)
        {
            var exemptions = new ExemptionCollection(pattern);

            Assert.True(exemptions.Matches("foo"));
        }
コード例 #18
0
        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"))));
        }
コード例 #19
0
        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"))));
        }