private void AddStateValidation() { var nameProperties = new[] { "State" }; const string errorMessage = "The State is required"; _validators.Add(new CallbackValidator(() => { nameProperties.ForEach(RemoveErrors); if (Country != null && Country.HasStates && Country.DisplayStates && State == null) nameProperties.ForEach(p => AddError(p, errorMessage)); }, nameProperties)); }
private void AddSuburbValidation() { var suburbProperties = new[] { "SuburbName", "SuburbCode", "Suburb" }; const string errorMessage = "The Suburb and PostCode are required"; _validators.Add(new CallbackValidator(() => { suburbProperties.ForEach(RemoveErrors); if (Suburb == null && (String.IsNullOrEmpty(SuburbName) || String.IsNullOrEmpty(SuburbCode))) suburbProperties.ForEach(p => AddError(p, errorMessage)); }, suburbProperties)); }
private void AddIataNumberValidation() { var nameProperties = new[] { "IataNumber" }; const string errorMessage = "The IATA Number is required, a minimum of 7 numbers and maximum for 8"; _validators.Add(new CallbackValidator(() => { nameProperties.ForEach(RemoveErrors); if (IataNumber.Trim().Length < 7 || IataNumber.Trim().Length > 8) nameProperties.ForEach(p => AddError(p, errorMessage)); }, nameProperties)); }
private void AddNameValidation() { var nameProperties = new[] { "Name" }; const string errorMessage = "The Name is required"; _validators.Add(new CallbackValidator(() => { nameProperties.ForEach(RemoveErrors); if (String.IsNullOrWhiteSpace(Name)) nameProperties.ForEach(p => AddError(p, errorMessage)); }, nameProperties)); }
public static IEnumerable<GtfsFile> GetAll() { var server = HttpContext.Current.Server; var files = new[] { new GtfsFile { FileName = "current.zip", Description = new HtmlString("<p>The current static GTFS data. This file will always contain the current schedule period.</p><p>At the time of a schedule change, this file will contain both schedule periods merged together. Your software must use the date ranges in the calendar.txt table to select the correct trips based on date.</p>"), DocumentationUrl = new KeyValuePair<string,string>("https://developers.google.com/transit/gtfs/", "GTFS") }, new GtfsFile { FileName = "alerts.bin", Description = new HtmlString("GTFS-Realtime alert data. This file contains information about availability of stops and routes."), DocumentationUrl = new KeyValuePair<string,string>("https://developers.google.com/transit/gtfs-realtime/service-alerts", "GTFS-realtime Service Alerts") }, new GtfsFile { FileName = "tripupdates.bin", Description = new HtmlString("GTFS-Realtime trip update data. This file contains information about the arrival times of current trips."), DocumentationUrl = new KeyValuePair<string,string>("https://developers.google.com/transit/gtfs-realtime/trip-updates", "GTFS-realtime Trip Updates") }, new GtfsFile { FileName = "vehiclepositions.bin", Description = new HtmlString("GTFS-Realtime vehicle position data. This file contains the most recent latitude/longitude of vehicles assigned to current trips."), DocumentationUrl = new KeyValuePair<string,string>("https://developers.google.com/transit/gtfs-realtime/vehicle-positions", "GTFS-realtime Vehicle Positions") } }.ToList(); files.ForEach(f => AssignLastUpdate(f, server)); return files; }
public void TestAssignment() { var algorithm = new Dijkstra<int>(Graph, 1); algorithm.Run(); var nodes = new[] { Graph.Get(7), Graph.Get(37), Graph.Get(59), Graph.Get(82), Graph.Get(99), Graph.Get(115), Graph.Get(133), Graph.Get(165), Graph.Get(188), Graph.Get(197), }.ToList(); nodes.ForEach(n => { Console.Write(n.Score); Console.Write(","); }); }
public void ForEach_Extension_With_Action() { var integers = new[] {1, 2, 3, 4, 5}; int sum = 0; integers.ForEach(value => sum += value); Assert.AreEqual(sum, 15); }
public ISessionFactory Seed(ISessionFactory factory) { var users = new[] { new User {Name = "Joe"}, new User {Name = "Anne"}, new User {Name = "Admin"} }; using (var s = factory.OpenSession()) { if (!s.Query<IUser>().Any()) { using (var t = s.BeginTransaction()) { users.ForEach(u => { s.Save(u); s.Save(CreateBragForUser(u)); }); t.Commit(); } } } return factory; }
public void Index_WhenGivenSnapShots_ShouldMapReduceAllBouncesAcrossAllCreativbes() { var snapshots = new[] { new DroneStateSnapshoot { MailBounced = new List<MailBounced> { new MailBounced {DomainGroup = "msn", Recipient = "*****@*****.**", CreativeId = "creative/1", Message = "this is bounce message1"}, new MailBounced {DomainGroup = "msn", Recipient = "*****@*****.**", CreativeId = "creative/1", Message = "this is bounce message2"} } }, new DroneStateSnapshoot { MailBounced = new List<MailBounced> { new MailBounced {DomainGroup = "msn", Recipient = "*****@*****.**", CreativeId = "creative/1", Message = "this is bounce message3"}, new MailBounced {DomainGroup = "msn", Recipient = "*****@*****.**", CreativeId = "creative/1", Message = "this is bounce message4"}, new MailBounced {DomainGroup = "msn", Recipient = "*****@*****.**", CreativeId = "creative/1", Message = "this is bounce message5"}, new MailBounced {DomainGroup = "msn", Recipient = "*****@*****.**", CreativeId = "creative/2", Message = "this is bounce message6"} } } }.ToList(); snapshots.ForEach(Store.Store); Store.WaitForIndexNotToBeStale<Creative_AllBounces.ReduceResult, Creative_AllBounces>(); var result = Store.Query<Creative_AllBounces.ReduceResult, Creative_AllBounces>(); result[0].Bounced.Select(x => x.Recipient).Should().BeEquivalentTo(new[] { "*****@*****.**", "*****@*****.**", "*****@*****.**", "*****@*****.**", "*****@*****.**", "*****@*****.**" }); result[0].Bounced.Select(x => x.Message).Should().BeEquivalentTo(new[] { "this is bounce message1", "this is bounce message2", "this is bounce message3", "this is bounce message4", "this is bounce message5", "this is bounce message6" }); }
public void ForEachFixture() { var list = new[] { 1, 2, 3, 4, 5 }; int idx = 0; list.ForEach(item => item.Should().Equal(list[idx++])); }
public void EigenUpdateWithoutUpdateURL() { string dir; string outDir; using (Utility.WithTempDirectory(out outDir)) using (IntegrationTestHelper.WithFakeInstallDirectory(out dir)) { var di = new DirectoryInfo(dir); var progress = new Subject<int>(); var bundledRelease = ReleaseEntry.GenerateFromFile(di.GetFiles("*.nupkg").First().FullName); var fixture = new InstallManager(bundledRelease, outDir); var pkg = new ZipPackage(Path.Combine(dir, "SampleUpdatingApp.1.1.0.0.nupkg")); var progressValues = new List<int>(); progress.Subscribe(progressValues.Add); fixture.ExecuteInstall(dir, pkg, progress).Wait(); var filesToLookFor = new[] { "SampleUpdatingApp\\app-1.1.0.0\\SampleUpdatingApp.exe", "SampleUpdatingApp\\packages\\RELEASES", "SampleUpdatingApp\\packages\\SampleUpdatingApp.1.1.0.0.nupkg", }; filesToLookFor.ForEach(f => Assert.True(File.Exists(Path.Combine(outDir, f)), "Could not find file: " + f)); // Progress should be monotonically increasing progressValues.Count.ShouldBeGreaterThan(2); progressValues.Zip(progressValues.Skip(1), (prev, cur) => cur - prev).All(x => x > 0).ShouldBeTrue(); } }
private void AddUserListValidation() { var properties = new[] { "Users" }; _validators.Add(new CallbackValidator(() => { properties.ForEach(RemoveErrors); bool emailsErrored = false; if (Users != null) { HashSet<string> emails = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase); foreach (var user in Users) { user.Validate(); if (user.HasErrors) emailsErrored = true; else { if (emails.Contains(user.Email)) { AddError("Users", "The same email is added a few times!"); return; } else emails.Add(user.Email); } } } if (emailsErrored) AddError("Members", "Invalid email addresses"); }, properties)); }
public void TestNullAction_ShouldThrowException() { IEnumerable<int> source = new[] { 1, 2, 3, 4, 5 }; Action<int> action = null; source.ForEach(action); }
public void Timed_Source_must_measure_time_it_takes_between_elements_matching_a_predicate() { var testActor = CreateTestProbe(); const int measureBetweenEvery = 5; Action<TimeSpan> printInfo = interval => { testActor.Tell(interval); _helper.WriteLine($"Measured interval between {measureBetweenEvery} elements was {interval}"); }; var n = 20; var testRuns = new[] {1, 2}; Func<Script<int, int>> script = () => Script.Create( Enumerable.Range(1, n) .Select(x => new Tuple<ICollection<int>, ICollection<int>>(new[] {x}, new[] {x})).ToArray()); testRuns.ForEach( _ => RunScript(script(), Materializer.Settings, flow =>flow.Select(x => x) .TimedIntervalBetween(i => i%measureBetweenEvery == 0, printInfo))); var expectedNrOfOnIntervalCalls = testRuns.Length*((n/measureBetweenEvery) - 1); // first time has no value to compare to, so skips calling onInterval Enumerable.Range(1,expectedNrOfOnIntervalCalls).ForEach(_=> testActor.ExpectMsg<TimeSpan>()); }
private void AddTestUsers() { var users = new[] { new User { Id = new Guid("55E1E49E-B7E8-4EEA-8459-7A906AC4D4C0"), UserName = "******", Password = "******", Claims = new[]{"Administrator"} }, new User { Id = new Guid("56E1E49E-B7E8-4EEA-8459-7A906AC4D4C0"), UserName = "******", Password = "******", Claims = new[]{"User"} } }; using (var session = this.documentStore.OpenSession()) { users.ForEach(session.Store); session.SaveChanges(); } }
private static string RemoveWhiteSpaces(string str) { var whiteSpaces = new[] { ' ', '\t', '\r', '\n' }; whiteSpaces.ForEach(ch => str = str.Replace(new string(ch, 1), "")); return str; }
public void TestNullActionShouldThrowException() { IEnumerable<int> source = new[] { 1, 2, 3, 4, 5 }; Action<int> action = null; // ReSharper disable once ExpressionIsAlwaysNull source.ForEach(action); }
public void ForEach_GivenListOfNumbers_SumsThemUp() { var listOfNumbers = new[] { 1, 1, 1 }; var sum = 0; listOfNumbers.ForEach ( e => sum = sum + e ); Assert.AreEqual ( 3, sum ); }
public void DoSomething_Called_ExpectBothCallsToSourceEventAreWovenToRaiseCliEvents() { var tokens = new[] {Guid.NewGuid(), Guid.NewGuid()}; this.AggregateRoot.MonitorEvents(); ((dynamic) this.AggregateRoot).DoSomething(tokens[0], tokens[1]); tokens.ForEach(token => this.AggregateRoot.ShouldRaise(EventName).WithDomainEvent<object>(this.AggregateRoot, x => SomethingHappenedWithToken(x, token))); }
public void Foreach_calls_given_lambda_for_each_element() { var elements = new[] { 1, 2, 3 }; int sum = 0; elements.ForEach(element => sum += element); sum.ShouldEqual(6); }
public void ForEach_ActionIsNull_ArgumentException() { int[] e = new[] {2, 2}; Action act = () => e.ForEach(null); act.ShouldThrow<ArgumentNullException>(); }
public void ForEach() { int[] numbers = new[] { 2, 3, 6, 7 }; int sum = 0; numbers.ForEach(x => sum += x); Assert.Equal(sum, numbers.Sum()); }
public void ShareWorksForArray() { var result = new List<int>(); var enm = new[] { 1, 2, 3, 4, 5 }.Share(); enm.Take(3).ForEach(i => result.Add(i)); result.Add(-1); enm.ForEach(i => result.Add(i)); Assert.AreEqual(result, new[] { 1, 2, 3, -1, 4, 5 }); }
protected void clear_Click(object sender, EventArgs e) { var img = new[] { p0, p1, p2, p3 }.ToList(); img.ForEach(o => o.Src = "../Content/Images/Transparent.png"); upload.InitialFileInputsCount = 1; upload.MaxFileInputsCount = 4; clear.Visible = false; imgRow.Visible = false; }
public void TestInvokeInstanceMethod() { RunWith( ( object person ) => { var elements = new[] { 1d, 2d, 3d, 4d, 5d }; elements.ForEach( element => person.CallMethod( "Walk", element ) ); Assert.AreEqual( elements.Sum(), person.GetFieldValue( "metersTravelled" ) ); } ); }
public void ForEachFunc() { var @enum = new[] {1, 2, 3, 4}.AsEnumerable(); var sum = 0; @enum.ForEach(n => sum += n); Assert.AreEqual(sum, @enum.Sum()); }
public void ForEach_Should_Call_The_Specified_Method_Each_Item() { var array = new[] { "Item 1", "Item2" }; var called = new[] { false, false }; array.ForEach(i => called[Array.IndexOf(array, i)] = true); Assert.IsTrue(called.All(c => c)); }
public void TestMultipleItemsSource_ShouldInvokeActionMultipleTimes() { IEnumerable<int> source = new[] { 1, 10, 100, 1000 }; var actionInvocationsCount = 0; Action<int> action = item => { actionInvocationsCount++; }; source.ForEach(action); Assert.AreEqual(source.Count(), actionInvocationsCount, "Action should be invoked N times for an enumerable with N items."); }
public void ForEach_MoreElements_ActionExecutedForEachElement() { List<int> actual = new List<int>(); int[] e = new[] {1, 2}; e.ForEach(actual.Add); List<int> expected = new List<int> {1, 2}; Assert.Equal(actual, expected); }
public void WhenCallingForEachIterateEachItemInTheGivenCollection() { IEnumerable<int> testCollection = new[]{1, 1, 1}; int itemCount = 0; testCollection.ForEach(item => itemCount++); Assert.That(itemCount, Is.EqualTo(testCollection.Count())); }
public void BostSystem(int boost) { System.ForEach(s => s.Boost(boost)); }