public void Initialize() { _privateKey = _passwordProvider.GetNextBytePassword(PasswordLength); _issuer = _fixture.Create <string>(); _audience = _fixture.Create <string>(); _tokenDescriptor = new TokenDescriptor { Issuer = _issuer, Audience = _audience, Ttl = TtlSeconds, ExpirationDate = DateTime.UtcNow.AddSeconds(30), PrivateKey = Convert.ToBase64String(_privateKey), IsActive = true }; _tokenRepository = new Mock <ITokenRepository>(); _tokenRepository.Setup(x => x.GetAsync(_issuer, _audience, CancellationToken.None)) .ReturnsAsync(_tokenDescriptor); _token = _tokenGenerator.CreateToken(_issuer, _audience, _privateKey, _ttl); var stringToken = _handler.WriteToken(_token); _tokenModel = new TokenModel(stringToken); var configurationOptions = new TokenServiceConfiguration { ClockSkew = TimeSpan.Zero, }; _tokenServiceConfiguration = new Mock <IOptions <TokenServiceConfiguration> >(); _tokenServiceConfiguration.Setup(x => x.Value).Returns(configurationOptions); _tokenService = new TokenValidationService(_tokenRepository.Object, _tokenGenerator, _tokenServiceConfiguration.Object); }