public CreateDatabaseTests()
 {
     _settings          = StoreSettings.DefaultSettings();
     _settings.Database = Guid.NewGuid().ToString();
     _service           = AdminServiceFactory.Create(_settings);
     _client            = new MongoClient(_settings.ConnectionString);
 }
        public static void AddIdentityServer(this IServiceCollection services, string idsConnectionString)
        {
            StoreSettings idSvrStoreSettings = StoreSettings.DefaultSettings();

            idSvrStoreSettings.ConnectionString = idsConnectionString;
            idSvrStoreSettings.Database         = MongoUrl.Create(idSvrStoreSettings.ConnectionString).DatabaseName;
            services.AddInstance(idSvrStoreSettings);
            services.AddInstance(AdminServiceFactory.CreateClientService(idSvrStoreSettings));
            services.AddInstance(AdminServiceFactory.CreateScopeService(idSvrStoreSettings));
        }
        public PersistenceTestFixture()
        {
            _settings          = StoreSettings.DefaultSettings();
            _settings.Database = "testidentityserver";
            var registrations = new ServiceFactory(null, _settings);
            var client        = new MongoClient(_settings.ConnectionString);

            _database = client.GetDatabase(_settings.Database);
            _factory  = new Factory(registrations);
        }
示例#4
0
        public PowershellAdminModuleFixture()
        {
            _powerShell = PowerShell.Create();
            _powerShell.AddCommand("Import-Module").AddParameter("Name", typeof(CreateScope).Assembly.Location);
            _database = Guid.NewGuid().ToString("N");

            var settings = StoreSettings.DefaultSettings();

            settings.Database = _database;
            var config = new ServiceFactory(null, settings);

            _factory = new Factory(settings, config,
                                   new AdminServiceRegistry());
            _client = new MongoClient(settings.ConnectionString);
        }
        public async Task CreateDatabase()
        {
            var defaults = StoreSettings.DefaultSettings();

            Assert.False(await _client.DatabaseExistsAsync(_database));
            _ps.Invoke();
            Assert.True(await _client.DatabaseExistsAsync(_database));
            var db = _client.GetDatabase(_database);

            Assert.True(await db.CollectionExistsAsync(defaults.AuthorizationCodeCollection), "Authoriz");
            Assert.True(await db.CollectionExistsAsync(defaults.ClientCollection));
            Assert.True(await db.CollectionExistsAsync(defaults.ConsentCollection));
            Assert.True(await db.CollectionExistsAsync(defaults.RefreshTokenCollection));
            Assert.True(await db.CollectionExistsAsync(defaults.ScopeCollection));
            Assert.True(await db.CollectionExistsAsync(defaults.TokenHandleCollection));

            await _client.DropDatabaseAsync(_database);
        }
        protected override void BeginProcessing()
        {
            var storeSettings = StoreSettings.DefaultSettings();

            storeSettings.ConnectionString            = ConnectionString ?? storeSettings.ConnectionString;
            storeSettings.Database                    = Database ?? storeSettings.Database;
            storeSettings.ClientCollection            = ClientCollection ?? storeSettings.ClientCollection;
            storeSettings.ScopeCollection             = ScopeCollection ?? storeSettings.ScopeCollection;
            storeSettings.ConsentCollection           = ConsentCollection ?? storeSettings.ConsentCollection;
            storeSettings.AuthorizationCodeCollection = AuthorizationCodeCollection ?? storeSettings.AuthorizationCodeCollection;
            storeSettings.RefreshTokenCollection      = RefreshTokenCollection ?? storeSettings.RefreshTokenCollection;
            storeSettings.TokenHandleCollection       = TokenHandleCollection ?? storeSettings.TokenHandleCollection;
            CanCreateDatabase(storeSettings);

            var serviceFactory = new ServiceFactory(null, storeSettings);

            serviceFactory.Register(new Registration <IMongoClient>(new MongoClient(storeSettings.ConnectionString)));
            var factory = new Factory(storeSettings, serviceFactory, new AdminServiceRegistry());

            _adminService        = factory.Resolve <IAdminService>();
            _tokenCleanupService = factory.Resolve <ICleanupExpiredTokens>();
            _scopeStore          = factory.Resolve <IScopeStore>();
            base.BeginProcessing();
        }