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); } } }
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); } } } }
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); }
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); }
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); }
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( itemRow, cellContent: cellContentByFy.ToArray()); } // Display Totals var cellContentTotals = new List<DisplayCell> { new DisplayCell { Content = "Totals", IsHeader = true } }; cellContentTotals.AddRange(exampleTotalsAsGroup.Select(x => new DisplayCell { Content = x.Sum(sum => sum.Value).ToString("C"), IsTotal = true, IsCurrency = true }).ToArray()); cellContentTotals.Add(new DisplayCell { Content = exampleTotalsAsGroup.Sum(sum => sum.Sum(x => x.Value)).ToString("C"), IsTotal = true, IsCurrency = true }); var projectCostCentreTotalRow = pdfBuilder.CreateInnerTableRow(exampleInnerTable, PdfBuilder.DefaultOuterPadding); pdfBuilder.CreateInnerTableItemCells( projectCostCentreTotalRow, cellContent: cellContentTotals.ToArray()); pdfBuilder.BlankRow(); }
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(); } }
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); } } }
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; }
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]); }
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(); } }
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]); }