Exemplo n.º 1
0
        public void TestOverallEquivalence([Values(false, true)] bool includeNull)
        {
            //--Arrange
            var collection = BuildSourceCollection(includeNull);
            var expected   = collection.ToLookup(x => x.key, x => x.element);

            //--Act/Assert
            var actual = new MutableLookup <long?, Guid>();

            foreach (var grouping in expected)
            {
                CollectionAssert.IsEmpty(actual[grouping.Key]);
                actual[grouping.Key] = grouping;
            }

            //--Assert
            Assert.IsFalse(actual.Contains(-1));
            CollectionAssert.AreEquivalent(expected.Select(x => x.Key), actual.Select(x => x.Key));
            foreach (var expectedGrouping in expected)
            {
                Assert.IsTrue(actual.Contains(expectedGrouping.Key));
                CollectionAssert.AreEquivalent(expectedGrouping, actual[expectedGrouping.Key]);
            }

            foreach (var(expectedGrouping, actualGrouping) in expected.Zip(actual, (e, a) => (e, a)))
            {
                Assert.AreEqual(expectedGrouping.Key, actualGrouping.Key);
                CollectionAssert.AreEquivalent(expectedGrouping, actualGrouping);
            }
        }