我的 main.cs 代码:
public string Generate(int length)
{
char[] chars = "$%#@!*abcdefghijklmnopqrstuvwxyz1234567890?;:ABCDEFGHIJKLMNOPQRSTUVWXYZ^&".ToCharArray();
string password = string.Empty;
Random random = new Random();
for (int i = 0; i < length; i++)
{
int x = random.Next(1, chars.Length);
if (!password.Contains(chars.GetValue(x).ToString()))
password += chars.GetValue(x);
else
i--;
}
return password;
}
我做了一个测试代码
[TestMethod]
[Timeout(1000)]
public void RenderingPasswordShouldHaveMaximumSize()
{
var amountOfCharacters = Int32.MaxValue;
var generator = new PasswordGenerator();
var target = generator.Generate(amountOfCharacters);
Assert.Fail("This method should throw an exception if you try to create a password with too many characters");
}
但它给了我以下错误:
消息:测试“RenderingPasswordShouldHaveMaximumSize”超出执行超时期限
有人可以帮我弄这个吗?我的密码需要最大为 74。