gpt4 book ai didi

rhino-mocks - Rhino Mock 和方法不返回正确值

转载 作者:行者123 更新时间:2023-12-04 05:40:19 31 4
gpt4 key购买 nike

有谁知道为什么 UsernameExists 不会返回 True。我的语法一定在某个地方搞砸了。

[TestMethod()]
public void GenerateUsername_AppendTwoCharacters_ReturnUsernameWithTwoAppendedCharacters()
{
var usersRepository = MockRepository.GenerateStub<IUsersRepository>();
var target = new StudentsService(null, null, usersRepository, null, null, null, null);

usersRepository.Expect(q => q.UsernameExists("", null)).Return(true);

var actual = target.GenerateUsername("test", "student", "280000");
Assert.AreEqual("A", actual);
}

public string GenerateUsername(string firstName, string lastName, string studentNumber)
{
var originalusername = new StudentUsernameGenerator(firstName, lastName, studentNumber).Generate(2, 2, 4);

var username = originalusername;
if (!string.IsNullOrWhiteSpace(username))
{
decimal maxCharacters = 26;
var counter = 0;
var overflow = 1;

while (_usersRepository.UsernameExists(username, null))
{
counter++;

if (counter > maxCharacters)
{
overflow++;
counter = 1;
}

username = GetCharacterPaddingForDuplicateUsername(counter, overflow, originalusername);
}
}

return username;
}

最佳答案

我不得不添加 IgnoreArguments

usersRepository.Stub(q => q.UsernameExists("", null)).IgnoreArguments().Return(true);

关于rhino-mocks - Rhino Mock 和方法不返回正确值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11349410/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com