当前位置: 首页>>代码示例>>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;未经允许,请勿转载。