Esempio n. 1
0
        public void TestThenBySelectorPreserved()
        {
            var sequence = new[]
                               {
                                   new {A = 2, B = 0},
                                   new {A = 1, B = 5},
                                   new {A = 2, B = 2},
                                   new {A = 1, B = 3},
                                   new {A = 1, B = 4},
                                   new {A = 2, B = 1},
                               };

            var resultA1 = sequence.OrderBy(x => x.A, OrderByDirection.Ascending)
                                     .ThenBy(y => y.B, OrderByDirection.Ascending);
            var resultA2 = sequence.OrderBy(x => x.A)
                                   .ThenBy(y => y.B);
            // ensure both produce the same order
            Assert.IsTrue(resultA1.SequenceEqual(resultA2));

            var resultB1 = sequence.OrderBy(x => x.A, OrderByDirection.Ascending)
                                     .ThenBy(y => y.B, OrderByDirection.Descending);
            var resultB2 = sequence.OrderBy(x => x.A)
                                   .ThenByDescending(y => y.B);
            // ensure both produce the same order
            Assert.IsTrue(resultB1.SequenceEqual(resultB2));
        }
Esempio n. 2
0
        public void Should_Insert_And_Retrieve_Page_PageContents_Successfully()
        {
            var page = TestDataProvider.CreateNewPage();

            var pageContents = new[]
                {
                    TestDataProvider.CreateNewPageContent(null, page),
                    TestDataProvider.CreateNewPageContent(null, page),
                    TestDataProvider.CreateNewPageContent(null, page)
                };

            page.PageContents = pageContents;
            
            var pageOptions = new[]
                {
                    TestDataProvider.CreateNewPageOption(page),
                    TestDataProvider.CreateNewPageOption(page),
                    TestDataProvider.CreateNewPageOption(page)
                };

            page.Options = pageOptions;

            SaveEntityAndRunAssertionsInTransaction(
                page,
                result =>
                {
                    Assert.AreEqual(page, result);
                    Assert.AreEqual(pageContents.OrderBy(f => f.Id), result.PageContents.OrderBy(f => f.Id));
                });
        }       
Esempio n. 3
0
        public void TestCommitOrder() {
            var list = new[] {"@cba-1.0.1", "@cba-1.1.1", "@cba-1.1", "@cba-1.0", "@cba-1"};

            var orderedList = list.OrderBy(x => x);

            orderedList.Should().Equal(new[] {"@cba-1", "@cba-1.0", "@cba-1.0.1", "@cba-1.1", "@cba-1.1.1"});
        }
        public void Test1()
        {
            var names = new[] {"Pavel", "Alexander", "Anna"};

            IOrderedEnumerable<string> sorted = names.OrderBy(n => n.Length);

            Assert.That(sorted, Is.EqualTo(new[] {"Anna", "Pavel", "Alexander"}));
        }
        public void NaturalSortComparerTest() {
            // Arrange
            var comparer = new NaturalSortComparer();
            var source = new[] { "2name", "1name", "20name", "3name", "11name" };

            // Act
            string[] destination = source.OrderBy(p => p, comparer).ToArray();

            // Assert
            Assert.AreEqual(source.Length, destination.Length);
            Assert.AreEqual("1name", destination[0]);
            Assert.AreEqual("2name", destination[1]);
            Assert.AreEqual("3name", destination[2]);
            Assert.AreEqual("11name", destination[3]);
            Assert.AreEqual("20name", destination[4]);
        }
        public void RemoveVersionSortRemovesThenByWhenVersionIsRepresentedInAWrapperObject()
        {
            // Arrange
            var packageAb = new { Id = "A", WrapperObject = new { Version = "B" } };
            var packageAa = new { Id = "A", WrapperObject = new { Version = "A" } };
            var packageAc = new { Id = "A", WrapperObject = new { Version = "C" } };

            var source = new[] { packageAb, packageAc, packageAa }.AsQueryable();

            // Act
            var resultA = source.OrderBy(p => p.Id).ThenBy(p => p.Id).ThenByDescending(p => p.WrapperObject.Version);
            var resultB = source.WithoutVersionSort().OrderBy(p => p.Id).ThenBy(p => p.Id).ThenByDescending(p => p.WrapperObject.Version);

            // Assert
            Assert.Equal(new[] { packageAc, packageAb, packageAa }, resultA);
            Assert.Equal(new[] { packageAb, packageAc, packageAa }, resultB);
        }
