public void ChartImage() { var products = new[] { new Product {Name = "Kayak", Category = "Watersports", Price = 275m}, new Product {Name = "Lifejacket", Category = "Watersports", Price = 48.95m}, new Product {Name = "Soccer ball", Category = "Football", Price = 19.50m}, new Product {Name = "Corner flags", Category = "Football", Price = 34.95m}, new Product {Name = "Thinking cap", Category = "Chess", Price = 16m}, }; Chart chart = new Chart(600, 200, @"<Chart BackColor=""Gray"" BackSecondaryColor=""WhiteSmoke"" BackGradientStyle=""DiagonalRight"" AntiAliasing=""All"" BorderlineDashStyle = ""Solid"" BorderlineColor = ""Gray""> <BorderSkin SkinStyle = ""Emboss"" /> <ChartAreas> <ChartArea Name=""Default"" _Template_=""All"" BackColor=""Wheat"" BackSecondaryColor=""White"" BorderColor=""64, 64, 64, 64"" BorderDashStyle=""Solid"" ShadowColor=""Transparent""> </ChartArea> </ChartAreas> </Chart>"); chart.AddSeries( chartType: "Column", yValues: products.Select(p => p.Price).ToArray(), xValue: products.Select(p => p.Name).ToArray() ); chart.Write(); }
public void CompareOk() { var predicates = checker.PredicatesList; var hands = new[] { "A♠ 2♥ 3♣ 9♦ Q♥", "2♠ 2♥ 3♣ 4♦ 6♥", "2♠ 2♥ 3♣ 3♦ 6♥", "2♠ 2♥ 2♣ 3♦ 6♥", "2♠ 5♠ 7♠ 9♠ J♠", "2♠ 3♥ 4♣ 5♦ 6♥", "2♠ 2♥ 2♣ 3♦ 3♥", "2♠ 2♥ 2♣ 2♦ 6♥", "2♠ 3♠ 4♠ 5♠ 6♠", "2♠ 2♥ 2♣ 2♦ 5♥", "A♠ 2♥ 3♣ 4♦ 5♥", "A♠ Q♥ 0♣ J♦ K♥", "A♠ A♠", "A♠ A♠ 0♣ J♦ K♥ 2♠", "" }; bool ok = true; foreach (var hand1 in hands.Select(h => PokerUtils.ReadHand(h))) foreach (var hand2 in hands.Select(h => PokerUtils.ReadHand(h))) { if (!checker.IsValidHand(hand1) || !checker.IsValidHand(hand2)) continue; // the indices of the two hands in the predicate list int ii, jj; for (ii = 0; ii < predicates.Count; ii++) { if (predicates[ii](hand1)) break; } for (jj = 0; jj < predicates.Count; jj++) { if (predicates[jj](hand2)) break; } var cmp = checker.CompareHands(hand1, hand2); if (cmp == 0) { if (ii != jj) ok = false; continue; } // the higher the index, the weaker the hand if (cmp == -1) { if (ii < jj) ok = false; continue; } else { if (ii > jj) ok = false; continue; } } Assert.IsTrue(ok); }
public void PicksCorrectVariablesInSimpleCase() { // Predicate p(X,Y) :- q(X, Z), r(Z,Y) should have Z and Y as permanent variables var p = Literal.NewAtom(); var q = Literal.NewAtom(); var r = Literal.NewAtom(); var X = Literal.NewVariable(); var Y = Literal.NewVariable(); var Z = Literal.NewVariable(); var pXY = Literal.NewFunctor(2).With(X, Y); var qXZ = Literal.NewFunctor(2).With(X, Z); var rZY = Literal.NewFunctor(2).With(Z, Y); // Create the clause var clause = Clause.If(qXZ, rZY).Then(pXY); // Compile to assignments var allPredicates = new[] { clause.Implies }.Concat(clause.If).ToArray(); var assignmentList = allPredicates.Select(predicate => PredicateAssignmentList.FromPredicate(predicate)); // Get the set of permanent variables var permanent = PermanentVariableAssignments.PermanentVariables(assignmentList); // Z and Y are the only permanent variables Assert.IsFalse(permanent.Contains(X)); Assert.IsTrue(permanent.Contains(Y)); Assert.IsTrue(permanent.Contains(Z)); Assert.AreEqual(2, permanent.Count); }
public void ReturnsCorrectDistinctPath() { var paths = new[] { Combine("logger.log"), Combine("Debug", "logger.log"), Combine("bin", "Debug", "logger.log"), Combine("C:\\", "App", "bin", "Debug", "logger.log"), Combine("D:\\", "App", "bin", "Debug", "logger.log"), Combine("C:\\", "App", "bin", "Release", "logger.log"), Combine("C:\\", "App", "obj", "Release", "logger.log") }; var expected = new[] { Combine("logger.log"), Combine("Debug", "logger.log"), Combine("bin", "..", "logger.log"), Combine("C:\\", "..", "logger.log"), Combine("D:\\", "..", "logger.log"), Combine("bin", "..", "logger.log"), Combine("obj", "..", "logger.log") }; var trie = new FileNamer(paths); var result = paths.Select(path => trie.GetName(path)).ToArray(); Assert.Equal(expected, result); }
public async Task TestTwoElementsAsync() { var testCode = @"%1 Foo { } %1 Bar { }"; var fixedCode = new[] { @"%1 Foo { } ", @"%1 Bar { }" }; testCode = testCode.Replace("%1", this.Keyword); fixedCode = fixedCode.Select(c => c.Replace("%1", this.Keyword)).ToArray(); DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(4, this.Keyword.Length + 2); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false); await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false); if (this.SupportsCodeFix) { await this.VerifyCSharpFixAsync(new[] { testCode }, fixedCode, cancellationToken: CancellationToken.None).ConfigureAwait(false); } }
public void CollectionNoErroronEmptyCollectionnTest() { var testCases = new[] { new { CollectionName = (string)null, PayloadItems = new CollectionWriterTestDescriptor.ItemDescription[0], ExpectedException = (ExpectedException)null, }, }; var testDescriptors = testCases.Select(tc => new CollectionWriterTestDescriptor( this.Settings, tc.CollectionName, tc.PayloadItems, tc.ExpectedException, /*model*/null)); this.CombinatorialEngineProvider.RunCombinations( testDescriptors, this.WriterTestConfigurationProvider.AtomFormatConfigurationsWithIndent, (testDescriptor, testConfig) => { CollectionWriterUtils.WriteAndVerifyCollectionPayload(testDescriptor, testConfig, this.Assert, this.Logger); }); }
public async Task CanForwardToMultipleRecipients() { var network = new InMemNetwork(); var activator = new BuiltinHandlerActivator(); Using(activator); var recipients = new[] { "recipient-A", "recipient-B" }.ToList(); recipients.ForEach(network.CreateQueue); Configure.With(activator) .Transport(t => t.UseInMemoryTransport(network, "forwarder")) .Routing(t => { t.AddTransportMessageForwarder(async transportMessage => ForwardAction.ForwardTo(recipients)); }) .Start(); await activator.Bus.SendLocal("HEJ MED DIG!!!"); var transportMessages = await Task.WhenAll(recipients.Select(async queue => { var message = await network.WaitForNextMessageFrom(queue); return message; })); Assert.That(transportMessages.Length, Is.EqualTo(2)); }
public static void NURBS1() { // Draw a simple NURBS // Example from this page:http://www.robthebloke.org/opengl_programming.html var page = SampleEnvironment.Application.ActiveDocument.Pages.Add(); var points = new[] { new VA.Drawing.Point(10, 10), new VA.Drawing.Point(5, 10), new VA.Drawing.Point(-5, 5), new VA.Drawing.Point(-10, 5), new VA.Drawing.Point(-4, 10), new VA.Drawing.Point(-4, 5), new VA.Drawing.Point(-8, 1) }; var origin = new VA.Drawing.Point(4, 4); var scale = new VA.Drawing.Size(1.0/4.0, 1.0/4.0); var controlpoints = points.Select(x => (x*scale) + origin).ToList(); var knots = new double[] {0, 0, 0, 0, 1, 2, 3, 4, 4, 4, 4}; var degree = 3; var weights = controlpoints.Select(i => 1.0).ToList(); var s0 = page.DrawNURBS(controlpoints, knots, weights, degree); s0.Text = "Generic NURBS shape"; }
public Rectangle2D GetBounds() { float ymin = 0; float xmin = 0; float xmax = this.Viewport.Width; float ymax = this.Viewport.Height; var matrix = Matrix.Invert(this.GetMatrix() * SpriteBatchExtensions.GetUndoMatrix(this.Viewport)); var corners = new[] { new Vector2(xmin, ymin), new Vector2(xmax, ymin), new Vector2(xmin, ymax), new Vector2(xmax, ymax), }; var vectors = corners.Select(x => Vector2.Transform(x, matrix)).ToList(); xmin = vectors.Min(x => x.X); xmax = vectors.Max(x => x.X); ymin = vectors.Min(x => x.Y); ymax = vectors.Max(x => x.Y); return new Rectangle2D(xmin, xmax, ymax, ymin); }
protected override void ProcessRecord() { var names = new[] {"Tolle", "Sinan", "Frissan", "Ekan"}; if (!string.IsNullOrEmpty(Prefix)) { names = names.Select(n => Prefix + n).ToArray(); } WriteObject(names); }
/*begin*/ public ActionResult GetItems(GridParams g, string[] selectedColumns, bool? choosingColumns) { //when setting columns from here we don't get the grid defaults, so we have to specify Sortable, Groupable etc. var columns = new[] { new Column { Name = "Id", Width = 70, Order = 1 }, new Column { Name = "Person", Sortable = true, Groupable = true, GroupRemovable = true, Order = 2 }, new Column { Name = "Food", Sortable = true, Groupable = true, GroupRemovable = true, Order = 3 }, new Column { Name = "Location", Sortable = true, Groupable = true, GroupRemovable = true, Order = 4 }, new Column { Name = "Date", Sortable = true, Groupable = true, GroupRemovable = true, Width = 100, Order = 5 }, new Column { Name = "Price", Sortable = true, Groupable = true, GroupRemovable = true, Width = 100, Order = 6 }, }; var baseColumns = new[] { "Id", "Person" }; //first load if (g.Columns.Length == 0) { g.Columns = columns; } if (choosingColumns.HasValue && selectedColumns == null) { selectedColumns = new string[] { }; } if (selectedColumns != null) { //make sure we always have Id and Person columns selectedColumns = selectedColumns.Union(baseColumns).ToArray(); var currectColumns = g.Columns.ToList(); //remove unselected columns currectColumns = currectColumns.Where(o => selectedColumns.Contains(o.Name)).ToList(); //add missing columns var missingColumns = selectedColumns.Except(currectColumns.Select(o => o.Name)).ToArray(); currectColumns.AddRange(columns.Where(o => missingColumns.Contains(o.Name))); g.Columns = currectColumns.ToArray(); } var gridModel = new GridModelBuilder<Lunch>(Db.Lunches.AsQueryable(), g).Build(); // used to populate the checkboxlist gridModel.Tag = new { columns = columns.Select(o => o.Name).Except(baseColumns).ToArray(), selectedColumns = g.Columns.Select(o => o.Name).Except(baseColumns).ToArray() }; return Json(gridModel); }
public void Test1To20() { var target = new FizzBuzz(); var collection = new[] { "1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz", "16", "17", "Fizz", "19", "Buzz" }; foreach (var item in collection.Select((value, index) => new { Index = index + 1, Value = value })) { Assert.That(target.Compute(item.Index), Is.EqualTo(item.Value)); } }
public void GetExtensionReturnsEmptyStringForPathsThatDoNotContainExtension() { // Arrange string[] paths = new[] { "SomePath", "SomePath/", "SomePath/MorePath", "SomePath/MorePath/" }; // Act var extensions = paths.Select(PathUtil.GetExtension); // Assert Assert.IsTrue(extensions.All(ext => ext.Length == 0)); }
public void GetExtensionReturnsEmptyStringForPathsContainingPathInfo() { // Arrange string[] paths = new[] { "SomePath.cshtml/", "SomePath.html/path/info" }; // Act var extensions = paths.Select(PathUtil.GetExtension); // Assert Assert.IsTrue(extensions.All(ext => ext.Length == 0)); }
public void GetExtensionReturnsEmptyStringForPathsTerminatingWithADot() { // Arrange string[] paths = new[] { "SomePath.", "SomeDirectory/SomePath/SomePath.", "SomeDirectory/SomePath.foo." }; // Act var extensions = paths.Select(PathUtil.GetExtension); // Assert Assert.IsTrue(extensions.All(ext => ext.Length == 0)); }
public void DontCompleteOne() { var taskCompletionSources = new [] { new TaskCompletionSource<int>(), new TaskCompletionSource<int>() }; var whenAllTask = TaskEx.WhenAll(taskCompletionSources.Select(tcs => tcs.Task)); taskCompletionSources[0].SetResult(1); Assert.IsFalse(whenAllTask.IsCompleted); }
public void AndWithNotsBecomesBoolWithMustNots() { var expectedMustNots = new[] { new RangeCriteria("field1", memberInfo, RangeComparison.LessThan, 2), new RangeCriteria("field2", memberInfo, RangeComparison.GreaterThan, 4) }; var actual = QueryCriteriaRewriter.Compensate(AndCriteria.Combine(expectedMustNots.Select(NotCriteria.Create).ToArray())); var boolActual = Assert.IsType<BoolCriteria>(actual); Assert.Equal(boolActual.MustNot.AsEnumerable(), expectedMustNots); Assert.Empty(boolActual.Should); Assert.Empty(boolActual.Must); }
public void CreateRepositoryReturnsLocalRepositoryIfSourceIsPhysicalPath() { // Arrange var paths = new[] { @"C:\packages\", @"\\folder\sub-folder", "file://some-folder/some-dir"}; var factory = new PackageRepositoryFactory(); // Act and Assert Assert.True(paths.Select(factory.CreateRepository) .All(p => p is LocalPackageRepository)); }
/// <summary> /// Creates an address formatted as a single string. /// </summary> /// <param name="address1"> /// The address 1. /// </param> /// <param name="address2"> /// The address 2. /// </param> /// <param name="locality"> /// The locality. /// </param> /// <param name="region"> /// The region. /// </param> /// <param name="postalCode"> /// The postal code. /// </param> /// <param name="countryCode"> /// The country code. /// </param> /// <returns> /// The <see cref="string"/>. /// </returns> public static string GetApiRequestFormattedAddressString(string address1, string address2, string locality, string region, string postalCode, string countryCode) { var segments = new[] { string.Concat(address1, " ", address2), locality ?? string.Empty, string.Concat(region, " ", postalCode), countryCode ?? string.Empty }; return string.Join(", ", segments.Select(x => x.Trim()).Where(x => !string.IsNullOrWhiteSpace(x))); }
public void MoreReadable() { var people = new[]{"Pavel Egorov", "Yuriy Okulovskiy", "Alexandr Denisov", "Ivan Sorokin", "Dasha Zubova", "Irina Gess"}; var names = people.Select(fullname => fullname.Split(' ')[0]); var girls = names.Where(name => name[name.Length - 1] == 'a'); Assert.That(girls, Is.EqualTo(new[] {"Dasha", "Irina"})); }
public void testLambdaSelect() { var someItems = new[] { "aap", "noot", "mies" }; var x = someItems.Select(s => s == "noot").ToArray(); AssertNotNull(x); AssertEquals(x.Length, 3); AssertFalse(x[0]); AssertTrue(x[1]); AssertFalse(x[2]); }
public async Task GenericIEnumerableWithSomeContents() { var taskCompletionSources = new [] { new TaskCompletionSource<int>(), new TaskCompletionSource<int>() }; var whenAnyTask = TaskEx.WhenAny(taskCompletionSources.Select(tcs => tcs.Task)); taskCompletionSources[1].SetResult(2); var result = await whenAnyTask; Assert.AreEqual(2, await result); }
public PartialViewResult Menu() { var names = new[] {"My Robots", "Add Robot", "All Program"}; var menuItems = names.Select(x => new LeftMenuItem { Name = x }).ToArray(); menuItems[0].Url = Url.Action("ShowMyRobots", "Robot"); menuItems[1].Url = Url.Action("AddRobotForm", "Robot"); menuItems[2].Url = Url.Action("ShowAllPrograms", "Program"); return PartialView("Menu", menuItems); }
public void Clearing_Children_Should_Clear_VisualParent() { var children = new[] { new Visual(), new Visual() }; var target = new TestVisual(); target.AddChildren(children); target.ClearChildren(); var result = children.Select(x => x.GetVisualParent()).ToList(); Assert.Equal(new Visual[] { null, null }, result); }
public async Task EnumerableWithSomeContents() { var taskCompletionSources = new [] { new TaskCompletionSource<int>(), new TaskCompletionSource<int>() }; var whenAnyTask = TaskEx.WhenAny(taskCompletionSources.Select(tcs => tcs.Task).Cast<Task>()); Assert.IsFalse(whenAnyTask.IsCompleted); taskCompletionSources[1].SetResult(2); await await whenAnyTask; }
public async Task ArrayVersion() { var taskCompletionSources = new[] { new TaskCompletionSource<int>(), new TaskCompletionSource<int>() }; Task whenAllTask = TaskEx.WhenAll(taskCompletionSources.Select(tcs => tcs.Task).ToArray()); taskCompletionSources[0].SetResult(1); Assert.IsFalse(whenAllTask.IsCompleted); taskCompletionSources[1].SetResult(1); await whenAllTask; }
public void Install(IWindsorContainer container, IConfigurationStore store) { var eventTypes = new[] { typeof(AmountsCalculated), typeof(TaxesCalculated), typeof(PayoutMethodSelected), }; var bus = container.Resolve<IBus>(); Task.WaitAll(eventTypes.Select(type => bus.Subscribe(type)).ToArray()); }
public async Task NonGenericVersion() { var taskCompletionSources = new [] { new TaskCompletionSource<int>(), new TaskCompletionSource<int>() }; var whenAllTask = TaskEx.WhenAll(taskCompletionSources.Select(tcs => tcs.Task).Cast<Task>()); taskCompletionSources[0].SetResult(1); Assert.IsFalse(whenAllTask.IsCompleted); taskCompletionSources[1].SetResult(1); await whenAllTask; }
public void does_not_complete_until_all_specs_are_handled() { var specs = new[] { new Specification(), new Specification(), new Specification() }; var watcher = new BatchWatcher(specs); watcher.Task.IsCompleted.ShouldBeFalse(); var results = specs.Select(x => new SpecResults()).ToArray(); var specPlans = specs.Select(x => { return new SpecificationPlan(Enumerable.Empty<CompositeExecution>()) { Specification = x }; }).ToArray(); for (var i = 0; i < specs.Length; i++) { watcher.SpecHandled(specPlans[i], results[i]); if (i < specs.Length - 1) { watcher.Task.IsCompleted.ShouldBeFalse(); } } watcher.Task.IsCompleted.ShouldBeTrue(); var records = watcher.Task.Result; records.Select(x => x.results).ShouldBe(results); records.Select(x => x.specification).ShouldBe(specs); }
public async Task GenericIEnumerableWithSomeContents() { var taskCompletionSources = new [] { new TaskCompletionSource<int>(), new TaskCompletionSource<int>(), new TaskCompletionSource<int>() }; var whenAllTask = TaskEx.WhenAll(taskCompletionSources.Select(tcs => tcs.Task)); taskCompletionSources[0].SetResult(1); taskCompletionSources[1].SetResult(2); taskCompletionSources[2].SetResult(3); var results = await whenAllTask; CollectionAssert.AreEquivalent(new[] {1, 2, 3}, results.ToList()); }