【发布时间】:2011-03-10 20:00:47
【问题描述】:
我想为名为@987654321@ 的类的成员函数创建一个单元测试,该类存储游戏中排名前五的玩家。
问题是我为 (SignInScoreBoard) 创建测试的方法正在调用 Console.ReadLine(),因此用户可以输入他们的姓名:
public void SignInScoreBoard(int steps)
{
if (topScored.Count < 5)
{
Console.Write(ASK_FOR_NAME_MESSAGE);
string name = Console.ReadLine();
KeyValuePair<string, int> pair = new KeyValuePair<string, int>(name, steps);
topScored.Insert(topScored.Count, pair);
}
else
{
if (steps < topScored[4].Value)
{
topScored.RemoveAt(4);
Console.Write(ASK_FOR_NAME_MESSAGE);
string name = Console.ReadLine();
topScored.Insert(4, new KeyValuePair<string, int>(name, steps));
}
}
}
有没有办法插入十个用户,这样我就可以检查是否存储了五个移动(步数)较少的用户?
【问题讨论】:
标签: c# visual-studio unit-testing console console-redirect