当前位置: 首页>>代码示例>>C#>>正文


C# List.OrderBy方法代码示例

本文整理汇总了C#中NUnit.Framework.List.OrderBy方法的典型用法代码示例。如果您正苦于以下问题:C# List.OrderBy方法的具体用法?C# List.OrderBy怎么用?C# List.OrderBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NUnit.Framework.List的用法示例。


在下文中一共展示了List.OrderBy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: LinqOrderBy

        public void LinqOrderBy()
        {
            List<Movie> moreMovies = new List<Movie>();
            string sameTitle = "sameTitle";
            string sameMovieMaker = "sameMovieMaker";
            for (int i = 0; i < 10; i++)
            {
                Movie movie = Movie.GetRandomMovie();
                movie.Title = sameTitle;
                movie.MovieMaker = sameMovieMaker;
                moreMovies.Add(movie);
                _movieTable.Insert(movie).Execute();
            }

            var movieQuery = _movieTable.Where(m => m.Title == sameTitle && m.MovieMaker == sameMovieMaker);

            List<Movie> actualOrderedMovieList = movieQuery.Execute().ToList();
            List<Movie> expectedOrderedMovieList = moreMovies.OrderBy(m => m.Director).ToList();
            Assert.AreEqual(expectedOrderedMovieList.Count, actualOrderedMovieList.Count);
            for (int i = 0; i < expectedOrderedMovieList.Count; i++)
            {
                Assert.AreEqual(expectedOrderedMovieList[i].Director, actualOrderedMovieList[i].Director);
                Assert.AreEqual(expectedOrderedMovieList[i].MainActor, actualOrderedMovieList[i].MainActor);
                Assert.AreEqual(expectedOrderedMovieList[i].MovieMaker, actualOrderedMovieList[i].MovieMaker);
            }
        }
开发者ID:Virus-X,项目名称:csharp-driver,代码行数:26,代码来源:OrderBy.cs

示例2: FindReferences

		AstNode[] FindReferences(IEntity entity)
		{
			var result = new List<AstNode>();
			var searchScopes = findReferences.GetSearchScopes(entity);
			findReferences.FindReferencesInFile(searchScopes, parsedFile, compilationUnit, compilation,
			                                    (node, rr) => result.Add(node), CancellationToken.None);
			return result.OrderBy(n => n.StartLocation).ToArray();
		}
开发者ID:KAW0,项目名称:Alter-Native,代码行数:8,代码来源:FindReferencesTest.cs

示例3: FindReferences

		AstNode[] FindReferences(INamespace ns)
		{
			var result = new List<AstNode>();
			var searchScopes = findReferences.GetSearchScopes(ns);
			findReferences.FindReferencesInFile(searchScopes, unresolvedFile, syntaxTree, compilation,
			                                    (node, rr) => result.Add(node), CancellationToken.None);
			return result.OrderBy(n => n.StartLocation).ToArray();
		}
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:8,代码来源:FindReferencesTest.cs

