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


C# List.SelectMany方法代码示例

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


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

示例1: ExportProductsTest

        public void ExportProductsTest()
        {
            var searchService = GetSearchService();
            var categoryService = GetCategoryService();
            var itemService = GetItemService();
            var result = searchService.Search(new SearchCriteria { CatalogId = "Sony", CategoryId = "66b58f4c-fd62-4c17-ab3b-2fb22e82704a", Skip = 0, Take = 10, ResponseGroup = coreModel.SearchResponseGroup.WithProducts });
            var importConfiguration = GetMapConfiguration();

            using (var csvWriter = new CsvWriter(new StreamWriter(@"c:\Projects\VCF\vc-community\PLATFORM\Modules\Catalog\VirtoCommerce.CatalogModule.Test\products.csv")))
            {
                var csvProducts = new List<CsvProduct>();
                foreach (var product in result.Products)
                {
                    var fullLoadedProduct = itemService.GetById(product.Id, ItemResponseGroup.ItemLarge);
                    csvProducts.Add(new CsvProduct(fullLoadedProduct, null, null, null));
                }

                importConfiguration.PropertyCsvColumns = csvProducts.SelectMany(x => x.PropertyValues).Select(x => x.PropertyName).Distinct().ToArray();
                csvWriter.Configuration.Delimiter = ";";
                csvWriter.Configuration.RegisterClassMap(new CsvProductMap(importConfiguration));

                csvWriter.WriteHeader<CsvProduct>();
                foreach (var product in csvProducts)
                {
                    csvWriter.WriteRecord(product);
                }

            }
        }
开发者ID:adwardliu,项目名称:vc-community,代码行数:29,代码来源:ImportExportTest.cs

示例2: CheckProperlySet_OfSocialShareButton_FromControllerToModel

        public void CheckProperlySet_OfSocialShareButton_FromControllerToModel()
        {
            var socialShareOptions = new List<SocialShareGroup>
                {
                    new SocialShareGroup(new List<SocialShareOption>
                        {
                            new SocialShareOption("Facebook", true),
                            new SocialShareOption("Twitter", true),
                            new SocialShareOption("GooglePlusOne", true),
                            new SocialShareOption("LinkedIn", true),
                            new SocialShareOption("SocialShareMode", false)
                        }),
                };

            // Arrange
            using (var controller = new DummySocialShareController(socialShareOptions))
            {
                // Act
                controller.Index();

                // Assert
                Assert.IsTrue(controller.Model.SocialButtons.Count == 4);

                foreach (SocialShareOption option in socialShareOptions.SelectMany(s => s.Groups))
                {
                    var button = controller.Model.SocialButtons.FirstOrDefault(b => b.ButtonName == option.Key);

                    if (!option.IsChecked)
                    {
                        Assert.IsNull(button);
                    }
                    else
                    {
                        Assert.IsNotNull(button);
                    }
                }
            }
        }
开发者ID:rhullah,项目名称:feather-widgets,代码行数:38,代码来源:SocialShareControllerTests.cs

示例3: MyTest

            public void MyTest()
            {
                var l = new int[] { 0, 1, 2, 3, 4, 5, 6 };
                var result = new List<int[]>();

                var numberOfChunks = (int)Math.Ceiling((double)l.Length / TweetinviConsts.UPLOAD_MAX_CHUNK_SIZE);

                for (int i = 0; i < numberOfChunks; ++i)
                {
                    var elts = l.Skip(i * TweetinviConsts.UPLOAD_MAX_CHUNK_SIZE).Take(Math.Min((i + 1) * TweetinviConsts.UPLOAD_MAX_CHUNK_SIZE, l.Length)).ToArray();
                    result.Add(elts);
                }

                var all = result.SelectMany(x => x).ToArray();

                Assert.AreEqual(l.Length, all.Length);
            }
开发者ID:SowaLabs,项目名称:TweetinviNew,代码行数:17,代码来源:StringExtensionsTests.cs

