當前位置: 首頁>>代碼示例>>C#>>正文


C# List.Each方法代碼示例

本文整理匯總了C#中NUnit.Framework.List.Each方法的典型用法代碼示例。如果您正苦於以下問題:C# List.Each方法的具體用法?C# List.Each怎麽用?C# List.Each使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在NUnit.Framework.List的用法示例。


在下文中一共展示了List.Each方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Can_report_progress_when_downloading_async

        public async Task Can_report_progress_when_downloading_async()
        {
            var hold = AsyncServiceClient.BufferSize;
            AsyncServiceClient.BufferSize = 100;

            try
            {
                var asyncClient = new JsonServiceClient(ListeningOn);

                var progress = new List<string>();

                //Note: total = -1 when 'Transfer-Encoding: chunked'
                //Available in ASP.NET or in HttpListener when downloading responses with known lengths: 
                //E.g: Strings, Files, etc.
                asyncClient.OnDownloadProgress = (done, total) =>
                    progress.Add("{0}/{1} bytes downloaded".Fmt(done, total));

                var response = await asyncClient.GetAsync(new TestProgress());

                progress.Each(x => x.Print());

                Assert.That(response.Length, Is.GreaterThan(0));
                Assert.That(progress.Count, Is.GreaterThan(0));
                Assert.That(progress.First(), Is.EqualTo("100/1160 bytes downloaded"));
                Assert.That(progress.Last(), Is.EqualTo("1160/1160 bytes downloaded"));
            }
            finally
            {
                AsyncServiceClient.BufferSize = hold;
            }
        }         
開發者ID:tystol,項目名稱:ServiceStack,代碼行數:31,代碼來源:AsyncProgressTests.cs

示例2: BasicTester

        public BasicTester()
        {
            _hostRoot = Path.Combine(Directory.GetCurrentDirectory(), "Templates");
            _pak1 = Path.Combine(_hostRoot, "Pak1");
            _pak2 = Path.Combine(_hostRoot, "Pak2");

            _hostHomeView = new Template(Path.Combine(_hostRoot, "Home", "Home.spark"), _hostRoot, TemplateConstants.HostOrigin);
            _hostApplicationView = new Template(Path.Combine(_hostRoot, "Shared", "application.spark"), _hostRoot, TemplateConstants.HostOrigin);
            _hostFooterPartialView = new Template(Path.Combine(_hostRoot, "Shared", "_footer.spark"), _hostRoot, TemplateConstants.HostOrigin);

            _pak1HomeView = new Template(Path.Combine(_pak1, "Home", "Home.spark"), _hostRoot, "Pak1");
            _pak1NamePartialView = new Template(Path.Combine(_pak1, "Home", "_name.spark"), _hostRoot, "Pak1");

            _pak2HomeView = new Template(Path.Combine(_pak2, "Home", "Home.spark"), _hostRoot, "Pak2");
            _pak2ApplicationView = new Template(Path.Combine(_pak2, "Shared", "application.spark"), _hostRoot, "Pak2");
            _pak2ThemeView = new Template(Path.Combine(_pak2, "Shared", "theme.spark"), _hostRoot, "Pak2");

            var templates = new List<ITemplate>
            {
                _hostHomeView, _hostApplicationView, _hostFooterPartialView,
                _pak1HomeView, _pak1NamePartialView,
                _pak2HomeView, _pak2ApplicationView, _pak2ThemeView
            };

            var viewPathPolicy = new ViewPathPolicy<ITemplate>();
            templates.Each(viewPathPolicy.Apply);

            _viewFolder = new TemplateViewFolder(new TemplateRegistry<ITemplate>(templates));
        }
開發者ID:mtscout6,項目名稱:FubuMVC.ViewEngines,代碼行數:29,代碼來源:BasicTester.cs

示例3: Method_Scenario_Result

        public void Method_Scenario_Result()
        {
            var list = new List<string> {"Simon", "Andrew"};
            list.SortSelf().Each(Console.WriteLine);

            list.Each(Console.WriteLine);
        }
開發者ID:Foxpips,項目名稱:ProgrammingCSharp,代碼行數:7,代碼來源:SortSelfTests.cs

