Esempio n. 1
0
        public void GroupByIsDefered()
        {
            var _src = new IterateAndCount(10);
            var a    = _src.GroupBy(i => i > 5, null);
            var b    = _src.GroupBy(i => i > 5, j => "str: " + j.ToString(CultureInfo.InvariantCulture), null);
            var c    = _src.GroupBy(i => i > 5, (key, group) => StringHelper.Concat(group.ToArray()), null);
            var d    = _src.GroupBy(i => i > 5, j => j + 1, (key, group) => StringHelper.Concat(group.ToArray()), null);

            Assert.AreEqual(_src.Total, 0);
            a.Consume();
            b.Consume();
            c.Consume();
            d.Consume();
            Assert.AreEqual(_src.Total, 40);
        }
Esempio n. 2
0
        public void GroupByIsDeferedToGetEnumerator()
        {
            var _src = new IterateAndCount(10);
            var a    = _src.GroupBy(i => i > 5, null);

            Assert.AreEqual(_src.Total, 0);
            using (var enumerator = a.GetEnumerator())
            {
                // This is a shame, GroupBy is not really deffered
                Assert.AreEqual(_src.Total, 10);
            }
            Assert.AreEqual(_src.Total, 10);
            using (var enumerator = a.GetEnumerator())
            {
                // This is a shame, GroupBy is not really deffered
                Assert.AreEqual(_src.Total, 20);
            }
            Assert.AreEqual(_src.Total, 20);
        }
Esempio n. 3
0
        public void GroupByIsDeferedToGetEnumerator() // TODO: Review
        {
            var src = new IterateAndCount(10);
            var a   = src.GroupBy(i => i > 5, null);

            Assert.AreEqual(src.Total, 0);
            using (var enumerator = a.GetEnumerator())
            {
                // This is a shame, GroupBy is not really deffered
                GC.KeepAlive(enumerator);
                Assert.AreEqual(src.Total, 10);
            }
            Assert.AreEqual(src.Total, 10);
            using (var enumerator = a.GetEnumerator())
            {
                // This is a shame, GroupBy is not really deffered
                GC.KeepAlive(enumerator);
                Assert.AreEqual(src.Total, 20);
            }
            Assert.AreEqual(src.Total, 20);
        }
Esempio n. 4
0
        public void GroupByIsDeferredToGetEnumerator()
        {
            var src = new IterateAndCount(10);
            var a   = src.GroupBy(i => i > 5, null);

            Assert.AreEqual(src.Total, 0);
            // ReSharper disable once PossibleMultipleEnumeration
            using (var enumerator = a.GetEnumerator())
            {
                // This is a shame, GroupBy is not really deferred
                GC.KeepAlive(enumerator);
                Assert.AreEqual(src.Total, 10);
            }
            Assert.AreEqual(src.Total, 10);
            // ReSharper disable once PossibleMultipleEnumeration
            using (var enumerator = a.GetEnumerator())
            {
                // This is a shame, GroupBy is not really deferred
                GC.KeepAlive(enumerator);
                Assert.AreEqual(src.Total, 20);
            }
            Assert.AreEqual(src.Total, 20);
        }