Esempio n. 7
0
        public void NaturalSortingCanBeDoneByPaddingAllTheNumbers()
        {
            var unsorted = new[]
                         {
                             "10.10.10",
                             "9.9.9"
                         };

            var sorted = unsorted.OrderBy(s => s.PadNumbers(2));

            CollectionAssert.AreEqual(new[]
                                      {
                                          "9.9.9",
                                          "10.10.10"
                                      },
                                      sorted.ToArray());
        }
        public void RemoveVersionSortRemovesThenByWhenItIsNestedInsideAnotherThenBy()
        {
            // Arrange
            var packageAb = new V2FeedPackage { Id = "A", Version = "B" };
            var packageAa = new V2FeedPackage { Id = "A", Version = "A" };
            var packageAc = new V2FeedPackage { Id = "A", Version = "C" };

            var source = new[] { packageAb, packageAc, packageAa }.AsQueryable();

            // Act
            var resultA = source.OrderBy(p => p.Id).ThenBy(p => p.Id).ThenByDescending(p => p.Version);
            var resultB = source.WithoutVersionSort().OrderBy(p => p.Id).ThenBy(p => p.Id).ThenByDescending(p => p.Version);

            // Assert
            Assert.Equal(new[] { packageAc, packageAb, packageAa }, resultA);
            Assert.Equal(new[] { packageAb, packageAc, packageAa }, resultB);
        }
        public void RemoveVersionSortRemovesThenByOnVersion()
        {
            // Arrange
            var packageAb = new V2FeedPackage { Id = "A", Version = "B" };
            var packageAa = new V2FeedPackage { Id = "A", Version = "A" };
            var packageCa = new V2FeedPackage { Id = "C", Version = "A" };

            var source = new[] { packageAb, packageCa, packageAa }.AsQueryable();

            // Act
            var resultA = source.OrderBy(p => p.Id).ThenBy(p => p.Version);
            var resultB = source.WithoutVersionSort().OrderBy(p => p.Id).ThenBy(p => p.Version);

            // Assert
            Assert.Equal(new[] { packageAa, packageAb, packageCa }, resultA);
            Assert.Equal(new[] { packageAb, packageAa, packageCa }, resultB);
        }
Esempio n. 10
0
        public void Should_Insert_And_Retrieve_Content_PageContents_Successfully()
        {
            var content = TestDataProvider.CreateNewContent();
            var pageContents = new[]
                {
                    TestDataProvider.CreateNewPageContent(content),
                    TestDataProvider.CreateNewPageContent(content)
                };
            content.PageContents = pageContents;

            SaveEntityAndRunAssertionsInTransaction(
                content,
                result =>
                    {
                        Assert.AreEqual(content, result);
                        Assert.AreEqual(pageContents.OrderBy(f => f.Id), result.PageContents.OrderBy(f => f.Id));
                    });
        }
Esempio n. 11
0
        public void Should_Insert_And_Retrieve_Region_PageContentOptions_Successfully()
        {
            var region = TestDataProvider.CreateNewRegion();

            var pageContents = new[]
                {
                    TestDataProvider.CreateNewPageContent(null, null, region)
                };
            region.PageContents = pageContents;

            SaveEntityAndRunAssertionsInTransaction(
                region,
                result =>
                {
                    Assert.AreEqual(region, result);
                    Assert.AreEqual(pageContents.OrderBy(f => f.Id), result.PageContents.OrderBy(f => f.Id));
                });
        }