示例4: Generate_country_enum

        public void Generate_country_enum()
        {
            const string code = @"//This file was automatically generated by {0} on {1}
            //Don't modify this file directory, instead edit the code that generated this file

            using System.ComponentModel;
            using Portoa.Util;

            namespace Portoa.Globalization {{
            // ReSharper disable InconsistentNaming
            ///<summary>Auto-generated enumeration of every country supported by <see cref=""System.Globalization.CultureInfo""/></summary>
            public enum Country {{
            ///<summary>Country is unknown or not applicable</summary>
            [Description(""N/A"")]
            Unknown = int.MinValue,
            {2}
            }}
            // ReSharper restore InconsistentNaming

            public static class CountryExtensions {{
            /// <summary> Gets the human-readable display name for a <see cref=""Country""/> </summary>
            public static string GetDisplayName(this Country country) {{
            return country.GetAttributes<DescriptionAttribute>()[0].Description;
            }}
            }}
            }}";

            var cultures = CultureInfo.GetCultures(CultureTypes.SpecificCultures);
            var regions = new List<RegionInfo>();
            foreach (var region in cultures.Select(culture => new RegionInfo(culture.LCID)).Where(region => !regions.Contains(region))) {
                regions.Add(region);
            }

            var valuesCode = new StringBuilder(1000);
            var invalidCharRegex = new Regex(@"\W");
            foreach (var region in regions.OrderBy(region => region.EnglishName)) {
                valuesCode.Append(string.Format("\t\t///<summary>The country {0}</summary>{1}", region.EnglishName, Environment.NewLine));
                var name = region
                    .EnglishName
                    .Split(' ')
                    .Aggregate(string.Empty, (current, word) => current + (word[0].ToString().ToUpperInvariant() + word.Substring(1)));

                var validName = invalidCharRegex.Replace(name, "");

                valuesCode.Append(string.Format("\t\t[Description(\"{0}\")]{1}", region.EnglishName, Environment.NewLine));
                valuesCode.Append(string.Format("\t\t{0} = {1},{2}", validName, region.GeoId, Environment.NewLine));
            }

            const string path = @"c:\users\tmont\code\Portoa\Src\Portoa\Globalization\Country.cs";
            using (var stream = File.Open(path, FileMode.OpenOrCreate, FileAccess.Write)) {
                stream.SetLength(0);
                using (var writer = new StreamWriter(stream)) {
                    writer.Write(string.Format(code, GetType().FullName + ".Generate_country_enum()", DateTime.Now, valuesCode));
                }
            }
        }
开发者ID:tmont,项目名称:portoa,代码行数:56,代码来源:DataGenerator.cs

示例5: AreEqual

 public static void AreEqual(List<LoggedData> loggedDatas, List<TSK> tsks, Catalog catalog, string cardPath)
 {
     tsks = tsks.OrderBy(x => x.A).ToList();
     for (int i = 0; i < loggedDatas.Count; i++)
     {
         var loggedData = loggedDatas[i];
         var matchingTask = tsks[tsks.Count - loggedDatas.Count + i];
         AreEqual(loggedData, matchingTask, catalog, cardPath);
     }
 }
开发者ID:ADAPT,项目名称:ISOv4Plugin,代码行数:10,代码来源:TskAssert.cs

示例6: SubscriptionsWorkLikeExpectedWhenRabbitManagesThem

        public void SubscriptionsWorkLikeExpectedWhenRabbitManagesThem()
        {
            // arrange
            DeleteQueue("test.rabbitsub.publisher");
            DeleteQueue("test.rabbitsub.sub1");
            DeleteQueue("test.rabbitsub.sub2");
            DeleteQueue("test.rabbitsub.sub3");

            var publisher = PullOneOutOfTheHat("test.rabbitsub.publisher");

            var receivedSub1 = new List<int>();
            var receivedSub2 = new List<int>();
            var receivedSub3 = new List<int>();

            var sub1 = PullOneOutOfTheHat("test.rabbitsub.sub1", receivedSub1.Add);
            var sub2 = PullOneOutOfTheHat("test.rabbitsub.sub2", receivedSub2.Add);
            var sub3 = PullOneOutOfTheHat("test.rabbitsub.sub3", receivedSub3.Add);

            // act
            publisher.Publish(new SomeEvent { Number = 1 });

            Thread.Sleep(200.Milliseconds());

            sub1.Subscribe<SomeEvent>();
            Thread.Sleep(200.Milliseconds());
            publisher.Publish(new SomeEvent { Number = 2 });

            sub2.Subscribe<SomeEvent>();
            Thread.Sleep(200.Milliseconds());
            publisher.Publish(new SomeEvent { Number = 3 });

            sub3.Subscribe<SomeEvent>();
            Thread.Sleep(200.Milliseconds());
            publisher.Publish(new SomeEvent { Number = 4 });

            Thread.Sleep(200.Milliseconds());

            sub3.Unsubscribe<SomeEvent>();
            Thread.Sleep(200.Milliseconds());
            publisher.Publish(new SomeEvent { Number = 5 });

            sub2.Unsubscribe<SomeEvent>();
            Thread.Sleep(200.Milliseconds());
            publisher.Publish(new SomeEvent { Number = 6 });

            sub1.Unsubscribe<SomeEvent>();
            Thread.Sleep(200.Milliseconds());
            publisher.Publish(new SomeEvent { Number = 7 });

            // assert
            receivedSub1.OrderBy(i => i).ToArray().ShouldBe(new[] { 2, 3, 4, 5, 6 });
            receivedSub2.OrderBy(i => i).ToArray().ShouldBe(new[] { 3, 4, 5 });
            receivedSub3.OrderBy(i => i).ToArray().ShouldBe(new[] { 4 });
        }
