Skip to content

Commit

Permalink
#15 - added test of chain call od extension methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
mpostol committed Apr 9, 2016
1 parent de64d02 commit fe2792e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Lecture/Lecture/ExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ public static int WordCount(this String str)
{
return str.Split(new char[] { ' ', '.', '?' }, StringSplitOptions.RemoveEmptyEntries).Length;
}

public static int MethodA(this int i)
{
return -i;
}
/// <summary>
/// Determines whether [contains] [the specified value].
/// </summary>
Expand Down
10 changes: 10 additions & 0 deletions Lecture/Lesson2UnitTest/ExtensionMethodsUnitTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ public void InstanceCallTestMethod()
Assert.AreEqual<int>(3, _TestString.WordCount()); //To enable extension methods for a particular type, the definition must be visible.
Assert.AreEqual<int>(3, ExtensionMethods.WordCount(_TestString)); //Typical method call can also be in use.
}
[TestMethod]
public void SequentialCallTestMethod()
{
string _TestString = "Hello Extension Methods";
int _WordCountResult = _TestString.WordCount();
Assert.AreEqual<int>(3, _WordCountResult);
Assert.AreEqual<int>(-3, _WordCountResult.MethodA());
}
/// <summary>
/// Mies the test method.
/// </summary>
Expand Down Expand Up @@ -42,6 +50,8 @@ public void MyTestMethod()
Assert.AreEqual<int>(1, (int)c.MethodA(1)); // C.MethodA(object)
Assert.AreSame(_inputString, c.MethodA(_inputString)); // C.MethodA(object)
Assert.AreNotSame(new AnyClass(), c.MethodA(new AnyClass()));

//How to use it
}
private class AnyClass
{
Expand Down

0 comments on commit fe2792e

Please sign in to comment.