Skip to content

Instantly share code, notes, and snippets.

@sharwell
Created January 29, 2014 18:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sharwell/8694092 to your computer and use it in GitHub Desktop.
Save sharwell/8694092 to your computer and use it in GitHub Desktop.
The assertions in the test method all pass. Read carefully :)
[TestMethod]
public void TestCalls()
{
FooDerived foo = new FooDerived();
Func<int> method = foo.Bar;
Assert.AreEqual(1, method());
method = foo.FooBar();
Assert.AreEqual(1, method());
method = foo.BaseFooBar();
Assert.AreEqual(0, method());
}
class Foo
{
public virtual int Bar()
{
return 0;
}
public virtual Func<int> FooBar()
{
return Bar;
}
public virtual Func<int> BaseFooBar()
{
return Bar;
}
}
class FooDerived : Foo
{
public override int Bar()
{
return 1;
}
public override Func<int> BaseFooBar()
{
return base.Bar;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment