I'm trying to Unit test my login method, for that I used below provider
var provider = Substitute.For<Sitecore.Security.Authentication.AuthenticationProvider>();
provider
.Login("extranet\[email protected]", "Test@123", false)
.Returns(true);
and used this in using block.
using(var db = new Sitecore.FakeDb.Db("master"){ new Sitecore.FakeDb.DbItem("home")} )
using (new Sitecore.Security.Authentication.AuthenticationSwitcher(provider))
{
var item = db.GetItem("/sitecore/content/home"); //Here the error throws "User cannot be null"
var loginResult = Sitecore.Security.Authentication.AuthenticationManager.Login("extranet\[email protected]", "Test@123");
loginResult.Should().BeTrue();
}
I'm able to test the sitecore Login method but inside that block the I'm not able to do any activity like DataBase.GetItem()
or AuthenticationManager.GetActiveUser()
which throws an error saying System.InvalidOperationException: 'User cannot be null.'