public void ReturnUserClaimsDTOForAuthenticatedUser() { // GIVEN a UserDTO containing a user's e-mail and password UserDTO user = new UserDTO { EmailAddress = "*****@*****.**", Password = "******" }; // WHEN the user is correctly authenticated // AND the user's login information is returned from the database TrainerCredentials mockTrainerCredentials = new TrainerCredentials { EmailAddress = "*****@*****.**", Hash = PASSWORD1234_HASH, Salt = PASSWORD1234_SALT }; accountContextMock.Setup(a => a.TrainerCredentials.Find(user.EmailAddress)).Returns(mockTrainerCredentials); Trainer mockTrainer = new Trainer { EmailAddress = "*****@*****.**", FirstName = "Test", LastName = "User" }; accountContextMock.Setup(a => a.Trainer.Find(mockTrainer.EmailAddress)).Returns(mockTrainer); configMock.Setup(c => c.Value.JwtKey).Returns(JWT_KEY); UserClaimsDTO userClaims = accountServices.AuthorizeTrainer(user); // THEN return a UserClaimsDTO containing an e-mail claim with the // user's e-mail, a name claim with the user's full name, a role claim // of trainer, and a TrainerId claim with the trainer's ID List <Claim> claims = new List <Claim> { new Claim(ClaimTypes.Email, "*****@*****.**"), new Claim(ClaimTypes.Name, "Test User"), new Claim(ClaimTypes.Role, UserRole.TRAINER.ToString()) }; for (int i = 0; i < claims.Count; i++) { Assert.Equal(claims[i].GetType(), userClaims.Claims[i].GetType()); Assert.Equal(claims[i].Value, userClaims.Claims[i].Value); } // AND an encrypted Token var handler = new JwtSecurityTokenHandler(); var decodedClaims = handler.ReadToken(userClaims.Token) as JwtSecurityToken; Assert.NotNull(decodedClaims); }