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.
        }
예제 #2
0
        private static void AssertMatches <K, T>(IEnumerable <K> keys, IEnumerable <T> elements, System.Linq.ILookup <K, T> lookup)
        {
            Assert.NotNull(lookup);
            Assert.NotNull(keys);
            Assert.NotNull(elements);

            int num = 0;

            using (IEnumerator <K> keyEnumerator = keys.GetEnumerator())
                using (IEnumerator <T> elEnumerator = elements.GetEnumerator())
                {
                    while (keyEnumerator.MoveNext())
                    {
                        Assert.True(lookup.Contains(keyEnumerator.Current));

                        foreach (T e in lookup[keyEnumerator.Current])
                        {
                            Assert.True(elEnumerator.MoveNext());
                            Assert.Equal(e, elEnumerator.Current);
                        }
                        ++num;
                    }
                    Assert.False(elEnumerator.MoveNext());
                }
            Assert.Equal(num, lookup.Count);
        }