Exemplo n.º 1
0
        public void ToLookupNullKey()
        {
            Country china, india, unknown;
            Data<Country> data = Data
            (
                china = new Country { Name = "China", Continent = "Asia" },
                india = new Country { Name = "India", Continent = "Asia" },
                unknown = new Country { Name = "Unknown", Continent = null }
            );

            ILookup<string, Country> continentLookup = data.ToLookup(x => x.Continent);

            using (IEnumerator<IGrouping<string, Country>> enumerator = continentLookup.GetEnumerator())
            {
                Assert.That(enumerator.MoveNext(), Is.True);
                Assert.That(enumerator.Current.Key, Is.EqualTo("Asia"));
                enumerator.Current.AssertSame(china, india);

                Assert.That(enumerator.MoveNext(), Is.True);
                Assert.That(enumerator.Current.Key, Is.EqualTo(null));
                enumerator.Current.AssertSame(unknown);

                Assert.That(enumerator.MoveNext(), Is.False);
            }
        }
        public void ThenByDescendingNullKey()
        {
            Country england, france, china, india, unknown;
            Data<Country> data = Data
            (
                england = new Country() { Name = "England", Continent = "Europe" },
                france = new Country() { Name = "France", Continent = "Europe" },
                china = new Country() { Name = "China", Continent = "Asia" },
                india = new Country() { Name = "India", Continent = "Asia" },
                unknown = new Country() { Name = "Unknown", Continent = null }
            );

            IOrderedEnumerable<Country> orderedData = data.OrderBy(x => true).ThenByDescending(x => x.Continent);

            orderedData.AssertSame(england, france, china, india, unknown);
        }
Exemplo n.º 3
0
        public void ToLookupNullElementInSource()
        {
            Country china, india, @null;
            Data<Country> data = Data
            (
                china = new Country { Name = "China", Continent = "Asia" },
                india = new Country { Name = "India", Continent = "Asia" },
                @null = null
            );

            ILookup<Country, Country> lookup = data.ToLookup(x => x);

            using (IEnumerator<IGrouping<Country, Country>> enumerator = lookup.GetEnumerator())
            {
                Assert.That(enumerator.MoveNext(), Is.True);
                Assert.That(enumerator.Current.Key, Is.SameAs(china));
                enumerator.Current.AssertSame(china);

                Assert.That(enumerator.MoveNext(), Is.True);
                Assert.That(enumerator.Current.Key, Is.SameAs(india));
                enumerator.Current.AssertSame(india);

                Assert.That(enumerator.MoveNext(), Is.True);
                Assert.That(enumerator.Current.Key, Is.SameAs(@null));
                enumerator.Current.AssertSame(@null);

                Assert.That(enumerator.MoveNext(), Is.False);
            }
        }
Exemplo n.º 4
0
        public void ThenByWithComparerNullKey()
        {
            Country england, france, china, india, unknown;
            Data<Country> data = Data
            (
                england = new Country() { Name = "England", Continent = "Europe" },
                france = new Country() { Name = "France", Continent = "Europe" },
                china = new Country() { Name = "China", Continent = "Asia" },
                india = new Country() { Name = "India", Continent = "Asia" },
                unknown = new Country() { Name = "Unknown", Continent = null }
            );

            IOrderedEnumerable<Country> orderedData = data.OrderBy(x => true).ThenBy(x => x.Continent, Comparer<string>.Default);

            orderedData.AssertSame(unknown, china, india, england, france);
        }