public void Each_runs_the_action_for_each_item() { int counter = 0; var collection = new [] {"a", "b", "c"}; collection.Each(x => counter++); counter.Should().Be(3); }
public void Each_should_call_the_provided_action() { IEnumerable<int> list = new[] { 4 }; bool isCalled = false; list.Each(i => isCalled = true); Assert.True(isCalled); }
public void Each_on_IEnumerable() { var source = new[] { "a", "b", "c" }; var items = new List<string>(); source.Each(i => { items.Add(i); }); Assert.AreEqual("a,b,c", String.Join(",", items)); }
public void Each_ActionInvokedOnEachElement() { var array = new[] { 1, 2, 3, 4, 5 }; int iteration = 0; array.Each(i => { Assert.AreEqual(i, array[iteration]); iteration++; }); Assert.AreEqual(iteration, array.Length); }
public void each() { Assert.Throws<ArgumentNullException>(() => CollectionsExtensions.Each<object>(null, it => {})); Assert.Throws<ArgumentNullException>(() => Enumerable.Empty<object>().Each(null)); var strings = new [] { "first", "second", "third" }; var list = new List<string>(); Assert.True(ReferenceEquals(strings.Each(list.Add), strings)); Assert.Equal(3, list.Count); Assert.Equal("first", list[0]); Assert.Equal("second", list[1]); Assert.Equal("third", list[2]); }
public void LinqEach() { IEnumerable<TestLinqProcess> items = new[] { new TestLinqProcess { Int1 = 1}, new TestLinqProcess { Int1 = 2}, new TestLinqProcess { Int1 = 3}, new TestLinqProcess { Int1 = 4}, new TestLinqProcess { Int1 = 5}, new TestLinqProcess { Int1 = 6} }; items.Each(item => item.Int1 += 1); var test = 2; foreach (var item in items) { Assert.AreEqual(test, item.Int1); test++; } }
public void Can_select_on_Dates() { using (var db = OpenDbConnection()) { db.DropAndCreateTable<Submission>(); var dates = new[] { new DateTime(2014,1,1), new DateTime(2014,1,1,1,0,0), new DateTime(2014,1,1,2,0,0), new DateTime(2014,1,2), new DateTime(2014,2,1), DateTime.UtcNow, new DateTime(2015,1,1), }; var i = 0; dates.Each(x => db.Insert(new Submission { Id = i++, StoryDate = x, Headline = "Headline" + i, Body = "Body" + i, })); Assert.That(db.Select<Submission>(q => q.StoryDate >= new DateTime(2014, 1, 1)).Count, Is.EqualTo(dates.Length)); Assert.That(db.Select<Submission>(q => q.StoryDate <= new DateTime(2014, 1, 1, 2, 0, 0)).Count, Is.EqualTo(3)); var storyDateTime = new DateTime(2014, 1, 1); Assert.That(db.Select<Submission>(q => q.StoryDate > storyDateTime - new TimeSpan(1, 0, 0, 0) && q.StoryDate < storyDateTime + new TimeSpan(1, 0, 0, 0)).Count, Is.EqualTo(3)); } }
public void remove_local_subscriptions() { var subscriptions = new[] { ObjectMother.NewSubscription(), ObjectMother.NewSubscription() }; subscriptions.Each(x => { x.Receiver = channelGraph.ReplyChannelFor("foo"); x.Source = new Uri("foo://source"); }); theRepository.PersistSubscriptions(subscriptions); persistence.LoadSubscriptions(TheNodeName, SubscriptionRole.Subscribes) .ShouldHaveTheSameElementsAs(subscriptions); var removed = theRepository.RemoveLocalSubscriptions(); removed.ShouldHaveTheSameElementsAs(subscriptions); persistence.LoadSubscriptions(TheNodeName, SubscriptionRole.Subscribes) .ShouldHaveCount(0); }
public void remove_subscriptions_for_receiver() { var differentNode = ObjectMother.ExistingSubscription("DifferentNode"); var differentReceiver = ObjectMother.ExistingSubscription(); differentReceiver.Receiver = new Uri("memory://other_receiver"); var subscriptions = new[] { ObjectMother.ExistingSubscription(), ObjectMother.ExistingSubscription(), ObjectMother.ExistingSubscription(), differentNode, differentReceiver }; subscriptions.Each(x => x.Role = SubscriptionRole.Publishes); persistence.Persist(subscriptions); theRepository.RemoveSubscriptionsForReceiver(subscriptions[0].Receiver); persistence.LoadSubscriptions(TheNodeName, SubscriptionRole.Publishes) .ShouldHaveTheSameElementsAs(differentReceiver); persistence.LoadSubscriptions("DifferentNode", SubscriptionRole.Publishes) .ShouldHaveTheSameElementsAs(differentNode); }
public void Delete_all_queues_and_exchanges() { var exchangeNames = new[] { Exchange, ExchangeDlq, ExchangeTopic, ExchangeFanout, QueueNames.Exchange, QueueNames.ExchangeDlq, QueueNames.ExchangeTopic, }; using (IConnection connection = mqFactory.CreateConnection()) using (IModel channel = connection.CreateModel()) { exchangeNames.Each(x => channel.ExchangeDelete(x)); channel.DeleteQueue<AlwaysThrows>(); channel.DeleteQueue<Hello>(); channel.DeleteQueue<HelloRabbit>(); channel.DeleteQueue<HelloResponse>(); channel.DeleteQueue<Incr>(); channel.DeleteQueue<AnyTestMq>(); channel.DeleteQueue<AnyTestMqResponse>(); channel.DeleteQueue<PostTestMq>(); channel.DeleteQueue<PostTestMqResponse>(); channel.DeleteQueue<ValidateTestMq>(); channel.DeleteQueue<ValidateTestMqResponse>(); channel.DeleteQueue<ThrowGenericError>(); channel.DeleteQueue<Reverse>(); channel.DeleteQueue<Rot13>(); channel.DeleteQueue<Wait>(); } }
public void Does_resolve_nested_files_and_folders() { var pathProvider = GetPathProvider(); var allFilePaths = new[] { "testfile.txt", "a/testfile-a1.txt", "a/testfile-a2.txt", "a/b/testfile-ab1.txt", "a/b/testfile-ab2.txt", "a/b/c/testfile-abc1.txt", "a/b/c/testfile-abc2.txt", "a/d/testfile-ad1.txt", "e/testfile-e1.txt", }; allFilePaths.Each(x => pathProvider.WriteFile(x, x.SplitOnLast('.').First().SplitOnLast('/').Last())); Assert.That(allFilePaths.All(x => pathProvider.IsFile(x))); Assert.That(new[] { "a", "a/b", "a/b/c", "a/d", "e" }.All(x => pathProvider.IsDirectory(x))); Assert.That(!pathProvider.IsFile("notfound.txt")); Assert.That(!pathProvider.IsFile("a/notfound.txt")); Assert.That(!pathProvider.IsDirectory("f")); Assert.That(!pathProvider.IsDirectory("a/f")); Assert.That(!pathProvider.IsDirectory("testfile.txt")); Assert.That(!pathProvider.IsDirectory("a/testfile-a1.txt")); AssertContents(pathProvider.RootDirectory, new[] { "testfile.txt", }, new[] { "a", "e" }); AssertContents(pathProvider.GetDirectory("a"), new[] { "a/testfile-a1.txt", "a/testfile-a2.txt", }, new[] { "a/b", "a/d" }); AssertContents(pathProvider.GetDirectory("a/b"), new[] { "a/b/testfile-ab1.txt", "a/b/testfile-ab2.txt", }, new[] { "a/b/c" }); AssertContents(pathProvider.GetDirectory("a").GetDirectory("b"), new[] { "a/b/testfile-ab1.txt", "a/b/testfile-ab2.txt", }, new[] { "a/b/c" }); AssertContents(pathProvider.GetDirectory("a/b/c"), new[] { "a/b/c/testfile-abc1.txt", "a/b/c/testfile-abc2.txt", }, new string[0]); AssertContents(pathProvider.GetDirectory("a/d"), new[] { "a/d/testfile-ad1.txt", }, new string[0]); AssertContents(pathProvider.GetDirectory("e"), new[] { "e/testfile-e1.txt", }, new string[0]); Assert.That(pathProvider.GetFile("a/b/c/testfile-abc1.txt").ReadAllText(), Is.EqualTo("testfile-abc1")); Assert.That(pathProvider.GetDirectory("a").GetFile("b/c/testfile-abc1.txt").ReadAllText(), Is.EqualTo("testfile-abc1")); Assert.That(pathProvider.GetDirectory("a/b").GetFile("c/testfile-abc1.txt").ReadAllText(), Is.EqualTo("testfile-abc1")); Assert.That(pathProvider.GetDirectory("a").GetDirectory("b").GetDirectory("c").GetFile("testfile-abc1.txt").ReadAllText(), Is.EqualTo("testfile-abc1")); var dirs = pathProvider.RootDirectory.Directories.Map(x => x.VirtualPath); Assert.That(dirs, Is.EquivalentTo(new[] { "a", "e" })); var rootDirFiles = pathProvider.RootDirectory.GetAllMatchingFiles("*", 1).Map(x => x.VirtualPath); Assert.That(rootDirFiles, Is.EquivalentTo(new[] { "testfile.txt" })); var allFiles = pathProvider.GetAllMatchingFiles("*").Map(x => x.VirtualPath); Assert.That(allFiles, Is.EquivalentTo(allFilePaths)); allFiles = pathProvider.GetAllFiles().Map(x => x.VirtualPath); Assert.That(allFiles, Is.EquivalentTo(allFilePaths)); pathProvider.DeleteFile("testfile.txt"); pathProvider.DeleteFolder("a"); pathProvider.DeleteFolder("e"); Assert.That(pathProvider.GetAllFiles().ToList().Count, Is.EqualTo(0)); }
public void numbers_should_be_invalid() { var numbers = new[] { "1,00", "100,1", "100,1.01", "A,Jun.K", }; numbers.Each(x => x.IsValidNumber(CultureInfo.CreateSpecificCulture("en-us")).ShouldBeFalse()); }
public void numbers_with_commas_and_periods_should_be_valid_in_european_culture() { var numbers = new[] { "1.000", "100,1", "1000,1", "1.000,1", "10.000,1", "100.000,1", }; numbers.Each(x => x.IsValidNumber(CultureInfo.CreateSpecificCulture("de-DE")).ShouldBeTrue()); }
public void numbers_with_commas_and_periods_should_be_valid() { var numbers = new[] { "1,000", "100.1", "1000.1", "1,000.1", "10,000.1", "100,000.1", }; numbers.Each(x => x.IsValidNumber(CultureInfo.CreateSpecificCulture("en-us")).ShouldBeTrue()); }
public string get_partial(PartialInput input) { var builder = new StringBuilder(); var partialModels = new[] { new PartialViewModel {Name = "Item1"}, new PartialViewModel {Name = "Item2"}, new PartialViewModel {Name = "Item3"} }; partialModels.Each(m => { _request.Set(m); var page = new Core.UI.FubuHtmlDocument<PartialViewModel>(_locator, _request); builder.AppendLine(SourceModifier(page).ToString()); //builder.AppendLine(); }); return builder.ToString(); }
public void Can_RemoveItemsFromSortedSet() { var removeMembers = new[] { "two" , "four", "six" }; storeMembers.ForEach(x => Redis.AddItemToSortedSet(SetId, x)); var removeCount = Redis.RemoveItemsFromSortedSet(SetId, removeMembers.ToList()); Assert.That(removeCount, Is.EqualTo(2)); removeMembers.Each(x => storeMembers.Remove(x)); var members = Redis.GetAllItemsFromSortedSet(SetId); Assert.That(members, Is.EquivalentTo(storeMembers)); }
public void Each2_ActionNull () { IEnumerable<char> e = new[]{'a'}; Action<char, int> a = null; e.Each (a); }
public void Can_view_files_in_Directory() { var pathProvider = GetPathProvider(); var testdirFileNames = new[] { "testdir/a.txt", "testdir/b.txt", "testdir/c.txt", }; testdirFileNames.Each(x => pathProvider.WriteFile(x, "textfile")); var testdir = pathProvider.GetDirectory("testdir"); var filePaths = testdir.Files.Map(x => x.VirtualPath); Assert.That(filePaths, Is.EquivalentTo(testdirFileNames)); var fileNames = testdir.Files.Map(x => x.Name); Assert.That(fileNames, Is.EquivalentTo(testdirFileNames.Map(x => x.SplitOnLast('/').Last()))); pathProvider.DeleteFolder("testdir"); }