开发者ID:plillevold,项目名称:Rebus,代码行数:54,代码来源:TestRabbitSubscriptions.cs

示例7: PrefixesShouldBeSortedCorrectly

        public void PrefixesShouldBeSortedCorrectly()
        {
            var usortedPrefixesList = new List<Prefix>
            {
                Prefix.Kb, Prefix.Mb, Prefix.Gb, Prefix.Gb, Prefix.Kb, Prefix.Tb, Prefix.Gb, Prefix.Mb,Prefix.Tb, Prefix.Gb, Prefix.Mb, Prefix.Kb
            };

            usortedPrefixesList.OrderBy(it => it).Should().BeInAscendingOrder();

            usortedPrefixesList.OrderByDescending(it => it).Should().BeInDescendingOrder();
        }
开发者ID:klym1,项目名称:Toloka-Archive,代码行数:11,代码来源:TestPrefixClass.cs

示例8: GivenRegistryWithMultiplePipes_WhenResolvingFromAToD_ItShouldChainAllThePipes

        public async Task GivenRegistryWithMultiplePipes_WhenResolvingFromAToD_ItShouldChainAllThePipes()
        {
            for (int counter = 0; counter < 15; counter++)
            {
                // pre-arrange
                var instanceClassA = new TestClassA();
                var instanceClassB = new TestClassB();
                var instanceClassC = new TestClassC();
                var instanceClassD = new TestClassD();

                // arrange
                var semanticBuilder = new SemanticBuilder();

                var enrollmentList = new List<Action>
                {
                    () => semanticBuilder.InstallPipe<TestClassA, TestClassB>((a, innerBroker) =>
                    {
                        Assert.AreSame(instanceClassA, a);
                        return instanceClassB;
                    }),
                    () => semanticBuilder.InstallPipe<TestClassB, TestClassC>((b, innerBroker) =>
                    {
                        Assert.AreSame(instanceClassB, b);
                        return instanceClassC;
                    }),
                    () => semanticBuilder.InstallPipe<TestClassC, TestClassD>((c, innerBroker) =>
                    {
                        Assert.AreSame(instanceClassC, c);
                        return instanceClassD;
                    }),
                };

                var enrollmentActions = enrollmentList.OrderBy(x=>Guid.NewGuid());
                foreach (var enrollmentAction in enrollmentActions)
                {
                    enrollmentAction();
                }

                ISemanticBroker broker = semanticBuilder.CreateBroker();

                // act
                var solvedExecution = await broker.On(instanceClassA).Output<TestClassD>();

                // assert
                Assert.AreEqual(instanceClassD, solvedExecution);
            }
        }
开发者ID:justin-lovell,项目名称:semantic-pipes,代码行数:47,代码来源:Feature_Chaining_Tests.cs

示例9: IgnoresQuotes

        public void IgnoresQuotes()
        {
            var unorderedList = new List<string> {
                "ZZZ",
                "\"AAA",
                "ABC",
                "DDD",
                "\"CCC"
            };

            var orderedList = unorderedList.OrderBy(c => c, new PolicyHolderComparer());

            Assert.AreEqual("\"AAA", orderedList.ElementAt(0));
            Assert.AreEqual("ABC", orderedList.ElementAt(1));
            Assert.AreEqual("\"CCC", orderedList.ElementAt(2));
            Assert.AreEqual("ZZZ", orderedList.Last());
        }
开发者ID:apalumbi,项目名称:Vista,代码行数:17,代码来源:PolicyHolderComparerTest.cs

