3 ms·
to be honest, I'd much prefer this [TestMethod] public void ShouldBeAbleToTestActions() { var dwarfs = new List<string>() { "Sneezy", "Bashf
by keithnz 5y ago
to be honest, I'd much prefer this
[TestMethod]
public void ShouldBeAbleToTestActions()
{
var dwarfs = new List<string>() { "Sneezy", "Bashful", "Sleepy", "Happy", "Grumpy", "Doc", "Dopey" };
Action<List<string>> DoDarkMagic = (creatures) => { creatures.RemoveAt(0); }
DoDarkMagic(dwarfs)
Should("have less dwarfs", () => { dwarfs.Count.Should().Be(6); });
Should("missing Sneezy", () => { dwarfs.Should().NotContain("Sneezy"); });
};
- SideburnsOfDoom 5y agoAgreed, simpler is better. To be even simpler, In this example, these two lines can be just one: Action<List<string>> DoDarkMagic = (creatures) => { creatures.RemoveAt(0); } DoDarkMagic(dwarfs) There is no point in putting the action in a variable, only to invoke it on the next line. This is a meandering way of expressing: // Do Dark Magic dwarfs.RemoveAt(0); Extract a private method if you're keen on keeping the name.
- keithnz 5y agoit was just an example on the authors page, he explains that in reality you'd actually have some real thing you'd be testing
- SideburnsOfDoom 5y agoyes, it's an example of how these frameworks encourage accidental complexity.