示例4: GetAllColorPermutations

        private IEnumerable<IList<Color>> GetAllColorPermutations()
        {
            var colors = new List<Color>() {
                Color.NotSet,
                Color.Blue,
                Color.Black,
                Color.Red,
                Color.White,
                Color.Yellow
            }
                .Select(c => new List<Color>() { c });

            return colors
                .SelectMany(li => this.GetNextLayer(li))
                .SelectMany(li => this.GetNextLayer(li))
                .SelectMany(li => this.GetNextLayer(li))
                .SelectMany(li => this.GetNextLayer(li))
                .SelectMany(li => this.GetNextLayer(li))
                .Where(li => li.Count(c => c != Color.NotSet) > 2);
        }
开发者ID:goosefraba19,项目名称:ktane-abe,代码行数:20,代码来源:WiresSolverTests.cs

示例5: TestJoinLists

        public void TestJoinLists()
        {
            // Create a new list of apps
            var apps = new List<EmailApplication>() {
                new EmailApplication() {Id = 1, CustomerId = 1, IPAccessRestrictions = "123.43.56.2"},
                new EmailApplication() {Id = 2, CustomerId = 1, IPAccessRestrictions = "123.43.56.36"},
                new EmailApplication() {Id = 3, CustomerId = 1},
                new EmailApplication() {Id = 4, CustomerId = 2},
                new EmailApplication() {Id = 5, CustomerId = 3, IPAccessRestrictions = "123.43.45.1"}
            };

            var customers = new List<Customer>();

            foreach (var customer in m_repository.GetSortedCustomers())
            {
//                customer.Applications = apps.Where(a => a.CustomerId == customer.Id).ToList();
                customers.Add(customer);
            }

            // Join customers to applications (with filter to those with IP restrictions)
            var joinQuery = customers.Join(apps,
                c => c.Id,
                a => a.CustomerId,
                (c, a) => new
                    {
                        Name = c.LastName + ", " + c.FirstName,
                        IpRestrictions = a.IPAccessRestrictions
                    }).Where(w => !String.IsNullOrEmpty(w.IpRestrictions));

            foreach (var item in joinQuery)
            {
                Debug.WriteLine(item.Name.ToString() + " : " + item.IpRestrictions);
            }

            // Try to get customers with IP access restrictions
            var manyQuery = customers
                .Select(c => c.Applications
                    .Where(a => !String.IsNullOrEmpty(a.IPAccessRestrictions)));

            foreach (var item in manyQuery)
            {
                Debug.WriteLine(item.ToString());
            }

            // The above query is an enumerable of an enumerable, which ain't great
            // Using SelectMany will flatten a parent/child relationship and allow projection on either
            var customersWithIpRestrictions = customers
                    .SelectMany(c => c.Applications
                    .Where(a => !String.IsNullOrEmpty(a.IPAccessRestrictions)),
                    // project to customer
                    (c, a) => c)
                    .Distinct();

            foreach (var item in customersWithIpRestrictions)
            {
                Debug.WriteLine(item.LastName + ", " + item.FirstName);
            }

            Debug.WriteLine(customers.Sum(c => 1));

            var groupBy = apps.GroupBy(a => a.CustomerId,
                         a => a.Id,
                         (key, id) => new
                         {
                             ClientId = key,
                             NumApps = id.Sum(a => 1),
                             MeanApps = id.Sum() / id.Sum(a => 1),
                             Avg = id.Average()
                         });

            foreach (var item in groupBy)
            {
                Debug.WriteLine(item.ClientId + " has this many apps: " + item.NumApps + " with mean: " + item.Avg);
            }

            var modeJoin = apps.Join(customers,
                                     a => a.CustomerId,
                                     c => c.Id,
                                     (a, c) => new
                                     {
                                         ClientName = c.LastName + ", " + c.FirstName,
                                         ApplicationId = a.Id
                                     });

            var modeQuery = modeJoin.GroupBy(e => e.ClientName)
                                .OrderByDescending(group => group.Count())
                                .Select(group => group.Key);

            Debug.WriteLine("ClientId with most apps: " + modeQuery.FirstOrDefault());

            Assert.IsNotNull(joinQuery);
        }
