我的控制器中确实有一些功能。下面的代码是示例:
[HttpPost]
public async Task<IActionResult> NewAccount(Account account)
{
if (ModelState.IsValid)
{
_Iaccount.NewAccount(account);
return RedirectToAction("Accounts");
}
return View();
}
我只想为此函数创建并发模拟单元测试。我试图创建一个。
[TestMethod]
public async Task TestforNewAccount()
{
Mock<IAccount> mock = new Mock<IAccount>();
var testController = new AccountController(mock.Object);
Account _account = new Account()
{
AccountName = "sample",
Id = 1,
AccountNumber = "123",
Password = "sample"
};
mock.Setup(s => s.GetAccountById(1)).Returns(_account);
IActionResult result = await testController.NewAccount(_account);
Assert.IsInstanceOfType(result, typeof(RedirectToActionResult));
}
public async Task TestForConcurrentNewAccount()
{
await TestforNewAccount();
}
但我认为它不会测试并发性。
谢谢!