Esempio n. 1
0
        private void WireupGenericTestClasses(Funq.Container container)
        {
            container.Register <IAuthenticator> (c => {
                var factory = c.Resolve <IDbConnectionFactory> ();
                var dbauth  = new DbAuthenticator(factory);
                //var dbauth = new DbTestAuthenticator ();

                var test_user = new DBUser {
                    Username    = RainyTestServer.TEST_USER,
                    IsActivated = true,
                    IsVerified  = true
                };
                test_user.CreateCryptoFields(RainyTestServer.TEST_PASS);

                // insert a dummy testuser
                using (var db = factory.OpenDbConnection()) {
                    db.InsertParam <DBUser> (test_user);
                }

                return(dbauth);
            });

            container.Register <IAdminAuthenticator> (c => {
                var admin_auth = new DummyAdminAuthenticator(ADMIN_TEST_PASS);
                return((IAdminAuthenticator)admin_auth);
            });

            RegisterStorageFactory(container, false);

            container.Register <IDataBackend> (c => {
                var conn_factory    = c.Resolve <IDbConnectionFactory> ();
                var storage_factory = c.Resolve <DbStorageFactory> ();
                var auth            = c.Resolve <IAuthenticator> ();
                var handler         = c.Resolve <OAuthHandler> ();
                return(new DatabaseBackend(conn_factory, storage_factory, auth, handler));
            });

            container.Register <OAuthHandler> (c => {
                var auth    = c.Resolve <IAuthenticator> ();
                var factory = c.Resolve <IDbConnectionFactory> ();
//				ITokenRepository<AccessToken> access_tokens = new SimpleTokenRepository<AccessToken> ();
//				ITokenRepository<RequestToken> request_tokens = new SimpleTokenRepository<RequestToken> ();
                ITokenRepository <AccessToken> access_tokens   = new DbAccessTokenRepository <AccessToken> (factory);
                ITokenRepository <RequestToken> request_tokens = new DbRequestTokenRepository <RequestToken> (factory);
                ITokenStore token_store = new RainyTokenStore(access_tokens, request_tokens);
                OAuthHandler handler    = new OAuthHandler(auth, access_tokens, request_tokens, token_store);
                return(handler);
            });

            var connFactory = container.Resolve <IDbConnectionFactory> ();

            DatabaseBackend.CreateSchema(connFactory, true);

            // HACK so the user is inserted when a fixture SetUp is run
            container.Resolve <IAuthenticator> ();
        }
Esempio n. 2
0
        private void WireupGenericTestClasses(Funq.Container container)
        {
            container.Register<IAuthenticator> (c => {
                var factory = c.Resolve<IDbConnectionFactory> ();
                var dbauth = new DbAuthenticator (factory);
                //var dbauth = new DbTestAuthenticator ();

                var test_user = new DBUser {
                    Username = RainyTestServer.TEST_USER,
                    IsActivated = true,
                    IsVerified = true
                };
                test_user.CreateCryptoFields (RainyTestServer.TEST_PASS);

                // insert a dummy testuser
                using (var db = factory.OpenDbConnection ()) {
                    db.InsertParam<DBUser> (test_user);
                }

                return dbauth;
            });

            container.Register<IAdminAuthenticator> (c => {
                var admin_auth = new DummyAdminAuthenticator (ADMIN_TEST_PASS);
                return (IAdminAuthenticator)admin_auth;
            });

            container.Register<IDbStorageFactory> (c => {
                var conn_factory = c.Resolve<IDbConnectionFactory> ();

                IDbStorageFactory storage_factory;
                bool use_encryption = true;
                if (use_encryption)
                    storage_factory = new DbEncryptedStorageFactory (conn_factory, use_history: true);
                else
                    storage_factory = new DbStorageFactory (conn_factory, use_history: true);

                return (IDbStorageFactory) storage_factory;
            });

            container.Register<IDataBackend> (c => {
                var conn_factory = c.Resolve<IDbConnectionFactory> ();
                var storage_factory = c.Resolve<IDbStorageFactory> ();
                var auth = c.Resolve<IAuthenticator> ();
                var handler = c.Resolve<OAuthHandler> ();
                return new DatabaseBackend (conn_factory, storage_factory, auth, handler);
            });

            container.Register<OAuthHandler> (c => {
                var auth = c.Resolve<IAuthenticator> ();
                var factory = c.Resolve<IDbConnectionFactory> ();
            //				ITokenRepository<AccessToken> access_tokens = new SimpleTokenRepository<AccessToken> ();
            //				ITokenRepository<RequestToken> request_tokens = new SimpleTokenRepository<RequestToken> ();
                ITokenRepository<AccessToken> access_tokens = new DbAccessTokenRepository<AccessToken> (factory);
                ITokenRepository<RequestToken> request_tokens = new DbRequestTokenRepository<RequestToken> (factory);
                ITokenStore token_store = new RainyTokenStore (access_tokens, request_tokens);
                OAuthHandler handler = new OAuthHandler (auth, access_tokens, request_tokens, token_store);
                return handler;
            });

            var connFactory = container.Resolve<IDbConnectionFactory> ();
            DatabaseBackend.CreateSchema (connFactory, true);

            // HACK so the user is inserted when a fixture SetUp is run
            container.Resolve<IAuthenticator> ();
        }