private static void ConfigureRepositories(IServiceCollection services, bool useInMemoryDatabase, int hiloLargeIntervalSize, int hiloSmallIntervalSize) { if (useInMemoryDatabase) { services.AddSingleton <IIdGenerator>(HiLoIdGenerator.InMemoryHiloGIdGenerator( hiloLargeIntervalSize, hiloSmallIntervalSize, hiloSmallIntervalSize)); services.AddSingleton <IUnitOfWork, InMemoryUnitOfWork>(); services.AddSingleton <IAuthUserRepository, InMemoryAuthUserRepository>(); services.AddSingleton <IRoleRepository, InMemoryRoleRepository>(); services.AddSingleton <IAdminLogRepository, InMemoryAdminLogRepository>(); services.AddSingleton <IUserRepository, InMemoryUserRepository>(); services.AddSingleton <IGameRepository, InMemoryGameRepository>(); services.AddSingleton <IGameStateRepository, InMemoryGameStateRepository>(); } else { services.AddSingleton <IIdGenerator>(HiLoIdGenerator.DbHiloGIdGenerator( hiloLargeIntervalSize, hiloSmallIntervalSize, hiloSmallIntervalSize)); services.AddSingleton <IUnitOfWork, DbUnitOfWork>(); services.AddSingleton <IAuthUserRepository, DbAuthUserRepository>(); services.AddSingleton <IRoleRepository, DbRoleRepository>(); services.AddSingleton <IAdminLogRepository, DbAdminLogRepository>(); services.AddSingleton <IUserRepository, DbUserRepository>(); services.AddSingleton <IGameRepository, DbGameRepository>(); services.AddSingleton <IGameStateRepository, DbGameStateRepository>(); } }
public DbApiTester() { IdGenerator = HiLoIdGenerator.DbHiloGIdGenerator(1, 1, 1); UnitOfWork = new DbUnitOfWork(Clock, IdGenerator); RoleRepository = new DbRoleRepository(UnitOfWork); AuthUserRepository = new DbAuthUserRepository(RoleRepository, UnitOfWork); UserRepository = new DbUserRepository(UnitOfWork); GameRepository = new DbGameRepository(UnitOfWork); }
public void IdGeneratorTest() { var idGenerator = HiLoIdGenerator.InMemoryHiloGIdGenerator(3, 3, 3); MiscDatabase.Get.IdGenerationTable[0].AvailableId = 1; var idPool = idGenerator.ReservePool(1, 1, 1); idPool.Count().Should().Be(3); idPool.Next().Should().Be(1); idPool.Next().Should().Be(2); idPool.Count().Should().Be(1); idPool = idGenerator.ReservePool(2, 2, 2); idPool.Count().Should().Be(4); idPool.Next().Should().Be(3); idPool.Next().Should().Be(4); idPool.Next().Should().Be(5); idPool.Next().Should().Be(6); idPool.Count().Should().Be(0); }