示例4: invoke_action_on_each_enumerable_value

 public void invoke_action_on_each_enumerable_value()
 {
     IList<int> list = new List<int>{42,42};
     var result = new int[2];
     list.Each((item, index) => result[index] = item * index);
     result[0].ShouldEqual(0);
     result[1].ShouldEqual(42);
 }
開發者ID:bobpace,項目名稱:fubucore,代碼行數:8,代碼來源:GenericEnumerableExtensionsTester.cs

示例5: can_perform_action_on_each

        public void can_perform_action_on_each()
        {
            var assembly = System.Reflection.Assembly.GetAssembly(typeof (EnumerableSpecs));
            assembly.GetTypes().Each(t=>t.GetFields().Each(Console.WriteLine));

            var myString = String.Empty;
            "abcd".Each(a=>myString+=a);
            myString.ShouldEqual("abcd");
            var ints = new List<int> {1, 2, 3};
            ints.Each(Console.WriteLine);
        }
開發者ID:ignu,項目名稱:ruebee,代碼行數:11,代碼來源:EnumerableSpecs.cs

示例6: verifyRoutes

        private void verifyRoutes(BehaviorGraph graph)
        {
            var routes = new List<string>
                             {
                                 "posts/create",
                                 "posts/complex-route",
                                 //"posts/sub/route", <-- I can't see how this route would ever have worked looking at the structure??
                                 "some-crazy-url/as-a-subfolder",
                                 "posts/{Year}/{Month}/{Title}"
                             };

            routes.Each(route => graph.Routes.ShouldContain(r => r.Pattern.Equals(route)));
        }
開發者ID:RobertTheGrey,項目名稱:FubuMVC.HandlerConventions,代碼行數:13,代碼來源:HandlersConventionTester.cs

示例7: ToCapitalCase

        public void ToCapitalCase()
        {
            var titlePairs = new List<Pair<string, string>>
            { // example words taken from Ruby on Rails inflector.rb
                new Pair<string, string> { First = "man from the boondocks", Second = "Man from the boondocks" },
                new Pair<string, string> { First = "x-men: the last stand", Second = "X-men: the last stand" }
            };

            titlePairs.Each(pair =>
            {
                Log.Info("{0} -> {1} = {2}?", pair.First, pair.First.ToCapitalCase(), pair.Second);
                Assert.That(pair.First.ToCapitalCase(), Is.EqualTo(pair.Second));
            });
        }
開發者ID:yukiyume,項目名稱:YukiYume,代碼行數:14,代碼來源:StringExtensionsFixture.cs

示例8: verifyRoutes

        private void verifyRoutes(BehaviorGraph graph)
        {
            var routes = new List<string>
                             {
                                 "posts/create",
                                 "posts/complex-route",
                                 "some-crazy-url/as-a-subfolder",
                                 "posts/{Year}/{Month}/{Title}"
                             };

            routes
                .Each(route => graph
                                   .Routes
                                   .ShouldContain(r => r.Pattern.Equals(route)));
        }
開發者ID:jemacom,項目名稱:fubumvc,代碼行數:15,代碼來源:HandlersConventionTester.cs

示例9: should_include_handlers

        public void should_include_handlers()
        {
            var graph = new FubuRegistry(x => x.ApplyHandlerConventions(typeof (Handlers.HandlersMarker))).BuildGraph();
            var routes = new List<string>
                             {
                                 "posts/create",
                                 "posts/complex-route",
                                 "some-crazy-url/as-a-subfolder",
                                 "posts/{Year}/{Month}/{Title}"
                             };

            routes
                .Each(route => graph
                                   .Routes
                                   .ShouldContain(r => r.Pattern.Equals(route)));
        }
開發者ID:davidalpert,項目名稱:FubuMVC.Conventions,代碼行數:16,代碼來源:FubuExtensionsTester.cs