示例10: MatchingCustomers_PostcodeSameAsSomeCustomers_MatchesCorrectCustomers

        public void MatchingCustomers_PostcodeSameAsSomeCustomers_MatchesCorrectCustomers()
        {
            List<ICustomerVM> famousCustomers = CreateFamousCustomerVMs();
            var customersToMatch = new List<ICustomerVM>();

            for (int i = 0; i < famousCustomers.Count; i++) {
                ICustomerVM customer = famousCustomers[i];
                if (i%2 != 0) continue;

                GiveAddressWithPostcode(customer, TestPostcode);
                customersToMatch.Add(customer);
            }
            sessionData.CustomersToReturn = famousCustomers;
            FindCustomerVM viewModel = CreateViewModel(TestPostcode);

            var expected = new List<ICustomerVM>(customersToMatch.OrderBy(cust => cust.FirstName));
            AssertAreEqual(expected, viewModel.MatchingCustomers.ToList());
        }
开发者ID:JWroe,项目名称:ScrapTraders,代码行数:18,代码来源:FindCustomerVMTests.cs

示例11: EnumerateFromKeys

        public void EnumerateFromKeys()
        {
            string path = Path.GetFullPath ("TestData\\EnumerateFromKeys");
            if (!Directory.Exists (path)) Directory.CreateDirectory (path);

            List<KeyValuePair<Key, Value>> items = new List<KeyValuePair<Key, Value>> ();

            int num_items = 10000;
            var mt = new MemTable ();
            for (int i = 0; i < num_items; i++) {
                var k0 = Key.Random (40);
                var v0 = Value.Random (200);
                mt.Add (k0, v0);

                items.Add (new KeyValuePair<Key, Value> (k0, v0));
            }

            mt.WriteToSortedBlockTable ("TestData\\EnumerateFromKeys", 10, 10);

            var cache = new RazorCache ();
            var sbt = new SortedBlockTable (cache, "TestData\\EnumerateFromKeys", 10, 10);

            try {
                var indexCache = new RazorCache ();

                var timer = new Stopwatch ();
                timer.Start ();
                Assert.AreEqual (10000, sbt.EnumerateFromKey (indexCache, new Key (new byte[] { 0 }, 0)).Count ());
                timer.Stop ();
                Console.WriteLine ("Counted from beginning at a throughput of {0} MB/s", (double)mt.Size / timer.Elapsed.TotalSeconds / (1024.0 * 1024.0));

                items = items.OrderBy ((a) => a.Key).ToList ();

                timer.Reset ();
                timer.Start ();
                Assert.AreEqual (5000, sbt.EnumerateFromKey (indexCache, items [5000].Key).Count ());
                timer.Stop ();
                Console.WriteLine ("Counted from halfway at a throughput of {0} MB/s", (double)mt.Size / 2 / timer.Elapsed.TotalSeconds / (1024.0 * 1024.0));

                Assert.AreEqual (0, sbt.EnumerateFromKey (indexCache, new Key (new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, 0xFF)).Count ());
            } finally {
                sbt.Close ();
            }
        }
开发者ID:T145,项目名称:razordbx,代码行数:44,代码来源:SortedBlockTableTests.cs

示例12: WorstCaseScenario_Should_ReturnAnswerInResonableTime

        public void WorstCaseScenario_Should_ReturnAnswerInResonableTime()
        {
            // Arrange
            const int testSize = 1000;
            Solver solver = new Solver();
            Random rand = new Random();
            List<string> input = new List<string>(testSize);
            StringBuilder expected = new StringBuilder("0 ");
            for (int i = 0; i < testSize - 1; i++)
            {
                input.Add(String.Format("{0} {1}", i, i + 1));
                for (int j = i + 2; j < testSize - 2; j++)
                {
                    input.Add(String.Format("{0} {1}", i, j));
                }

                expected.Append(i + 1).Append(" ");
            }
            StringBuilder sb = new StringBuilder().AppendFormat("{0} {1}\n", testSize, input.Count);
            foreach (var experiment in input.OrderBy(d => rand.Next()))
            {
                sb.AppendLine(experiment);
            }
            string expectedResult = expected.ToString().TrimEnd() + "\r\n";

            // Act
            using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(sb.ToString())))
            using (var outMs = new MemoryStream())
            {
                Stopwatch sw = new Stopwatch();
                sw.Start();
                solver.Solve(ms, outMs);
                sw.Stop();
                Debug.WriteLine("Solved in {0}", sw.Elapsed);
                outMs.Position = 0;
                var result = new StreamReader(outMs).ReadToEnd();

                // Assert
                Assert.That(result, Is.EqualTo(expectedResult));
            }
        }
