我想为一个类的成员函数创建一个单元测试,该类函数ScoreBoard存储游戏中的前五名玩家.
问题是我为(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));
}
}
}
Run Code Online (Sandbox Code Playgroud)
有没有办法插入十个用户,所以我可以检查是否存储了五个较少的移动(步骤)?