Beispiel #1
0
        /// <summary>
        /// Matches the type of the symbol with the membertype of the candidates
        /// </summary>
        /// <param name="symbol">The symbol.</param>
        /// <returns>True if there are any candidates left</returns>
        private IEnumerable <IBaseConfigModel> MatchSymbolType(ISymbol symbol, IEnumerable <IBaseConfigModel> candidates)
        {
            var matches = new List <IBaseConfigModel>();

            foreach (Member candidate in candidates)
            {
                if (SymbolMatcher.MatchSymbolKind(symbol, candidate.MemberType))
                {
                    matches.Add(candidate);
                }
            }

            return(matches);
        }
        public void MatchSymbolKindTest()
        {
            // Arrange
            var helpers = new TestHelpers();

            var fieldMember     = helpers.GetMockMember(Constants.PrivateFieldMember, "TestMemberName");
            var methodMember    = helpers.GetMockMember(Constants.PublicMethodMember, "TestMemberName");
            var namedTypeMember = helpers.GetMockMember(Constants.PublicNamedTypeMember, "TestMemberName");
            var propertyMember  = helpers.GetMockMember(Constants.PublicPropertyMember, "TestMemberName");
            var eventMember     = helpers.GetMockMember(Constants.PublicEventMember, "TestMemberName");

            // Act
            var fieldMatch     = SymbolMatcher.MatchSymbolKind(fieldMember, MemberType.Field);
            var methodMatch    = SymbolMatcher.MatchSymbolKind(methodMember, MemberType.Method);
            var namedTypeMatch = SymbolMatcher.MatchSymbolKind(namedTypeMember, MemberType.Class);
            var propertyMatch  = SymbolMatcher.MatchSymbolKind(propertyMember, MemberType.Property);
            var eventMatch     = SymbolMatcher.MatchSymbolKind(eventMember, MemberType.Event);

            var anyMatch = SymbolMatcher.MatchSymbolKind(fieldMember, MemberType.Any);

            var noFieldMatch     = SymbolMatcher.MatchSymbolKind(fieldMember, MemberType.Property);
            var noMethodMatch    = SymbolMatcher.MatchSymbolKind(methodMember, MemberType.Field);
            var noNamedTypeMatch = SymbolMatcher.MatchSymbolKind(namedTypeMember, MemberType.Field);
            var noPropertyMatch  = SymbolMatcher.MatchSymbolKind(propertyMember, MemberType.Field);
            var noEventMatch     = SymbolMatcher.MatchSymbolKind(eventMember, MemberType.Field);

            // Assert
            Assert.IsTrue(fieldMatch);
            Assert.IsTrue(methodMatch);
            Assert.IsTrue(namedTypeMatch);
            Assert.IsTrue(propertyMatch);
            Assert.IsTrue(eventMatch);

            Assert.IsTrue(anyMatch);

            Assert.IsFalse(noFieldMatch);
            Assert.IsFalse(noMethodMatch);
            Assert.IsFalse(noNamedTypeMatch);
            Assert.IsFalse(noPropertyMatch);
            Assert.IsFalse(noEventMatch);
        }