public static Databases SetUpRepositories(BaseConfig baseConfig) { CustomSerializers.RegisterAll(); IMongoClient mongoClient = new MongoClient(baseConfig.MongoDbConnectionUri); IMongoDatabase mongoDatabase = mongoClient.GetDatabase(baseConfig.MongoDbDatabaseName); IUserRepo userRepo = new UserRepo( database: mongoDatabase, startingPokeyen: baseConfig.StartingPokeyen, startingTokens: baseConfig.StartingTokens); IBadgeRepo badgeRepo = new BadgeRepo( database: mongoDatabase); IBank <User> pokeyenBank = new Bank <User>( database: mongoDatabase, currencyCollectionName: UserRepo.CollectionName, transactionLogCollectionName: "pokeyentransactions", u => u.Pokeyen, u => u.Id, clock: SystemClock.Instance); IBank <User> tokenBank = new Bank <User>( database: mongoDatabase, currencyCollectionName: UserRepo.CollectionName, transactionLogCollectionName: "tokentransactions", u => u.Tokens, u => u.Id, clock: SystemClock.Instance); tokenBank.AddReservedMoneyChecker( new PersistedReservedMoneyCheckers(mongoDatabase).AllDatabaseReservedTokens); return(new Databases( userRepo: userRepo, badgeRepo: badgeRepo, pokeyenBank: pokeyenBank, tokensBank: tokenBank)); }
public static Databases SetUpRepositories(ILogger logger, BaseConfig baseConfig) { IClock clock = SystemClock.Instance; CustomSerializers.RegisterAll(); IMongoClient mongoClient = new MongoClient(baseConfig.MongoDbConnectionUri); IMongoDatabase mongoDatabase = mongoClient.GetDatabase(baseConfig.MongoDbDatabaseName); IMongoDatabase mongoDatabaseMessagelog = mongoClient.GetDatabase(baseConfig.MongoDbDatabaseNameMessagelog); UserRepo userRepo = new( database : mongoDatabase, startingPokeyen : baseConfig.StartingPokeyen, startingTokens : baseConfig.StartingTokens, defaultOperators : baseConfig.Chat.DefaultOperatorNames); IMongoBadgeLogRepo badgeLogRepo = new BadgeLogRepo(mongoDatabase); IBadgeRepo badgeRepo = new BadgeRepo(mongoDatabase, badgeLogRepo, clock); badgeRepo.UserLostBadgeSpecies += (_, args) => TaskToVoidSafely(logger, () => userRepo.UnselectBadgeIfSpeciesSelected(args.UserId, args.Species)); IBank <User> pokeyenBank = new Bank <User>( database: mongoDatabase, currencyCollectionName: UserRepo.CollectionName, transactionLogCollectionName: "pokeyentransactions", u => u.Pokeyen, u => u.Id, clock: clock); IBank <User> tokenBank = new Bank <User>( database: mongoDatabase, currencyCollectionName: UserRepo.CollectionName, transactionLogCollectionName: "tokentransactions", u => u.Tokens, u => u.Id, clock: clock); tokenBank.AddReservedMoneyChecker( new PersistedReservedMoneyCheckers(mongoDatabase).AllDatabaseReservedTokens); return(new Databases ( UserRepo: userRepo, BadgeRepo: badgeRepo, PollRepo: new PollRepo(mongoDatabase, clock), PokeyenBank: pokeyenBank, TokensBank: tokenBank, CommandLogger: new CommandLogger(mongoDatabase, clock), MessagequeueRepo: new MessagequeueRepo(mongoDatabase), MessagelogRepo: new MessagelogRepo(mongoDatabaseMessagelog), LinkedAccountRepo: new LinkedAccountRepo(mongoDatabase, userRepo.Collection), SubscriptionLogRepo: new SubscriptionLogRepo(mongoDatabase), ModLogRepo: new ModLogRepo(mongoDatabase), ResponseCommandRepo: new ResponseCommandRepo(mongoDatabase) )); }
public void SetUpMongoClient() { CustomSerializers.RegisterAll(); // try to connect to a mongodb running on the default port _client = new MongoClient($"mongodb://localhost:27017/?replicaSet={ReplicaSetName}"); bool success = _client.ListDatabaseNamesAsync(CancellationToken.None).Wait(TimeSpan.FromSeconds(5)); if (!success) { throw new AssertionException( "Failed to connect to a local MongoDB instance running on the default port. " + "Please start a local MongoDB instance on the default port (27017), " + $"and make sure it is in replica set mode with a replica set named '{ReplicaSetName}'. " + "Alternatively, skip these tests using 'dotnet test --filter TestCategory!=IntegrationTest'"); } }
public static Databases SetUpRepositories(BaseConfig baseConfig) { IClock clock = SystemClock.Instance; CustomSerializers.RegisterAll(); IMongoClient mongoClient = new MongoClient(baseConfig.MongoDbConnectionUri); IMongoDatabase mongoDatabase = mongoClient.GetDatabase(baseConfig.MongoDbDatabaseName); IMongoDatabase mongoDatabaseMessagelog = mongoClient.GetDatabase(baseConfig.MongoDbDatabaseNameMessagelog); IUserRepo userRepo = new UserRepo( database: mongoDatabase, startingPokeyen: baseConfig.StartingPokeyen, startingTokens: baseConfig.StartingTokens); IMongoBadgeLogRepo badgeLogRepo = new BadgeLogRepo(mongoDatabase); IBadgeRepo badgeRepo = new BadgeRepo(mongoDatabase, badgeLogRepo, clock); badgeRepo.UserLostBadgeSpecies += async(_, args) => await userRepo.UnselectBadgeIfSpeciesSelected(args.UserId, args.Species); IBank <User> pokeyenBank = new Bank <User>( database: mongoDatabase, currencyCollectionName: UserRepo.CollectionName, transactionLogCollectionName: "pokeyentransactions", u => u.Pokeyen, u => u.Id, clock: clock); IBank <User> tokenBank = new Bank <User>( database: mongoDatabase, currencyCollectionName: UserRepo.CollectionName, transactionLogCollectionName: "tokentransactions", u => u.Tokens, u => u.Id, clock: clock); tokenBank.AddReservedMoneyChecker( new PersistedReservedMoneyCheckers(mongoDatabase).AllDatabaseReservedTokens); return(new Databases ( UserRepo: userRepo, BadgeRepo: badgeRepo, PokeyenBank: pokeyenBank, TokensBank: tokenBank, CommandLogger: new CommandLogger(mongoDatabase, clock), MessagequeueRepo: new MessagequeueRepo(mongoDatabase), MessagelogRepo: new MessagelogRepo(mongoDatabaseMessagelog) )); }