Ejemplo n.º 1
0
        public void DebuggerAttributesValid <TKey, TElement>(ILookup <TKey, TElement> lookup, TKey dummy1, TElement dummy2)
        {
            // The dummy parameters can be removed once https://github.com/dotnet/buildtools/pull/1300 is brought in.
            Assert.Equal($"Count = {lookup.Count}", DebuggerAttributes.ValidateDebuggerDisplayReferences(lookup));

            object proxyObject = DebuggerAttributes.GetProxyObject(lookup);

            // Validate proxy fields
            Assert.Empty(DebuggerAttributes.GetDebuggerVisibleFields(proxyObject.GetType()));

            // Validate proxy properties
            IEnumerable <PropertyInfo> properties = DebuggerAttributes.GetDebuggerVisibleProperties(proxyObject.GetType());

            Assert.Equal(1, properties.Count());

            // Groupings
            PropertyInfo groupingsProperty = properties.Single(property => property.Name == "Groupings");

            Assert.Equal(DebuggerBrowsableState.RootHidden, DebuggerAttributes.GetDebuggerBrowsableState(groupingsProperty));
            var groupings = (IGrouping <TKey, TElement>[])groupingsProperty.GetValue(proxyObject);

            Assert.IsType <IGrouping <TKey, TElement>[]>(groupings); // Arrays can be covariant / of assignment-compatible types

            Assert.All(groupings.Zip(lookup, (l, r) => Tuple.Create(l, r)), tuple =>
            {
                Assert.Same(tuple.Item1, tuple.Item2);
            });

            Assert.Same(groupings, groupingsProperty.GetValue(proxyObject)); // The result should be cached, as Lookup is immutable.
        }
Ejemplo n.º 2
0
        public void DebuggerAttributesValid <TKey, TElement>(IGrouping <TKey, TElement> grouping, string keyString, TKey dummy1, TElement dummy2)
        {
            // The dummy parameters can be removed once https://github.com/dotnet/buildtools/pull/1300 is brought in.
            Assert.Equal($"Key = {keyString}", DebuggerAttributes.ValidateDebuggerDisplayReferences(grouping));

            object proxyObject = DebuggerAttributes.GetProxyObject(grouping);

            // Validate proxy fields
            Assert.Empty(DebuggerAttributes.GetDebuggerVisibleFields(proxyObject));

            // Validate proxy properties
            IDictionary <string, PropertyInfo> properties = DebuggerAttributes.GetDebuggerVisibleProperties(proxyObject);

            Assert.Equal(2, properties.Count);

            // Key
            TKey key = (TKey)properties["Key"].GetValue(proxyObject);

            Assert.Equal(grouping.Key, key);

            // Values
            PropertyInfo valuesProperty = properties["Values"];

            Assert.Equal(DebuggerBrowsableState.RootHidden, DebuggerAttributes.GetDebuggerBrowsableState(valuesProperty));
            TElement[] values = (TElement[])valuesProperty.GetValue(proxyObject);
            Assert.IsType <TElement[]>(values);                        // Arrays can be covariant / of assignment-compatible types
            Assert.Equal(grouping, values);
            Assert.Same(values, valuesProperty.GetValue(proxyObject)); // The result should be cached, as Grouping is immutable.
        }
Ejemplo n.º 3
0
        public void DebuggerAttributesValid <TKey, TElement>(IGrouping <TKey, TElement> grouping, string keyString)
        {
            Assert.Equal($"Key = {keyString}", DebuggerAttributes.ValidateDebuggerDisplayReferences(grouping));

            object proxyObject = DebuggerAttributes.GetProxyObject(grouping);

            // Validate proxy fields
            Assert.Empty(DebuggerAttributes.GetDebuggerVisibleFields(proxyObject.GetType()));

            // Validate proxy properties
            IEnumerable <PropertyInfo> properties = DebuggerAttributes.GetDebuggerVisibleProperties(proxyObject.GetType());

            Assert.Equal(2, properties.Count());

            // Key
            TKey key = (TKey)properties.Single(property => property.Name == "Key").GetValue(proxyObject);

            Assert.Equal(grouping.Key, key);

            // Values
            PropertyInfo valuesProperty = properties.Single(property => property.Name == "Values");

            Assert.Equal(DebuggerBrowsableState.RootHidden, DebuggerAttributes.GetDebuggerBrowsableState(valuesProperty));
            TElement[] values = (TElement[])valuesProperty.GetValue(proxyObject);
            Assert.IsType <TElement[]>(values);                        // Arrays can be covariant / of assignment-compatible types
            Assert.Equal(grouping, values);
            Assert.Same(values, valuesProperty.GetValue(proxyObject)); // The result should be cached, as Grouping is immutable.
        }
        public void DebuggerAttributesValid <TKey, TElement>(System.Linq.ILookup <TKey, TElement> lookup)
        {
            Assert.Equal($"Count = {lookup.Count}", DebuggerAttributes.ValidateDebuggerDisplayReferences(lookup));

            object proxyObject = DebuggerAttributes.GetProxyObject(lookup);

            // Validate proxy fields
            Assert.Empty(DebuggerAttributes.GetDebuggerVisibleFields(proxyObject.GetType()));

            // Validate proxy properties
            IEnumerable <PropertyInfo> properties = DebuggerAttributes.GetDebuggerVisibleProperties(proxyObject.GetType());

            Assert.Equal(1, properties.Count());

            // Groupings
            PropertyInfo groupingsProperty = properties.Single(property => property.Name == "Groupings");

            Assert.Equal(DebuggerBrowsableState.RootHidden, DebuggerAttributes.GetDebuggerBrowsableState(groupingsProperty));
            var groupings = (System.Linq.IGrouping <TKey, TElement>[])groupingsProperty.GetValue(proxyObject);

            Assert.IsType <System.Linq.IGrouping <TKey, TElement>[]>(groupings); // Arrays can be covariant / of assignment-compatible types

            Assert.All(groupings.Zip(lookup, (l, r) => Tuple.Create(l, r)), tuple =>
            {
                Assert.Same(tuple.Item1, tuple.Item2);
            });

            Assert.Same(groupings, groupingsProperty.GetValue(proxyObject)); // The result should be cached, as Lookup is immutable.
        }