Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[Fact]
public async Task ShouldGenerateAccessTokenIfUserIsRegistered()
{
// arrange
var membershipRepositoryMock = new Mock<IMembershipRepository>();
var registeredUser = new RegisteredUser("firstName", "lastName");
membershipRepositoryMock
.Setup(x => x.Verify(It.IsAny<UserLogin>()))
.ReturnsAsync(registeredUser);
var tokenGenerator = new Mock<IJwtTokenGenerator>();
tokenGenerator
.Setup(x => x.GenerateAccessToken(
It.IsAny<string>(),
It.IsAny<Claim[]>()))
.Returns(It.IsAny<string>())
.Verifiable();
var authController = new AuthController(
membershipRepositoryMock.Object,
tokenGenerator.Object);
// act
var response = await authController.Login(
new UserLoginRequest
{
Username = "unregistered",
Password = "pass1"
});
// assert
tokenGenerator.Verify(x =>
x.GenerateAccessToken(
registeredUser.Fullname,
It.IsAny<Claim[]>()),
Times.Once);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment