예제 #1
0
        public override void Configure(Container container)
        {
            Plugins.Add(new RegistrationFeature());
            Plugins.Add (
                new AuthFeature
                (
                    () => new AuthUserSession(),
                    new IAuthProvider[]
                    {
                        new BasicAuthProvider(),
                        new CustomCredentialsAuthProvider()
                    }
                ) {HtmlRedirect = "/common/login" }
            );
            Plugins.Add(new RazorFormat());

            SetConfig(new EndpointHostConfig {
                DefaultContentType = ContentType.Json,
                CustomHttpHandlers = {
                    { HttpStatusCode.NotFound, new RazorHandler("/notfound") }
                }
            });

            container.Register<IRedisClientsManager>(new PooledRedisClientManager("localhost:6379"));
            UserRepository = new RedisAuthRepository(container.Resolve<IRedisClientsManager>());
            container.Register<IUserAuthRepository>(UserRepository);
        }
        public void SetUp()
        {
            try
            {
                tests = new OAuthUserSessionTests();
                var inMemoryRepo = new InMemoryAuthRepository();
                inMemoryRepo.Clear();
                userAuthRepositorys.Add(inMemoryRepo);

                var appSettings = new AppSettings();
                var redisRepo = new RedisAuthRepository(new BasicRedisClientManager(new string[] { appSettings.GetString("Redis.Host") ?? "localhost" }));
                redisRepo.Clear();
                userAuthRepositorys.Add(redisRepo);

                if (OAuthUserSessionTestsBase.UseSqlServer)
                {
                    var connStr = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\App_Data\auth.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
                    var sqlServerFactory = new OrmLiteConnectionFactory(connStr, SqlServerOrmLiteDialectProvider.Instance);
                    var sqlServerRepo = new OrmLiteAuthRepository(sqlServerFactory);
                    sqlServerRepo.DropAndReCreateTables();
                }
                else
                {
                    var sqliteInMemoryRepo = new OrmLiteAuthRepository(dbFactory);
                    dbFactory.Run(db => {
                        db.CreateTable<UserAuth>(true);
                        db.CreateTable<UserOAuthProvider>(true);
                    });
                    sqliteInMemoryRepo.Clear();
                    userAuthRepositorys.Add(sqliteInMemoryRepo);

                    var sqliteDbFactory = new OrmLiteConnectionFactory(
                        "~/App_Data/auth.sqlite".MapProjectPath());
                    var sqliteDbRepo = new OrmLiteAuthRepository(sqliteDbFactory);
                    sqliteDbRepo.CreateMissingTables();
                    userAuthRepositorys.Add(sqliteDbRepo);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                throw;
            }
        }