private IServiceProvider CreateServiceProvider(ICacheStore <CacheUser> userCache, IVersionedTable <CacheUser> userTable)
        {
            // Create the services collection.
            var services = new ServiceCollection();

            ServerLibInitializer.RegisterTypes(services, this.global.MakeTestConfiguration());

            // Mock the caches.
            var cachesMock = new Mock <ICaches>();

            cachesMock.SetupGet(c => c.Users).Returns(userCache);
            cachesMock.Setup(c => c.StoreForType <CacheUser>()).Returns(userCache);

            services.AddSingleton(cachesMock.Object);

            // Mock the database.
            var tablesMock = new Mock <ITables>();

            tablesMock.Setup(t => t.TableForType <CacheUser>()).Returns(userTable);
            tablesMock.Setup(t => t.TableForVersionedType <CacheUser>()).Returns(userTable);

            services.AddSingleton(tablesMock.Object);

            // Create the service provider and return.
            return(services.BuildServiceProvider());
        }
        private async Task <IServiceProvider> CreateServiceProvider()
        {
            // Create the services collection, and initialize the connector.
            var services = new ServiceCollection();

            ServerLibInitializer.RegisterTypes(services, this.global.MakeTestConfiguration());
            var serviceProvider = services.BuildServiceProvider();

            // Initialize the caches.
            await serviceProvider.GetService <ICaches>().InitializeAsync();

            return(serviceProvider);
        }
Beispiel #3
0
        private IVersionedTable <CacheUser> CreateMongoUserTable()
        {
            // Create the services collection, and initialize the connector.
            var services = new ServiceCollection();

            ServerLibInitializer.RegisterTypes(services, this.global.MakeTestConfiguration());
            var serviceProvider = services.BuildServiceProvider();

            // Create the class to test.
            var mongoTables = serviceProvider.GetService <ITables>();

            // Initialize the tables.
            //await mongoTables.InitializeAsync(new CancellationToken());
            return(mongoTables.TableForVersionedType <CacheUser>());
        }