Exemplo n.º 1
0
        public void SelectMany()
        {
            Func <int, IEnumerable <int> > collectionSelector = i => Enumerable.Range(i, 10);
            Func <int, int, int>           resultSelector     = (i, e) => e * 2;

            foreach (var arr in new[] { empty, oneElement, manyElements })
            {
                Assert.Equal(
                    Enumerable.SelectMany(arr, collectionSelector, resultSelector),
                    ImmutableArrayExtensions.SelectMany(arr, collectionSelector, resultSelector));
            }

            Assert.Throws <NullReferenceException>(() => ImmutableArrayExtensions.SelectMany <int, int, int>(emptyDefault, null, null));
            Assert.Throws <ArgumentNullException>(() =>
                                                  ImmutableArrayExtensions.SelectMany <int, int, int>(manyElements, null, (i, e) => e));
            Assert.Throws <ArgumentNullException>(() =>
                                                  ImmutableArrayExtensions.SelectMany <int, int, int>(manyElements, i => new[] { i }, null));
        }
        public void SelectMany()
        {
            Func <int, IEnumerable <int> > collectionSelector = i => Enumerable.Range(i, 10);
            Func <int, int, int>           resultSelector     = (i, e) => e * 2;

            foreach (var arr in new[] { s_empty, s_oneElement, s_manyElements })
            {
                Assert.Equal(
                    Enumerable.SelectMany(arr, collectionSelector, resultSelector),
                    ImmutableArrayExtensions.SelectMany(arr, collectionSelector, resultSelector));
            }

            TestExtensionsMethods.ValidateDefaultThisBehavior(() => ImmutableArrayExtensions.SelectMany <int, int, int>(s_emptyDefault, null, null));
            AssertExtensions.Throws <ArgumentNullException>("collectionSelector", () =>
                                                            ImmutableArrayExtensions.SelectMany <int, int, int>(s_manyElements, null, (i, e) => e));
            AssertExtensions.Throws <ArgumentNullException>("resultSelector", () =>
                                                            ImmutableArrayExtensions.SelectMany <int, int, int>(s_manyElements, i => new[] { i }, null));
        }