Created
November 8, 2010 20:49
-
-
Save gamlerhart/668230 to your computer and use it in GitHub Desktop.
Unit Testing, Part II, Synchronisation Issues
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ComplexBusinessOperations | |
{ | |
private int moneyEarnedSoFar; | |
public int MoneyEarnedSoFar | |
{ | |
get { return moneyEarnedSoFar; } | |
} | |
public void EarnMoney(int investment) | |
{ | |
EarnMoneySubTaks(investment); | |
EarnMoneySubTaks(investment); | |
} | |
private void EarnMoneySubTaks(int investment) | |
{ | |
for (int i = 0; i < investment; i++) | |
{ | |
var result = EarnOneDollar(); | |
moneyEarnedSoFar += result; | |
} | |
} | |
private int EarnOneDollar() | |
{ | |
Thread.Sleep(50); | |
return 1; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Test] | |
public void EarnMoney() | |
{ | |
var toTest = new ComplexBusinessOperations(); | |
toTest.EarnMoney(100); | |
Assert.AreEqual(200, toTest.MoneyEarnedSoFar); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment