I have a class with a constructor like so:
public class SsoAuthenticationService : ISsoAuthenticationService
{
public SsoAuthenticationService(ILoginManager manager)
{
_manager = manager;
}
}
And also the manager class has a constructor like so:
public class LoginManager:ILoginManager
{
private ILoginRepository login;
public LoginManager(ILoginRepository loginRepository)
{
login = loginRepository;
}
}
I am trying to write a unit test against the SSoAuthenticationService class
public void CreateLogin_Returns_Login()
{
//arrange
var mocManager = new Mock<ILoginManager>();
ILoginManager m = mocManager.Object;
//fails at the next line
var svc = new SsoAuthenticationService(mocManager.Object);
var request = new CreateSsoLoginRequest()
{
EmailAddress = "",
Password = "",
SecurityQuestionAnswer = "",
SecurityQuestionId = 0,
SiteIdentifier = "",
Username = ""
};
//act
var response = svc.CreateSsoLogin(request);
//assert
response.Should().NotBeNull();
}
This gives an error when it tries to instantiate the SsoAuthenticationService
class ("Value cannot be null.\r\nParameter name: value"
), and I believe that the problem is that I need to also mock the IRepository
class as well, but I'm not sure how the mocking code should then look.
Edit: Full exception info
The type initializer for 'Progressive.Sso.WebServices.SsoAuthenticationService' threw an exception.
Value cannot be null.\r\nParameter name: value
at Progressive.Sso.WebServices.SsoAuthenticationService..ctor(ILoginManager manager)
at Progressive.Sso.Tests.Service_Methods.ServiceTest.CreateLogin_Returns_Login() in d:\tfs\sso\Dev\Dev\Src\SSO Web Services\Progressive.Sso.Tests\Service Methods\ServiceTest.cs:line 29
Can anyone help me out?