-
Notifications
You must be signed in to change notification settings - Fork 36
Mocking the Authentication Provider
sergeyshushlyapin edited this page Nov 4, 2014
·
1 revision
[Fact]
public void HowToMockAuthenticationProvider()
{
// create and configure authentication provider mock
var provider =
Substitute.For<Sitecore.Security.Authentication.AuthenticationProvider>();
provider.Login("John", true).Returns(true);
// switch the authentication provider so the mocked version is used
using (new Sitecore.Security.Authentication.AuthenticationSwitcher(provider))
{
// the authentication manager is called with expected parameters and returns True
Xunit.Assert.True(
Sitecore.Security.Authentication.AuthenticationManager.Login("John", true));
// the authentication manager is called with wrong parameters and returns False
Xunit.Assert.False(
Sitecore.Security.Authentication.AuthenticationManager.Login("Robber", true));
}
}