我想对一个用于验证用户的类AuthClient(使用Moq)进行单元测试.
问题是我的AuthenticationService依赖关系没有注入课堂.我对如何在不注入依赖项的情况下测试流程感到困惑.
[TestClass]
public class AuthClient
{
string Dictionary<string, IList<UserPermissions> _userPermissions;
User Login(string username, string password)
{
IAuthenticationService authenticationService = new AuthenticationService();
User user = authService.Login(username, password);
IAuthorizationService authorizationService = new AuthorizationService();
var permissions = authorizationService.GetPermissions(user);
_userPermissions.Add(user.Username, permissions);
return user;
}
}
Run Code Online (Sandbox Code Playgroud)
我目前的单元测试代码如下:
public class UnitTestClass
{
public string UserName {get;set;}
public string Password {get;set;}
[TestInitialize]
public void Setup()
{
UserName = "test";
Password = "test123";
}
[TestMethod]
public void When_ValidUserCredentials_Expect_UserIsNotNull()
{
var mockAuthenticationService …Run Code Online (Sandbox Code Playgroud)