public void VisitConstructorInfoElementProducesCorrectValue(
            Func<MethodBase, bool> predicate, Accessibilities expected)
        {
            var sut = new AccessibilityCollector();
            BindingFlags bindingFlags =
                BindingFlags.Public | BindingFlags.NonPublic |
                BindingFlags.Instance | BindingFlags.Static;
            var constructorInfoElement = typeof(object).Assembly
                .GetTypes().SelectMany(t => t.GetConstructors(bindingFlags))
                .Where(predicate).Cast<ConstructorInfo>().First().ToElement();

            var actual = sut.Visit(constructorInfoElement);

            Assert.Empty(sut.Value);
            Assert.Equal(expected, actual.Value.Single());
        }
        public void VisitEventInfoElementManyTimeProducesCorrectValues()
        {
            var sut = new AccessibilityCollector();
            BindingFlags bindingFlags =
                BindingFlags.Public | BindingFlags.NonPublic |
                BindingFlags.Instance | BindingFlags.Static;
            var eventInfos = typeof(object).Assembly
                .GetTypes().SelectMany(t => t.GetEvents(bindingFlags)).ToArray();
            var eventInfoElement1 = eventInfos.First(x => x.GetAddMethod(true).IsFamily).ToElement();
            var eventInfoElement2 = eventInfos.First(x => x.GetRemoveMethod(true).IsPublic).ToElement();

            var actual = sut.Visit(eventInfoElement1).Visit(eventInfoElement2);

            Assert.Equal(
                new[] { Accessibilities.Protected, Accessibilities.Public },
                actual.Value.ToArray());
        }
        public void VisitConstructorInfoElementManyTimeProducesCorrectValues()
        {
            var sut = new AccessibilityCollector();
            BindingFlags bindingFlags =
                BindingFlags.Public | BindingFlags.NonPublic |
                BindingFlags.Instance | BindingFlags.Static;
            var constructorInfos = typeof(object).Assembly
                .GetTypes().SelectMany(t => t.GetConstructors(bindingFlags)).ToArray();
            var constructorInfoElement1 = constructorInfos.First(x => x.IsFamily).ToElement();
            var constructorInfoElement2 = constructorInfos.First(x => x.IsPrivate).ToElement();

            var actual = sut.Visit(constructorInfoElement1).Visit(constructorInfoElement2);

            Assert.Equal(
                new[] { Accessibilities.Protected, Accessibilities.Private },
                actual.Value.ToArray());
        }
        public void VisitEventInfoElementProducesCorrectValue(
            Func<EventInfo, bool> predicate, Accessibilities expected)
        {
            var sut = new AccessibilityCollector();
            BindingFlags bindingFlags =
                BindingFlags.Public | BindingFlags.NonPublic |
                BindingFlags.Instance | BindingFlags.Static;
            var eventInfoElement = typeof(object).Assembly
                .GetTypes().Concat(new[] { typeof(ClassWithMembers) })
                .SelectMany(t => t.GetEvents(bindingFlags))
                .Where(predicate).First().ToElement();

            var actual = sut.Visit(eventInfoElement);

            Assert.Empty(sut.Value);
            Assert.Equal(expected, actual.Value.Single());
        }
        public void VisitTypeElementProducesCorrectValue(
            Func<Type, bool> predicate, Accessibilities expected)
        {
            var sut = new AccessibilityCollector();
            var typeElement = typeof(object).Assembly
                .GetTypes().Where(predicate).First().ToElement();

            var actual = sut.Visit(typeElement);

            Assert.Empty(sut.Value);
            Assert.Equal(expected, actual.Value.Single());
        }
        public void VisitTypeElementManyTimeProducesCorrectValues()
        {
            var sut = new AccessibilityCollector();
            var types = typeof(object).Assembly.GetTypes();
            var typeElement1 = types.First(x => x.IsPublic).ToElement();
            var typeElement2 = types.First(x => x.IsNotPublic).ToElement();

            var actual = sut.Visit(typeElement1).Visit(typeElement2);

            Assert.Equal(
                new[] { Accessibilities.Public, Accessibilities.Internal },
                actual.Value.ToArray());
        }
        public void VisitPropertyInfoElementManyTimeProducesCorrectValues()
        {
            // Fixture setup
            var sut = new AccessibilityCollector();

            BindingFlags bindingFlags =
                BindingFlags.Public | BindingFlags.NonPublic |
                BindingFlags.Instance | BindingFlags.Static;

            var propertyInfos = typeof(object).Assembly
                .GetTypes().SelectMany(t => t.GetProperties(bindingFlags)).ToArray();

            var propertyInfoElement1 = propertyInfos.Where(
                x =>
                {
                    var getMethod = x.GetGetMethod(true);
                    var setMethod = x.GetSetMethod(true);
                    return getMethod != null && getMethod.IsAssembly &&
                           setMethod != null && setMethod.IsPrivate;
                })
                .First().ToElement();

            var propertyInfoElement2 = propertyInfos.Where(
                x =>
                {
                    var getMethod = x.GetGetMethod(true);
                    var setMethod = x.GetSetMethod(true);
                    return getMethod != null && getMethod.IsPublic &&
                           setMethod != null && setMethod.IsPrivate;
                })
                .First().ToElement();

            // Exercise system
            var actual = sut.Visit(propertyInfoElement1).Visit(propertyInfoElement2);

            // Verify outcome
            Assert.Equal(
                new[]
                {
                    Accessibilities.Internal | Accessibilities.Private,
                    Accessibilities.Public | Accessibilities.Private
                },
                actual.Value.ToArray());
        }
 public void VisitParameterInfoElementReturnsSutItself()
 {
     var sut = new AccessibilityCollector();
     var actual = sut.Visit((ParameterInfoElement)null);
     Assert.Equal(sut, actual);
 }
 public void VisitNullTypeElementThrows()
 {
     var sut = new AccessibilityCollector();
     Assert.Throws<ArgumentNullException>(() => sut.Visit((TypeElement)null));
 }