开发者ID:karpikpl,项目名称:reactivitySeriesCS,代码行数:41,代码来源:WorstCaseScenarioTests.cs

示例13: CalculateSmallestNumber

        public void CalculateSmallestNumber(string str, int n)
        {
            char[] mychar = str.ToCharArray();
            var smallest = mychar.FirstOrDefault();
            var list = new List<ComplexLetter>();

            var maxTrim = str.Length - n;

            while (list.Count < maxTrim)
            {
                StringBuilder stringBuilder = new StringBuilder(str);
                var traverseString = TraverseString(str, smallest);
                list.Add(traverseString);
                stringBuilder[traverseString.Position] = ' ';
                str = stringBuilder.ToString().Replace(" ", string.Empty);
                smallest = str.ToCharArray().FirstOrDefault();
            }

            Console.WriteLine();

            var orderedEnumerable = list.OrderBy(letter => letter.Position);
            orderedEnumerable.Each(letter => Console.WriteLine(letter.Letter + " " + letter.Position));
        }
开发者ID:Foxpips,项目名称:ProgrammingCSharp,代码行数:23,代码来源:SmallestNumberTests.cs

示例14: PagingTest

        public void PagingTest()
        {
            CreateTestData();
              var repository = Locator.GetInstance<IRepository<Product>>();

              var allItems = new List<Product>();

              var query = repository.CreateQuery<IPagedProductSearch>();
              query.Sort = PagedProductSearchSort.PriceAsc;
              query.ItemsPerPage = 2;
              query.PageNumber = 1;
              var actual = query.Execute();
              Assert.AreEqual(5, actual.TotalItems);
              Assert.AreEqual(2, actual.PageOfResults.Count());
              allItems.AddRange(actual.PageOfResults);

              query = repository.CreateQuery<IPagedProductSearch>();
              query.Sort = PagedProductSearchSort.PriceAsc;
              query.ItemsPerPage = 2;
              query.PageNumber = 2;
              actual = query.Execute();
              Assert.AreEqual(5, actual.TotalItems);
              Assert.AreEqual(2, actual.PageOfResults.Count());
              allItems.AddRange(actual.PageOfResults);

              query = repository.CreateQuery<IPagedProductSearch>();
              query.Sort = PagedProductSearchSort.PriceAsc;
              query.ItemsPerPage = 2;
              query.PageNumber = 3;
              actual = query.Execute();
              Assert.AreEqual(5, actual.TotalItems);
              Assert.AreEqual(1, actual.PageOfResults.Count());
              allItems.AddRange(actual.PageOfResults);

              Assert.True(allItems.SequenceEqual(
            allItems.OrderBy(p => p.UnitPrice)));
        }
开发者ID:akhuang,项目名称:NHibernate,代码行数:37,代码来源:PagedProductSearchTests.cs

示例15: withCategories

        public void withCategories(params string[] categories)
        {
            var actualCategories = new List<string>();

            var categoriesXml = _xml.Elements("categories");

            if (categoriesXml != null)
            {
                foreach(var category in categoriesXml.Elements("category").Select(c => c.Attribute("name").Value))
                {
                    actualCategories.Add(category);
                }
            }

            categories = categories.OrderBy(c => c).ToArray();
            actualCategories = actualCategories.OrderBy(c => c).ToList();

            Assert.That(categories, Is.EquivalentTo(actualCategories),
                String.Format("Expected {0} named {1} to have categories {2}, actually had {3}",
                    _typeName,
                    _name,
                    string.Join(",", categories),
                    string.Join(",", actualCategories)));
        }
开发者ID:guyzo,项目名称:DreamNJasmine,代码行数:24,代码来源:BaseResult.cs


注:本文中的NUnit.Framework.List.OrderBy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。