本文整理汇总了C#中System.Linq.Each方法的典型用法代码示例。如果您正苦于以下问题:C# System.Linq.Each方法的具体用法?C# System.Linq.Each怎么用?C# System.Linq.Each使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Linq
的用法示例。
在下文中一共展示了System.Linq.Each方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: When_laird_is_defeated_then_all_kobolds_in_hall_are_defeated
public void When_laird_is_defeated_then_all_kobolds_in_hall_are_defeated()
{
// Arrange
var context = new TestContext();
var player = context.Player;
var laird = context.CreateCard<KoboldHumanoid>("Drakeclan Laird");
var ambusher = context.CreateCard<KoboldHumanoid>("Drakeclan Ambusher");
var cutter = context.CreateCard<KoboldHumanoid>("Drakeclan Cutter");
var shaman = context.CreateCard<KoboldHumanoid>("Drakeclan Shaman");
var kobolds = new[] {laird, ambusher, cutter, shaman};
context.SetTopOfDungeonDeck(kobolds);
context.AdvanceMonsterToFirstRank(laird);
var hand = Enumerable.Range(0, 6).Select(x => context.CreateCard<Criochan>("Criochan Captain")).ToArray();
context.SetPlayerHand(hand);
var startingXp = player.Xp;
var startingVp = player.Vp;
// Act
context.WhenBattling(laird);
player.DetermineBattleResult();
// Assert
kobolds.Each(x => Assert.That(player.Discard.Contains(x), "Discard does not contain {0}".Template(x.Name)));
context.Game.Dungeon.Ranks.Each(r=> Assert.That(r.Card, Is.Not.Null, "Rank {0} is empty".Template(r.Number)));
kobolds.Each(x => Assert.That(context.Game.Dungeon.Ranks.All(rank => rank.Card != x)));
Assert.That(player.Xp, Is.EqualTo(startingXp + laird.Xp));
Assert.That(player.Vp, Is.EqualTo(startingVp + kobolds.Sum(x => x.Vp)));
}
示例2: EachExecutesActionOnEachEnumeratedElement
public void EachExecutesActionOnEachEnumeratedElement()
{
var elements = new[]
{
new IntContainer(),
new IntContainer(),
new IntContainer()
};
elements.Each( x => x.Number++ );
Assert.IsTrue( elements.All( x=>x.Number == 1 ) );
}
示例3: Does_resolve_nested_files_and_folders
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));
}
示例4: Can_view_files_in_Directory
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");
}