示例#1
0
        public void SortProviderNullableTypeTest()
        {
            List <Thing> Things = Thing.GenerateThings(10);

            IEnumerable <Thing> Results = Things.Sort(
                SortComparerFactory,
                new SortCriteria[]
            {
                new SortCriteria
                {
                    SortDirection = SortDirection.Ascending,
                    SortField     = "Flag"
                }
            });

            CollectionAssert.AreEqual(
                Things.OrderBy(i => i.Flag).ToList(),
                Results.ToList());

            Results = Things.Sort(
                SortComparerFactory,
                new SortCriteria[]
            {
                new SortCriteria
                {
                    SortDirection = SortDirection.Descending,
                    SortField     = "Flag"
                }
            });

            CollectionAssert.AreEqual(
                Things.OrderByDescending(i => i.Flag).ToList(),
                Results.ToList());
        }
示例#2
0
        public void SortProviderSwampThingTest()
        {
            List <Thing> Things = Thing.GenerateThings(10);

            IEnumerable <Thing> Results = Things.Sort(
                SortComparerFactory,
                new SortCriteria[]
            {
                new SortCriteria
                {
                    SortDirection = SortDirection.Ascending,
                    SortField     = "SwampName"
                }
            });

            CollectionAssert.AreEqual(
                Things.OrderBy(i => (i as SwampThing)?.SwampName ?? null).ToList(),
                Results.ToList());

            Results = Things.Sort(
                SortComparerFactory,
                new SortCriteria[]
            {
                new SortCriteria
                {
                    SortDirection = SortDirection.Descending,
                    SortField     = "SwampName"
                }
            });

            CollectionAssert.AreEqual(
                Things.OrderByDescending(i => (i as SwampThing)?.SwampName ?? null).ToList(),
                Results.ToList());
        }
示例#3
0
        public void SortProviderOneSideNullableTypeTest()
        {
            List <Thing> Things = Thing.GenerateThings(10);

            IEnumerable <Thing> Results = Things.Sort(
                SortComparerFactory,
                new SortCriteria[]
            {
                new SortCriteria
                {
                    SortDirection = SortDirection.Ascending,
                    SortField     = "License"
                }
            });

            CollectionAssert.AreEqual(
                Things.OrderBy(
                    i => i is SwampThing swampThing
                                                ? swampThing.License
                                                : i is SpaceThing spaceThing
                                                        ? spaceThing.License
                                                        : null).ToList(),
                Results.ToList());

            Results = Things.Sort(
                SortComparerFactory,
                new SortCriteria[]
            {
                new SortCriteria
                {
                    SortDirection = SortDirection.Descending,
                    SortField     = "License"
                }
            });

            CollectionAssert.AreEqual(
                Things.OrderByDescending(
                    i => i is SwampThing swampThing
                                                ? swampThing.License
                                                : i is SpaceThing spaceThing
                                                        ? spaceThing.License
                                                        : null).ToList(),
                Results.ToList());
        }
示例#4
0
        public void SortProviderMismatchedTypesTest()
        {
            List <Thing> Things = Thing.GenerateThings(10);

            IEnumerable <Thing> Results = Things.Sort(
                SortComparerFactory,
                new SortCriteria[]
            {
                new SortCriteria
                {
                    SortDirection = SortDirection.Ascending,
                    SortField     = "Value"
                }
            });

            try
            {
                Results.ToList();
                Assert.Fail();
            }
#pragma warning disable CA1031 // Do not catch general exception types
            catch (Exception exception)
#pragma warning restore CA1031 // Do not catch general exception types
            {
                bool FoundMatch = false;
                while (exception != null)
                {
                    if (exception.Message == "Object must be of type Int64.")
                    {
                        FoundMatch = true;
                        break;
                    }
                    exception = exception.InnerException;
                }
                if (!FoundMatch)
                {
                    Assert.Fail();
                }
            }
        }
示例#5
0
        public void SortProviderMixedTypeTest()
        {
            List <Thing> Things = Thing.GenerateThings(100);

            SortCriteria[] sortCriteria = new SortCriteria[]
            {
                new SortCriteria
                {
                    SortDirection = SortDirection.Ascending,
                    SortField     = "Text"
                },
                new SortCriteria
                {
                    SortDirection = SortDirection.Descending,
                    SortField     = "Flag"
                },
                new SortCriteria
                {
                    SortDirection = SortDirection.Ascending,
                    SortField     = "Day"
                },
                new SortCriteria
                {
                    SortDirection = SortDirection.Descending,
                    SortField     = "Id"
                },
            };

            IEnumerable <Thing> Results = Things.Sort(
                SortComparerFactory,
                sortCriteria);

            CollectionAssert.AreEqual(
                Things.OrderBy(i => i.Text).ThenByDescending(i => i.Flag).ThenBy(i => i.Day).ThenByDescending(i => i.Id).ToList(),
                Results.ToList());
        }