public UserServiceTest()
        {
            var context = new MaktoobDbContext(new DbContextOptionsBuilder <MaktoobDbContext>().UseInMemoryDatabase("MaktoobDb").Options);

            _errorDescriber = new GErrorDescriber();
            var keyNormalizer  = new NameNormalizer();
            var passwordHasher = new PasswordHasher();
            var unitOfWork     = new UnitOfWork(context);
            var userRepository = new UserRepository(context, unitOfWork);
            var userValidator  = new IValidator <User>[] { new UserValidator(userRepository, keyNormalizer, _errorDescriber) };

            _userService = new UserService(userRepository, _errorDescriber, keyNormalizer, passwordHasher, userValidator);
        }
        public SignInServiceTest()
        {
            var context = new MaktoobDbContext(new DbContextOptionsBuilder <MaktoobDbContext>().UseInMemoryDatabase("MaktoobDb").Options);

            _errorDescriber = new GErrorDescriber();
            var keyNormalizer       = new NameNormalizer();
            var passwordHasher      = new PasswordHasher();
            var unitOfWork          = new UnitOfWork(context);
            var userRepository      = new UserRepository(context, unitOfWork);
            var userLoginRepository = new UserLoginRepository(context, unitOfWork);
            var userValidator       = new IValidator <User>[] { new UserValidator(userRepository, keyNormalizer, _errorDescriber) };

            _userService = new UserService(userRepository, _errorDescriber, keyNormalizer, passwordHasher, userValidator);
            var jsonWebTokenOptions = new JsonWebTokenOptions
            {
                Issuer       = "issuer",
                Audience     = "audience",
                Algorithm    = "HS256",
                Key          = "super secret key",
                Expires      = TimeSpan.Parse("00:00:01"), // 1 seconds
                RefreshToken = new RefreshTokenOptions
                {
                    Expires        = TimeSpan.Parse("00:00:10"), // 10 seconds
                    UpdateRequired = TimeSpan.Parse("00:00:05")  // 5 seconds
                }
            };
            var securityKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jsonWebTokenOptions.Key));
            JwtBearerOptions jwtBearerOptions = new JwtBearerOptions
            {
                TokenValidationParameters = new TokenValidationParameters
                {
                    IssuerSigningKey         = securityKey,
                    ValidIssuer              = jsonWebTokenOptions.Issuer,
                    ValidAudience            = jsonWebTokenOptions.Audience,
                    ValidateAudience         = !string.IsNullOrWhiteSpace(jsonWebTokenOptions.Audience),
                    ValidateIssuer           = !string.IsNullOrWhiteSpace(jsonWebTokenOptions.Issuer),
                    ValidateIssuerSigningKey = true,
                    ClockSkew        = TimeSpan.Zero,
                    ValidateLifetime = true
                }
            };
            var jsonWebTokenCoder     = new JsonWebTokenCoder(Options.Create(jsonWebTokenOptions));
            var userClaimsFactory     = new UserClaimsFactory();
            var refreshTokenGenerator = new RefreshTokenGenerator();

            _signInService = new SignInService(_userService,
                                               jsonWebTokenCoder, userLoginRepository,
                                               _errorDescriber, userClaimsFactory, refreshTokenGenerator, null,
                                               Options.Create(jsonWebTokenOptions));
        }
 public Repository(MaktoobDbContext dbContext, IUnitOfWork unitOfWork)
 {
     _dbContext = dbContext;
     UnitOfWork = unitOfWork;
 }
Exemple #4
0
 public UnitOfWork(MaktoobDbContext dbContext)
 {
     _dbContext = dbContext;
 }
 public UserLoginRepository(MaktoobDbContext dbContext, IUnitOfWork unitOfWork) : base(dbContext, unitOfWork)
 {
 }