public void Setup() { SymmetricSecurityKey key = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(Constants.GetSecret())); SigningCredentials signingCredentials = new SigningCredentials(key, SecurityAlgorithms.HmacSha256Signature); JwtSecurityTokenHandler tokenHandler = new JwtSecurityTokenHandler(); DateTime expires = DateTime.UtcNow.AddHours(1); MapperConfiguration mapperConfig = new MapperConfiguration(c => c.AddProfile(new AutoMapperProfile())); _mapper = new Mapper(mapperConfig); _dotsSecurityTokenHandler = new DotsSecurityTokenHandler( key, signingCredentials, tokenHandler, expires); _usersRepository = new UsersRepository(Constants.databaseContext); _usersCollection = Constants.databaseContext.Users; _usersController = new UsersController( _usersRepository, _mapper, _dotsSecurityTokenHandler, AuthorizationService); User testSubject = new User(); testSubject.Id = "60848ae8fb71edf2a7ebf846"; testSubject.Email = "*****@*****.**"; testSubject.PasswordHash = "$2a$11$wvypXckqs4LxCCalZMBV9.CIkcUmayQAvvyISAPmlY4/Prs49Wkce"; testSubject.Notices = new Notice[] { }; if (_usersCollection.Find(u => u.Email == testSubject.Email).FirstOrDefault() == null) { _usersCollection.InsertOne(testSubject); } }
public UsersController( IUsersRepository userRepository, IMapper mapper, IDotsSecurityTokenHandler dotsSecurityTokenHandler, IAuthorizationService authorizationService) { _userRepository = userRepository; _mapper = mapper; _dotsSecurityTokenHandler = dotsSecurityTokenHandler; AuthorizationService = authorizationService; }