Esempio n. 12
0
        public void Should_Insert_And_Retrieve_Region_LayoutRegions_Successfully()
        {
            var region = TestDataProvider.CreateNewRegion();

            var layoutRegions = new[]
                {
                    TestDataProvider.CreateNewLayoutRegion(null, region),
                    TestDataProvider.CreateNewLayoutRegion(null, region)
                };
            region.LayoutRegion = layoutRegions;

            SaveEntityAndRunAssertionsInTransaction(
                region,
                result =>
                {
                    Assert.AreEqual(region, result);
                    Assert.AreEqual(layoutRegions.OrderBy(f => f.Id), result.LayoutRegion.OrderBy(f => f.Id));
                });
        }
Esempio n. 13
0
        public void Should_Insert_And_Retrieve_Widget_ContentOptions_Successfully()
        {
            var widget = TestDataProvider.CreateNewWidget();

            var contentOptions = new[]
                {
                    TestDataProvider.CreateNewContentOption(widget),
                    TestDataProvider.CreateNewContentOption(widget)
                };
            widget.ContentOptions = contentOptions;

            SaveEntityAndRunAssertionsInTransaction(
                widget,
                result =>
                {
                    Assert.AreEqual(widget, result);
                    Assert.AreEqual(contentOptions.OrderBy(f => f.Id), result.ContentOptions.OrderBy(f => f.Id));
                });
        }
Esempio n. 14
0
        public void Should_Insert_And_Retrieve_Layout_Pages_Successfully()
        {
            var layout = TestDataProvider.CreateNewLayout();
            var pages = new[]
                {
                    TestDataProvider.CreateNewPage(layout),
                    TestDataProvider.CreateNewPage(layout),
                    TestDataProvider.CreateNewPage(layout)
                };
            layout.Pages = pages;

            SaveEntityAndRunAssertionsInTransaction(
                layout,
                result =>
                    {
                        Assert.AreEqual(layout, result);
                        Assert.AreEqual(pages.OrderBy(f => f.Id), result.Pages.OrderBy(f => f.Id));
                    });
        }
        public void Should_Insert_And_Retrieve_PageProperties_PageTags_Successfully()
        {
            var page = TestDataProvider.CreateNewPageProperties();

            var pageTags = new[]
                {
                    TestDataProvider.CreateNewPageTag(page),
                    TestDataProvider.CreateNewPageTag(page),
                    TestDataProvider.CreateNewPageTag(page)
                };

            page.PageTags = pageTags;

            SaveEntityAndRunAssertionsInTransaction(
                page,
                result =>
                {
                    Assert.AreEqual(page, result);
                    Assert.AreEqual(pageTags.OrderBy(f => f.Id), result.PageTags.OrderBy(f => f.Id));
                });
        }
Esempio n. 16
0
        public void Should_Insert_And_Retrieve_MediaFolder_Files_Successfully()
        {
            var mediaFolder = TestDataProvider.CreateNewMediaFolder();

            var files = new []
                {
                    TestDataProvider.CreateNewMediaFile(mediaFolder),
                    TestDataProvider.CreateNewMediaImage(mediaFolder),
                    TestDataProvider.CreateNewMediaImage( mediaFolder)
                };

            mediaFolder.Medias = files;

            SaveEntityAndRunAssertionsInTransaction(
                mediaFolder,
                result =>
                {
                    Assert.AreEqual(mediaFolder, result);
                    Assert.AreEqual(files.OrderBy(f => f.Id), result.Medias.OrderBy(f => f.Id));
                });
        }
