I have one method inside my code which is fetching session and using the UserAuthId in further process
public async Task<object> PostAsync(RequestDTO request)
{
var session = await GetSessionAsync();
var userAuthId = session.UserAuthId;
// Rest code
}
Now I want to write unit tests for this and I am able to mock rest dependency but every time I am getting session as null
I am mocking UserManager and EmailSender which is needed for my methods
[SetUp]
public void SetUp()
{
_appHost = new BasicAppHost().Init();
var container = _appHost.Container;
_userManagerMock = new Mock<UserManager<ApplicationUser>>(
Mock.Of<IUserStore<ApplicationUser>>(), null!, null!, null!, null!, null!, null!, null!, null!);
_emailSenderMock = new Mock<IEmailSender<ApplicationUser>>();
_appSettingsMock = new Mock<IAppSettings>();
container.Register(_userManagerMock.Object);
container.Register(_emailSenderMock.Object);
container.Register(_appSettingsMock.Object);
_target = container.Resolve<MyServices>();
}
So how will I mock session to lets say return specific details for eg: UserAuthId to be “user1”