开发者ID:SpinozaJoe,项目名称:WebsiteService,代码行数:92,代码来源:WebsiteRepositoryTest.cs

示例6: CreateSectionFiveExample001

        private static void CreateSectionFiveExample001(PdfBuilder pdfBuilder, MarginInfo parentPadding)
        {
            var secionFiveExampleTable = pdfBuilder.CreateOuterTable(
                    "140 310",
                    Resources.ArialFont,
                    PdfBuilder.DefaultHeadingTwoFontSize,
                    parentPadding,
                    keepContentTogether: true);

            // create table row heading
            pdfBuilder.CreateOuterTableRowHeading(
                secionFiveExampleTable,
                "Example Section 5 Heading");

            pdfBuilder.BlankRow(secionFiveExampleTable);

            // Create dates
            var exampleItem01Row = secionFiveExampleTable.Rows.Add();
            pdfBuilder.CreateOuterTableRowCells(
                exampleItem01Row,
                "Example item 01",
                DateTime.Now.ToShortDateString(),
                padding: PdfBuilder.DefaultSubHeadingBottomPadding);

            var exampleItem02Row = secionFiveExampleTable.Rows.Add();
            pdfBuilder.CreateOuterTableRowCells(
                exampleItem02Row,
                "Example item 02",
                "example info",
                padding: PdfBuilder.DefaultSubHeadingBottomPadding);

            var exampleItem03Row = secionFiveExampleTable.Rows.Add();
            pdfBuilder.CreateOuterTableRowCells(
                exampleItem03Row,
                "Example item 03",
                "example info",
                padding: PdfBuilder.DefaultSubHeadingBottomPadding);

            var exampleItem04Row = secionFiveExampleTable.Rows.Add();
            pdfBuilder.CreateOuterTableRowCells(
                exampleItem04Row,
                "Example item 04",
                "example info",
                padding: PdfBuilder.DefaultSubHeadingBottomPadding);

            pdfBuilder.BlankRow(secionFiveExampleTable);

            // create an overly complex arrangement of data and values to demonstrate the flexibility of the aspose pdf builder.
            var orderedNumbers = new[] { "0001", "0002", "0003" };
            var examplePairsAsGroup = new List<KeyValuePair<string, decimal>>
            {
                new KeyValuePair<string, decimal>(orderedNumbers[0], 10000), 
                new KeyValuePair<string, decimal>(orderedNumbers[0], 10000), 
                new KeyValuePair<string, decimal>(orderedNumbers[0], 10000), 
                new KeyValuePair<string, decimal>(orderedNumbers[1], 20000), 
                new KeyValuePair<string, decimal>(orderedNumbers[1], 20000), 
                new KeyValuePair<string, decimal>(orderedNumbers[1], 20000), 
                new KeyValuePair<string, decimal>(orderedNumbers[2], 30000),
                new KeyValuePair<string, decimal>(orderedNumbers[2], 30000),
                new KeyValuePair<string, decimal>(orderedNumbers[2], 30000)
            }.OrderBy(x => x.Key)
            .GroupBy(x => x.Key)
            .ToArray();

            // calculate totals - terrible example...
            var orderedNumbers0001 = examplePairsAsGroup.SelectMany(x => x).Where(x => x.Key == orderedNumbers[0]).ToArray();
            var orderedNumbers0002 = examplePairsAsGroup.SelectMany(x => x).Where(x => x.Key == orderedNumbers[1]).ToArray();
            var orderedNumbers0003 = examplePairsAsGroup.SelectMany(x => x).Where(x => x.Key == orderedNumbers[2]).ToArray();
            var exampleTotalsAsGroup = new List<KeyValuePair<string, decimal>>
            {
                new KeyValuePair<string, decimal>(orderedNumbers[0], orderedNumbers0001[0].Value + orderedNumbers0002[0].Value + orderedNumbers0003[0].Value), 
                new KeyValuePair<string, decimal>(orderedNumbers[1], orderedNumbers0001[1].Value + orderedNumbers0002[1].Value + orderedNumbers0003[1].Value), 
                new KeyValuePair<string, decimal>(orderedNumbers[2], orderedNumbers0001[2].Value + orderedNumbers0002[2].Value + orderedNumbers0003[2].Value)
            }.OrderBy(x => x.Key)
            .GroupBy(x => x.Key)
            .ToArray();

            var useWidths = "53 80 79 79 80 79"; // remember - a user can specify less or more columns and pass them into CreateInnerTable.
            // Create an inner table
            var exampleInnerTable = pdfBuilder.CreateInnerTable(useWidths, secionFiveExampleTable);

            // Create Header Inner Table row
            var exampleInnerHeaderRow = pdfBuilder.CreateInnerTableRow(exampleInnerTable, parentPadding);

            // Create Header Cell Titles
            var titles = new List<HeaderCell> { new HeaderCell { Content = "Side Content Name" } };
            var additionalNames = new [] { "example 01", "example 02", "example 03" }.GroupBy(x => x).ToArray();
            titles.AddRange(additionalNames.Select(name => new HeaderCell { Content = "ex name " + name.Key }));
            titles.Add(new HeaderCell { Content = "Total" });
            pdfBuilder.CreateInnerTableHeaderCells(exampleInnerHeaderRow, titles.ToArray());

            // Display example pairs by their ordered numbers
            foreach (var epag in examplePairsAsGroup)
            {
                var cellContentByFy = new List<DisplayCell> { new DisplayCell { Content = epag.Key, IsDate = true } };
                cellContentByFy.AddRange(epag.Select(x => new DisplayCell { Content = x.Value.ToString("C"), IsCurrency = true }).ToArray());
                cellContentByFy.Add(new DisplayCell { Content = epag.Sum(x => x.Value).ToString("C"), IsCurrency = true });

                var itemRow = pdfBuilder.CreateInnerTableRow(exampleInnerTable, parentPadding);
                pdfBuilder.CreateInnerTableItemCells(
//.........这里部分代码省略.........
开发者ID:TheY2T,项目名称:Aspose.Pdf.Builder,代码行数:101,代码来源:AsposePdfBuilderDoes.cs

示例7: DLINQPerformsDistributedSelectManyWithResultSelector

        public void DLINQPerformsDistributedSelectManyWithResultSelector()
        {
            BluepathListener listener1;
            BluepathListener listener2;
            ConnectionManager connectionManager;
            PrepareDLINQEnviroment(out listener1, out listener2, out connectionManager);

            try
            {
                var inputCollection = new List<string>()
                    {
                        "jack",
                        "checked",
                        "chicken",
                        "in",
                        "the",
                        "kitchen"
                    };

                var expectedResult = inputCollection.SelectMany(word => word.ToCharArray(), (word, character) => string.Format("{0} - {1}", word, character)).ToList();

                var storage = new RedisStorage(Host);

                var processedCollection = inputCollection.AsDistributed(storage, connectionManager)
                    .SelectMany(word => word.ToCharArray(), (word, character) => string.Format("{0} - {1}", word, character)).ToList();

                for (int i = 0; i < processedCollection.Count; i++)
                {
                    processedCollection[i].ShouldBe(expectedResult[i]);
                }
            }
            finally
            {
                listener1.Stop();
                listener2.Stop();
            }
        }
开发者ID:pbazydlo,项目名称:bluepath,代码行数:37,代码来源:DLINQIntegrationTests.cs

示例8: CheckProperlySet_OfSocialShareButton_PassedFromClient

        public void CheckProperlySet_OfSocialShareButton_PassedFromClient()
        {
            string selectedSocialButtons = "[{\"__type\":\"Telerik.Sitefinity.Frontend.SocialShare.Mvc.Models.SocialShareGroupMap, Telerik.Sitefinity.Frontend.SocialShare\",\"Groups\":[{\"Key\":\"Facebook\",\"Label\":\"Facebook\",\"IsChecked\":true,\"$$hashKey\":\"object:15\"},{\"Key\":\"Twitter\",\"Label\":\"Twitter\",\"IsChecked\":false,\"$$hashKey\":\"object:16\"},{\"Key\":\"GooglePlusOne\",\"Label\":\"Google +\",\"IsChecked\":true,\"$$hashKey\":\"object:17\"},{\"Key\":\"StumbleUpon\",\"Label\":\"Stumble Upon\",\"IsChecked\":true,\"$$hashKey\":\"object:18\"},{\"Key\":\"GoogleBookmarks\",\"Label\":\"Google bookmarks\",\"IsChecked\":true,\"$$hashKey\":\"object:19\"}],\"$$hashKey\":\"object:9\"}}]";

            var socialShareOptions = new List<SocialShareGroup>
                {
                    new SocialShareGroup(new List<SocialShareOption>
                        {
                            new SocialShareOption("Facebook", true),
                            new SocialShareOption("GooglePlusOne", true),
                            new SocialShareOption("StumbleUpon", true),
                            new SocialShareOption("GoogleBookmarks", true)
                        }),
                };

            // Arrange
            using (var controller = new DummySocialShareController())
            {
                controller.SerializedSocialShareOptionsList = selectedSocialButtons;

                // Act
                controller.Index();

                // Assert
                Assert.IsTrue(controller.Model.SocialButtons.Count == 4);

                foreach (SocialShareOption option in socialShareOptions.SelectMany(s => s.Groups))
                {
                    var button = controller.Model.SocialButtons.FirstOrDefault(b => b.ButtonName == option.Key);

                    Assert.IsNotNull(button);
                }
            }
        }
开发者ID:rhullah,项目名称:feather-widgets,代码行数:34,代码来源:SocialShareControllerTests.cs

示例9: CreateContextWithTestData

        private static DbContextFakeWrapper CreateContextWithTestData()
        {
            Role roleAdmin = new Role
            {
                Id = 1,
                Name = "Admin",
                Users = new List<User>
                {
                    new User {Id = 1, Name = "John", RoleId = 1},
                    new User {Id = 2, Name = "Alex", RoleId = 1},
                }
            };

            Role roleUser = new Role
            {
                Id = 2,
                Name = "User",
                Users = new List<User>
                {
                    new User {Id = 3, Name = "Matt", RoleId = 1},
                    new User {Id = 4, Name = "Mike", RoleId = 1},
                }
            };

            List<Role> roles = new List<Role> {roleAdmin, roleUser};
            foreach (Role role in roles)
            {
                foreach (User user in role.Users)
                    user.Role = role;
            }

            List<User> users = roles.SelectMany(r => r.Users).ToList();

            DbContextFakeWrapper wrapper = new DbContextFakeWrapper();

            DbSet<User> userSet = users.MockDbSet(wrapper);
            DbSet<Role> roleSet = roles.MockDbSet(wrapper);

            wrapper.ContextDouble.Setup(x => x.Set<User>()).Returns(() => userSet);
            wrapper.ContextDouble.Setup(x => x.Set<Role>()).Returns(() => roleSet);

            return wrapper;
        }
开发者ID:popcatalin81,项目名称:DataAccess,代码行数:43,代码来源:RepositoryBaseTests.cs

示例10: Report_FromNonEmptyQuadrant_ShouldReturnElements

        public void Report_FromNonEmptyQuadrant_ShouldReturnElements()
        {
            var items = new List<List<TestBox>>
            {
                new List<TestBox> { new TestBox(110, 0) }, // 1st
                new List<TestBox> { new TestBox(10, 0), new TestBox(50, 0) }, // 2nd
                new List<TestBox> { new TestBox(10, 110) } // 3rd
            };

            foreach (TestBox testBox in items.SelectMany(q => q))
            {
                this.quadTree.Insert(testBox);
            }

            var firstQuadrant = GetSubquadrantBounds(1);
            var elementsFirst = this.quadTree.Report(firstQuadrant);
            AssertCollectionEquality(elementsFirst, items[0]);

            var secondQuadrant = GetSubquadrantBounds(2);
            var elementsSecond = this.quadTree.Report(secondQuadrant);
            AssertCollectionEquality(elementsSecond, items[1]);

            var thirdQuadrant = GetSubquadrantBounds(3);
            var elementsThird = this.quadTree.Report(thirdQuadrant);
            AssertCollectionEquality(elementsThird, items[2]);
        }
开发者ID:pavelilchev,项目名称:HomeWorks,代码行数:26,代码来源:QuadTreeTests.cs

示例11: TestInitialize

        public void TestInitialize()
        {
            TestCleanup();

            var totalNumber = default(int);
            using (var db = new SaleDbContext())
            {
                if (db.SaleHeaders.Any())
                {
                    totalNumber = db.SaleHeaders.Max(s => s.TotalNumber);
                }
            }

            var sales = new List<SaleHeader>(55);

            for (int i = 0; i < sales.Capacity; i++)
            {
                var now = GenerateFakeNow();
                var random = new Random(i);

                var sale = new SaleHeader()
                {
                    DayNumber = sales.Count(s => s.Created.Date == now.Date) + 1,
                    TotalNumber = totalNumber + i + 1,
                    SalesPersonName = GenerateSalesPersonName(i),
                    CustomerName = string.Format("customer {0}", i + 1),
                    Status = GenerateEnumValue<SaleStatus>(),
                };
                sale.NumberText = sale.GenerateSaleNumber();
                sale.CustomerContacts = new[]
                {
                    new Contact()
                    {
                        Method = ContactMethod.Phone,
                        Value = string.Format("contact method phone number {0}", i + 1),
                    },
                    new Contact()
                    {
                        Method = GenerateEnumValue<ContactMethod>(),
                        Value = string.Format("contact method {0}", i + 1),
                    },
                };
                sale.Items = new List<SaleLineItem>();
                var length = random.Next(1, 5);
                for (int j = 0; j < length; j++)
                {
                    var line = new SaleLineItem()
                    {
                        ProductName = GenerateProductName(),
                        ProductDescription = null,
                        Quantity = random.Next(1, 2),
                        UnitPrice = (decimal)((random.NextDouble() + 0.1) * 10000),
                        Status = GenerateEnumValue<SaleStatus>(),
                    };
                    if (j % 2 == 0)
                    {
                        line.DynamicProperties.Add("Certificate", GenerateCertificate());
                        line.DynamicProperties.Add("Cut", GenerateCut());
                        line.DynamicProperties.Add("Caret", GenerateCaret());
                        line.DynamicProperties.Add("Color", GenerateColor());
                        line.DynamicProperties.Add("Clarity", GenerateClarity());
                    }

                    sale.Items.Add(line);
                }

                FillCommonValues(sale, now);

                sales.Add(sale);
            }

            using (var db = new SaleDbContext())
            {
                db.SaleHeaders.AddRange(sales);
                db.SaleLineItems.AddRange(sales.SelectMany(s => s.Items));
                db.Contacts.AddRange(sales.SelectMany(s => s.CustomerContacts));
                db.SaveChanges();
            }
        }
开发者ID:wei-zhou,项目名称:diamond,代码行数:79,代码来源:SalesServiceE2ETest.cs

示例12: selectMany

        public void selectMany()
        {
            // arrange

            List<Javascript> list = new List<Javascript>() {
                new Javascript("Angular", 3, new List<String>(new List<String>() {"1.0.1", "1.0.2"})),
                new Javascript("React", 1, new List<String>(new List<String>() {"2.0.1", "2.0.2"})),
                new Javascript("Backbone", 1, new List<String>(new List<String>() {"3.0.1", "3.0.2"}))
            };

            // act
            List<String> actual = list.SelectMany(x => x.Ver).ToList();

            // assert
            Assert.AreEqual(6, actual.Count());
            Assert.AreEqual("1.0.1", actual[0]);
            Assert.AreEqual("1.0.2", actual[1]);
            Assert.AreEqual("2.0.1", actual[2]);
            Assert.AreEqual("2.0.2", actual[3]);
            Assert.AreEqual("3.0.1", actual[4]);
            Assert.AreEqual("3.0.2", actual[5]);
        }
开发者ID:jlinqer,项目名称:jLinqer,代码行数:22,代码来源:EnumerableTest.cs


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