public void QualifiedSymbolNamesWithoutPrefixAreIgnored()
        {
            // Arrange
            var compilation = GetCompilation(@"
using System;

public namespace MyNamespace
{
    public class MyClass
    {
        public int MyField;
        public int MyProperty { get; set; }
        public event EventHandler<EventArgs> MyEvent;
        public void MyMethod() {}
    }
}");
            var symbolNames = ImmutableArray.Create(
                "MyNamespace.MySubNamespace",
                "MyNamespace.MyClass",
                "MyNamespace.MyClass.MyField",
                "MyNamespace.MyClass.MyProperty",
                "MyNamespace.MyClass.MyEvent",
                "MyNamespace.MyClass.MyMethod()");

            // Act
            var options = SymbolNamesWithValueOption <Unit> .Create(symbolNames, compilation, null, null);

            // Assert
            Assert.Empty(options.GetTestAccessor().Names);
            Assert.Empty(options.GetTestAccessor().Symbols);
            Assert.Empty(options.GetTestAccessor().WildcardNamesBySymbolKind);
        }
        public void WildcardConstructionsWithPrefixAreCorrectlyClassified()
        {
            // Arrange
            var compilation = GetCompilation();
            var symbolNames = ImmutableArray.Create(
                "N:MyNamespace*",
                "T:MyNamespace.MyClass*",
                "F:MyNamespace.MyClass.MyField*",
                "P:MyNamespace.MyClass.MyProperty*",
                "E:MyNamespace.MyClass.MyEvent*",
                "M:MyNamespace.MyClass.MyMethod(*");

            // Act
            var options = SymbolNamesWithValueOption <Unit> .Create(symbolNames, compilation, null, null);

            // Assert
            Assert.Empty(options.GetTestAccessor().Names);
            Assert.Empty(options.GetTestAccessor().Symbols);
            Assert.Equal(symbolNames.Length, options.GetTestAccessor().WildcardNamesBySymbolKind.Count);
            Assert.True(options.GetTestAccessor().WildcardNamesBySymbolKind[SymbolKind.Namespace].ContainsKey("MyNamespace"));
            Assert.True(options.GetTestAccessor().WildcardNamesBySymbolKind[SymbolKind.NamedType].ContainsKey("MyNamespace.MyClass"));
            Assert.True(options.GetTestAccessor().WildcardNamesBySymbolKind[SymbolKind.Field].ContainsKey("MyNamespace.MyClass.MyField"));
            Assert.True(options.GetTestAccessor().WildcardNamesBySymbolKind[SymbolKind.Property].ContainsKey("MyNamespace.MyClass.MyProperty"));
            Assert.True(options.GetTestAccessor().WildcardNamesBySymbolKind[SymbolKind.Event].ContainsKey("MyNamespace.MyClass.MyEvent"));
            Assert.True(options.GetTestAccessor().WildcardNamesBySymbolKind[SymbolKind.Method].ContainsKey("MyNamespace.MyClass.MyMethod("));
        }
        public void WildcardConstructionsWithoutPrefixAreCorrectlyClassified()
        {
            // Arrange
            var compilation = GetCompilation();
            var symbolNames = ImmutableArray.Create(
                "MyNamespace*",
                "MyNamespace.MyClass*",
                "MyNamespace.MyClass.MyField*",
                "MyNamespace.MyClass.MyProperty*",
                "MyNamespace.MyClass.MyEvent*",
                "MyNamespace.MyClass.MyMethod(*");

            // Act
            var options = SymbolNamesWithValueOption <Unit> .Create(symbolNames, compilation, null, static name => new SymbolNamesWithValueOption <Unit> .NameParts(name, Unit.Default));

            // Assert
            Assert.Empty(options.GetTestAccessor().Names);
            Assert.Empty(options.GetTestAccessor().Symbols);
            Assert.Single(options.GetTestAccessor().WildcardNamesBySymbolKind);
            Assert.Equal(symbolNames.Length, options.GetTestAccessor().WildcardNamesBySymbolKind[SymbolNamesWithValueOption <Unit> .AllKinds].Count);
            Assert.True(options.GetTestAccessor().WildcardNamesBySymbolKind[SymbolNamesWithValueOption <Unit> .AllKinds].ContainsKey("MyNamespace"));
            Assert.True(options.GetTestAccessor().WildcardNamesBySymbolKind[SymbolNamesWithValueOption <Unit> .AllKinds].ContainsKey("MyNamespace.MyClass"));
            Assert.True(options.GetTestAccessor().WildcardNamesBySymbolKind[SymbolNamesWithValueOption <Unit> .AllKinds].ContainsKey("MyNamespace.MyClass.MyField"));
            Assert.True(options.GetTestAccessor().WildcardNamesBySymbolKind[SymbolNamesWithValueOption <Unit> .AllKinds].ContainsKey("MyNamespace.MyClass.MyProperty"));
            Assert.True(options.GetTestAccessor().WildcardNamesBySymbolKind[SymbolNamesWithValueOption <Unit> .AllKinds].ContainsKey("MyNamespace.MyClass.MyEvent"));
            Assert.True(options.GetTestAccessor().WildcardNamesBySymbolKind[SymbolNamesWithValueOption <Unit> .AllKinds].ContainsKey("MyNamespace.MyClass.MyMethod("));
        }
        public void QualifiedSymbolNamesWithPrefixAreProcessedAsSymbols()
        {
            // Arrange
            var compilation = GetCompilation(@"
using System;

public namespace MyNamespace
{
    public class MyClass
    {
        public int MyField;
        public int MyProperty { get; set; }
        public event EventHandler<EventArgs> MyEvent;
        public void MyMethod() {}
    }
}");
            var symbolNames = ImmutableArray.Create(
                "N:MyNamespace",
                "T:MyNamespace.MyClass",
                "F:MyNamespace.MyClass.MyField",
                "P:MyNamespace.MyClass.MyProperty",
                "E:MyNamespace.MyClass.MyEvent",
                "M:MyNamespace.MyClass.MyMethod()");

            // Act
            var options = SymbolNamesWithValueOption <Unit> .Create(symbolNames, compilation, null, static name => new SymbolNamesWithValueOption <Unit> .NameParts(name, Unit.Default));

            // Assert
            Assert.Empty(options.GetTestAccessor().Names);
            Assert.Equal(symbolNames.Length, options.GetTestAccessor().Symbols.Count);
            Assert.Empty(options.GetTestAccessor().WildcardNamesBySymbolKind);
        }
        public void WhenNoSymbolNames_ReturnsEmpty()
        {
            // Arrange & act
            var options = SymbolNamesWithValueOption <Unit> .Create(ImmutableArray <string> .Empty, GetCompilation(), null, null);

            // Assert
            Assert.Equal(SymbolNamesWithValueOption <Unit> .Empty, options);
        }
        public void WhenNoSymbolNames_ReturnsEmpty()
        {
            // Arrange & act
            var options = SymbolNamesWithValueOption <Unit> .Create(ImmutableArray <string> .Empty, GetCompilation(), null, static name => new SymbolNamesWithValueOption <Unit> .NameParts(name, Unit.Default));

            // Assert
            Assert.Equal(SymbolNamesWithValueOption <Unit> .Empty, options);
        }
        public void UnqualifiedSymbolNamesAreProcessedAsNames()
        {
            // Arrange
            // Note that there is no check for the existence of the member
            var compilation = GetCompilation();
            var symbolNames = ImmutableArray.Create("MyNamespace", "MyClass", "MyMethod()", "MyProperty", "MyEvent", "MyField");

            // Act
            var options = SymbolNamesWithValueOption <Unit> .Create(symbolNames, compilation, null, null);

            // Assert
            Assert.Equal(symbolNames.Length, options.GetTestAccessor().Names.Count);
            Assert.Empty(options.GetTestAccessor().Symbols);
            Assert.Empty(options.GetTestAccessor().WildcardNamesBySymbolKind);
        }
        public void UnsupportedWildcardConstructionsAreIgnored()
        {
            // Arrange
            var compilation = GetCompilation();
            var symbolNames = ImmutableArray.Create(
                "*",        // only wildcard symbol
                "*a",       // wildcard symbol is not last
                "a*a",      // wildcard symbol is not last
                "*a*");     // more than one wildcard symbol

            // Act
            var options = SymbolNamesWithValueOption <Unit> .Create(symbolNames, compilation, null, null);

            // Assert
            Assert.Empty(options.GetTestAccessor().Names);
            Assert.Empty(options.GetTestAccessor().Symbols);
            Assert.Empty(options.GetTestAccessor().WildcardNamesBySymbolKind);
        }
        public void UnfoundQualifiedSymbolNamesWithPrefixAreExcluded()
        {
            // Arrange
            var compilation = GetCompilation();
            var symbolNames = ImmutableArray.Create(
                "N:MyNamespace",
                "T:MyNamespace.MyClass",
                "F:MyNamespace.MyClass.MyField",
                "P:MyNamespace.MyClass.MyProperty",
                "E:MyNamespace.MyClass.MyEvent",
                "M:MyNamespace.MyClass.MyMethod()");

            // Act
            var options = SymbolNamesWithValueOption <Unit> .Create(symbolNames, compilation, null, null);

            // Assert
            Assert.Empty(options.GetTestAccessor().Names);
            Assert.Empty(options.GetTestAccessor().Symbols);
            Assert.Empty(options.GetTestAccessor().WildcardNamesBySymbolKind);
        }
        public void SymbolNamePartsFuncIsCalledForEachSymbol()
        {
            // Arrange
            var callCount   = 0;
            var symbolNames = ImmutableArray.Create("a", "b");
            Func <string, SymbolNamesWithValueOption <Unit> .NameParts> func = symbolName =>
            {
                if (symbolNames.Contains(symbolName))
                {
                    callCount++;
                }
                return(new SymbolNamesWithValueOption <Unit> .NameParts(symbolName));
            };

            // Act
            SymbolNamesWithValueOption <Unit> .Create(symbolNames, GetCompilation(), null, func);

            // Assert
            Assert.Equal(2, callCount);
        }
        public void WildcardMatch(string patternName, string symbolName)
        {
            // Arrange
            var compilation = GetCompilation(@"
public namespace MyCompany.MyProduct.MyFeature
{
    public class MyOuterClass
    {
        public class MyInnerClass
        {
            public int MyField;
            public MyInnerClass() {}
            public MyInnerClass(int i) {}
            public int MyProperty { get; set; }
            public int this[]
            {
                get { return 42; }
                set {}
            }
            public int this[string s]
            {
                get { return 42; }
                set {}
            }
            public event EventHandler<EventArgs> MyEvent;
            public void MyMethod() {}
            public void MyMethod2(string s) {}
        }
    }
}");
            var symbolNames = ImmutableArray.Create(patternName);
            var symbol      = FindSymbol(compilation, symbolName);
            var options     = SymbolNamesWithValueOption <Unit> .Create(symbolNames, compilation, null, null);

            // Act
            var isFound = options.Contains(symbol);

            // Assert
            Assert.True(isFound);
            Assert.True(options.GetTestAccessor().WildcardMatchResult.ContainsKey(symbol));
        public void ValueCanBeAssociatedWithAllSymbolNames()
        {
            // Arrange
            var compilation = GetCompilation(@"
using System;

public namespace MyNamespace
{
    public class MyClass {}
}");
            var symbolNames = ImmutableArray.Create(
                "MyClass->SomeValue1",
                "T:MyNamespace.MyClass->SomeValue2",
                "MyClass*->SomeValue3",
                "T:MyClass*->SomeValue4");

            var namedTypeSymbol = (INamedTypeSymbol)compilation.GetSymbolsWithName("MyClass").Single();

            // Act
            var options = SymbolNamesWithValueOption <string> .Create(symbolNames, compilation, null,
                                                                      getSymbolNamePartsFunc : symbolName =>
            {
                var split = symbolName.Split(new[] { "->" }, StringSplitOptions.RemoveEmptyEntries);
                return(new SymbolNamesWithValueOption <string> .NameParts(split[0], split[1]));
            });

            // Assert
            Assert.Single(options.GetTestAccessor().Names);
            Assert.Equal("SomeValue1", options.GetTestAccessor().Names["MyClass"]);
            Assert.Single(options.GetTestAccessor().Symbols);
            Assert.Equal("SomeValue2", options.GetTestAccessor().Symbols[namedTypeSymbol]);
            Assert.Equal(2, options.GetTestAccessor().WildcardNamesBySymbolKind.Count);
            Assert.Single(options.GetTestAccessor().WildcardNamesBySymbolKind[SymbolNamesWithValueOption <Unit> .AllKinds]);
            Assert.Equal("SomeValue3", options.GetTestAccessor().WildcardNamesBySymbolKind[SymbolNamesWithValueOption <Unit> .AllKinds]["MyClass"]);
            Assert.Single(options.GetTestAccessor().WildcardNamesBySymbolKind[SymbolKind.NamedType]);
            Assert.Equal("SomeValue4", options.GetTestAccessor().WildcardNamesBySymbolKind[SymbolKind.NamedType]["MyClass"]);
        }