示例10: Can_hijack_all_Insert_Apis

        public void Can_hijack_all_Insert_Apis()
        {
            //Most INSERT Statements return void. To check each Insert uses the results filter (i.e. instead of the db)
            //we count the number of sql statements generated instead.

            var sqlStatements = new List<string>();
            var sqlCommandStatements = new List<SqlCommandDetails>();
            using (new OrmLiteResultsFilter
            {
                SqlFilter = sql => sqlStatements.Add(sql),
                SqlCommandFilter = sql => sqlCommandStatements.Add(new SqlCommandDetails(sql)),
            })
            {
                int i = 0;

                i++; db.Insert(new Person { Id = 7, FirstName = "Amy", LastName = "Winehouse", Age = 27 });
                Assert.That(sqlStatements.Count, Is.EqualTo(i));
                Assert.That(sqlCommandStatements.Count, Is.EqualTo(i));


                i++; db.InsertAll(new[] { new Person { Id = 10, FirstName = "Biggie", LastName = "Smalls", Age = 24 } });
                Assert.That(sqlStatements.Count, Is.EqualTo(i));
                Assert.That(sqlCommandStatements.Count, Is.EqualTo(i));

                i++; db.InsertOnly(new PersonWithAutoId { FirstName = "Amy", Age = 27 }, ev => ev.Insert(p => new { p.FirstName, p.Age }));
                Assert.That(sqlStatements.Count, Is.EqualTo(i));
                Assert.That(sqlCommandStatements.Count, Is.EqualTo(i));

                i++; db.InsertOnly(new PersonWithAutoId { FirstName = "Amy", Age = 27 }, ev => db.From<PersonWithAutoId>().Insert(p => new { p.FirstName, p.Age }));
                Assert.That(sqlStatements.Count, Is.EqualTo(i));
                Assert.That(sqlCommandStatements.Count, Is.EqualTo(i));

                sqlStatements.Each(x => x.Print());
                sqlCommandStatements.Each(x => x.PrintDump());

            }
        }
開發者ID:wrx362114,項目名稱:ServiceStack.OrmLite,代碼行數:37,代碼來源:MockAllApiTests.cs

示例11: Can_trace_all_generated_sql

        public void Can_trace_all_generated_sql()
        {
            var sqlStatements = new List<string>();
            var sqlCommandStatements = new List<SqlCommandDetails>();
            using (new OrmLiteResultsFilter
            {
                SqlFilter = sql => sqlStatements.Add(sql),
                SqlCommandFilter = sql => sqlCommandStatements.Add(new SqlCommandDetails(sql)),
                ResultsFn = (dbCmd, type) => new[] { new Person { Id = 1, FirstName = "Mocked", LastName = "Person", Age = 100 } },
                SingleResultFn = (dbCmd, type) => new Person { Id = 1, FirstName = "MockedSingle", LastName = "Person", Age = 100 },
                ScalarResultFn = (dbCmd, type) => 1000,
            })
            {
                Assert.That(db.Select<Person>(x => x.Age > 40)[0].FirstName, Is.EqualTo("Mocked"));

                Assert.That(db.Single<Person>(x => x.Age == 42).FirstName, Is.EqualTo("MockedSingle"));

                Assert.That(db.Scalar<Person, int>(x => Sql.Max(x.Age)), Is.EqualTo(1000));
                
                Assert.That(sqlStatements.Count, Is.EqualTo(3));
                Assert.That(sqlCommandStatements.Count, Is.EqualTo(3));

                sqlStatements.Each(x => x.Print());
                sqlCommandStatements.Each(x => x.PrintDump());
            }
        }
開發者ID:wrx362114,項目名稱:ServiceStack.OrmLite,代碼行數:26,代碼來源:MockAllApiTests.cs

示例12: Can_hijack_References_Apis

        public void Can_hijack_References_Apis()
        {
            var customer = new Customer
            {
                Id = 1,
                Name = "Customer 1",
                PrimaryAddress = new CustomerAddress
                {
                    AddressLine1 = "1 Humpty Street",
                    City = "Humpty Doo",
                    State = "Northern Territory",
                    Country = "Australia"
                },
                Orders = new[] { 
                    new Order { LineItem = "Line 1", Qty = 1, Cost = 1.99m },
                    new Order { LineItem = "Line 2", Qty = 2, Cost = 2.99m },
                }.ToList(),
            };

            var sqlStatements = new List<string>();
            using (new ResultsFilter
                {
                    SqlFilter = sql => sqlStatements.Add(sql),
                    SingleResult = customer,
                    RefSingleResultFn = (dbCmd, refType) => customer.PrimaryAddress,
                    RefResultsFn = (dbCmd, refType) => customer.Orders,
                })
            {
                int i = 0;

                i += 2; db.Save(customer);
                Assert.That(sqlStatements.Count, Is.EqualTo(i));

                i += 1; db.SaveReferences(customer, customer.PrimaryAddress);
                Assert.That(sqlStatements.Count, Is.EqualTo(i));

                i += 2; db.SaveReferences(customer, customer.Orders);
                Assert.That(sqlStatements.Count, Is.EqualTo(i));

                i += 3; var dbCustomer = db.LoadSingleById<Customer>(customer.Id);
                Assert.That(sqlStatements.Count, Is.EqualTo(i));

                sqlStatements.Each(x => x.Print());
            }
        }