Esempio n. 17
0
        public void Sort_WithoutLabels()
        {
            var semVers = new[]
            {
                "2.1.0",
                "2.0.0",
                "2.1.1",
                "1.0.0",
            }.Select(SemanticVersion.Parse);

            var sortedSemVers = semVers.OrderBy(sv => sv).Select(x => x.ToString()).ToList();
            // 1.0.0 < 2.0.0 < 2.1.0 < 2.1.1.
            CollectionAssert.AreEqual(new[]
            {
                "1.0.0",
                "2.0.0",
                "2.1.0",
                "2.1.1",
            }, sortedSemVers);

            // Example: 1.0.0-alpha < 1.0.0-alpha.1 < 1.0.0-alpha.beta < 1.0.0-beta < 1.0.0-beta.2 < 1.0.0-beta.11 < 1.0.0-rc.1 < 1.0.0.
        }
        public void SplitUnsupportedQuery()
        {
            IQueryable<string> queryRoot = new[] { "query", "root" }.AsQueryable();
            IQueryable<string> query = queryRoot.OrderBy(s => s).ThenBy(s => s);

            IQueryable supportedQuery;
            IQueryable unsupportedQuery;

            supportedQuery = QueryComposer.Split(query, out unsupportedQuery);

            Assert.IsNull(supportedQuery,
                "The supported query should be null.");

            MethodCallExpression mce = unsupportedQuery.Expression as MethodCallExpression;
            Assert.IsNotNull(mce,
                "The first unsupported expression should be a method call.");
            Assert.AreEqual("ThenBy", mce.Method.Name,
                "The first unsupported expression should be a ThenBy call.");
            Assert.AreEqual(2, mce.Arguments.Count,
                "The first unsupported expression should have 2 arguments.");

            MethodCallExpression mce2 = mce.Arguments[0] as MethodCallExpression;
            Assert.IsNotNull(mce2,
                "The second unsupported expression should be a method call.");
            Assert.AreEqual("OrderBy", mce2.Method.Name,
                "The second unsupported expression should be an OrderBy call.");
            Assert.AreEqual(2, mce2.Arguments.Count,
                "The second unsupported expression should have 2 arguments.");

            ConstantExpression ce = mce2.Arguments[0] as ConstantExpression;
            Assert.IsNotNull(ce,
                "The first argument in the second unsupported expression should be constant.");
        }
Esempio n. 19
0
        public void Sort_WithLabels()
        {
            var random = new[]
            {
                "1.0.0-beta.11",
                "1.0.0-alpha.beta",
                "1.0.0-alpha.1",
                "1.0.0-rc.1",
                "1.0.0-alpha",
                "1.0.0-beta.2",
                "1.0.0-beta",
                "1.0.0",
            }.Select(SemanticVersion.Parse);

            var exptected = new[]
            {
                "1.0.0-alpha",
                "1.0.0-alpha.1",
                "1.0.0-alpha.beta",
                "1.0.0-beta",
                "1.0.0-beta.2",
                "1.0.0-beta.11",
                "1.0.0-rc.1",
                "1.0.0",
            }.Select(SemanticVersion.Parse).ToList();

            var sorted = random.OrderBy(sv => sv).ToList();
            CollectionAssert.AreEqual(exptected, sorted);

        }
Esempio n. 20
0
        public void TestThenByComparerPreserved()
        {
            var sequence = new[]
                               {
                                   new {A = "2", B = "0"},
                                   new {A = "1", B = "5"},
                                   new {A = "2", B = "2"},
                                   new {A = "1", B = "3"},
                                   new {A = "1", B = "4"},
                                   new {A = "2", B = "1"},
                               };

            var comparer = new ComparerFunc<string>((a, b) => int.Parse(a).CompareTo(int.Parse(b)));

            var resultA1 = sequence.OrderBy(x => x.A, comparer, OrderByDirection.Ascending)
                                     .ThenBy(y => y.B, comparer, OrderByDirection.Ascending);
            var resultA2 = sequence.OrderBy(x => x.A, comparer)
                                   .ThenBy(y => y.B, comparer);
            // ensure both produce the same order
            Assert.IsTrue(resultA1.SequenceEqual(resultA2));

            var resultB1 = sequence.OrderBy(x => x.A, comparer, OrderByDirection.Ascending)
                                     .ThenBy(y => y.B, comparer, OrderByDirection.Descending);
            var resultB2 = sequence.OrderBy(x => x.A, comparer)
                                   .ThenByDescending(y => y.B, comparer);
            // ensure both produce the same order
            Assert.IsTrue(resultB1.SequenceEqual(resultB2));
        }