開發者ID:jchannon,項目名稱:ServiceStack.OrmLite,代碼行數:45,代碼來源:MockAllApiTests.cs

示例13: Should_render_the_view_and_have_valid_data_when_Valid_Slug_is_passed_in

        public void Should_render_the_view_and_have_valid_data_when_Valid_Slug_is_passed_in()
        {
            var testSlug = "My-Test-Slug";
            var id = Guid.NewGuid();
            var title = "My BlogPost Title";
            var bodyShort = "Body Short Text";
            var body = "This is the main body of a blogpost";
            var published = DateTime.Today;
            var modelTags = "help, test, sample, ";
            var objectTags = new List<Tag> {new Tag {Name = "help"}, new Tag {Name = "test"}, new Tag {Name = "sample"}};

            var post = new Post
                           {
                               ID = id,
                               Title = title,
                               BodyShort = bodyShort,
                               Body = body,
                               Published = published
                           };
            objectTags.Each(post.AddTag);

            var postList = new List<Post> { post }.AsQueryable();

            _repository.Expect(call => call.Query(new PostBySlug(testSlug))).IgnoreArguments().Return(postList);

            var outModel = _controller.Edit(new BlogPostEditViewModel { Slug = testSlug });

            outModel.ShouldBeOfType<BlogPostAddViewModel>();

            var actualResult = outModel as BlogPostAddViewModel;

            actualResult.ShouldNotBeNull();

            actualResult.Id.ShouldEqual(id.ToString());
            actualResult.Title.ShouldEqual(title);
            actualResult.BodyShort.ShouldEqual(bodyShort);
            actualResult.Body.ShouldEqual(body);
            actualResult.Published.ShouldEqual(published);
            actualResult.Tags.ShouldEqual(modelTags);
        }
開發者ID:Anupam-,項目名稱:fubumvc-contrib,代碼行數:40,代碼來源:BlogPostControllerTester.cs

示例14: ToOrdinal

        public void ToOrdinal()
        {
            var numbers = new List<Pair<int, string>>
            {
                new Pair<int, string> { First = 1, Second = "1st" },
                new Pair<int, string> { First = 2, Second = "2nd" },
                new Pair<int, string> { First = 1002, Second = "1002nd" },
                new Pair<int, string> { First = 1003, Second = "1003rd" },
                new Pair<int, string> { First = 10013, Second = "10013th" },
                new Pair<int, string> { First = 20026, Second = "20026th" }
            };

            numbers.Each(pair =>
            {
                Log.Info("{0} -> {1} = {2}?", pair.First, pair.First.ToOrdinal(), pair.Second);
                Assert.That(pair.First.ToOrdinal(), Is.EqualTo(pair.Second));
            });
        }
開發者ID:yukiyume,項目名稱:YukiYume,代碼行數:18,代碼來源:NumberExtensionsFixture.cs

示例15: ScanBadEscapedUnicode

        public void ScanBadEscapedUnicode()
        {
            var jsonList = new List<string> { @"""\u005X""", @"""\u00X5""", @"""\u0X05""", @"""\uX005""", @"""\u500""", @"""\u05""", @"""\u5""", @"""\u""" };

            jsonList.Each(json =>
            {
                using (var lex = new JsonLexicalAnalyzer(json))
                {
                    Assert.That(JsonLexicalType.Error == lex.Scan());
                }
            });
        }
開發者ID:yukiyume,項目名稱:YukiYume,代碼行數:12,代碼來源:JsonLexicalAnalyzerFixture.cs


注:本文中的NUnit.Framework.List.Each方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。