public void EnumeratePort_Test()
        {
            var optionsBuilder = new DbContextOptionsBuilder <DatabaseContext>();

            optionsBuilder.UseSqlite($"Data Source={Path.GetTempFileName()}");
            IEmulatedPortStore store = new EmulatedPortStore(optionsBuilder);
            var orch = new Mock <IEmulatorOrchestrator>();

            orch.SetupGet(p => p.Name).Returns("Test");
            var device       = new Mock <IInputDevice>();
            var instanceGuid = Guid.NewGuid();

            device.SetupGet(p => p.InstanceGuid).Returns(instanceGuid);


            var instance = new Mock <IInputDeviceInstance>();

            instance.SetupGet(p => p.Driver).Returns(InputDriver.Passthrough);
            instance.SetupGet(p => p.NameEnumerationIndex).Returns(0);

            store.SetPort(orch.Object, "TEST_PLATFORM", 0, "TEST_CONTROLLER", device.Object.InstanceGuid, instance.Object.Driver, Guid.NewGuid());
            store.SetPort(orch.Object, "TEST_PLATFORM", 2, "TEST_CONTROLLER", device.Object.InstanceGuid, instance.Object.Driver, Guid.NewGuid());

            var ret = store.EnumeratePorts(orch.Object, "TEST_PLATFORM");

            Assert.Equal(2, ret.Count());
        }
        public void Compose(IModule module, Loader.IServiceRepository serviceContainer)
        {
            var    physicalFs       = serviceContainer.Get <IFileSystem>();
            var    contentDirectory = serviceContainer.Get <IContentDirectoryProvider>();
            string sqlitePath       = Path.Combine(contentDirectory.ApplicationData.FullName, "library.db");
            var    optionsBuilder   = new DbContextOptionsBuilder <DatabaseContext>();

            optionsBuilder
            .UseSqlite($"Data Source={sqlitePath}");

            using (var context = new DatabaseContext(optionsBuilder.Options))
            {
                var connection = context.Database.GetDbConnection();
                connection.Open();
                using var command   = connection.CreateCommand();
                command.CommandText = "PRAGMA journal_mode=WAL;";
                command.ExecuteNonQuery();
            }

            // game library dependency tree

            var gameRecordLibrary = new GameRecordLibrary(optionsBuilder);
            var gameLibrary       = new GameLibrary(gameRecordLibrary);
            var configStore       = new ConfigurationCollectionStore(optionsBuilder);

            var fileLibrary = new FileRecordLibrary(optionsBuilder);

            var appDataPath = physicalFs.ConvertPathFromInternal(contentDirectory.ApplicationData.FullName);
            var gameFs      = physicalFs.GetOrCreateSubFileSystem(appDataPath / "games");

            // Add default extensions
            gameLibrary.AddExtension <IGameFileExtensionProvider,
                                      IGameFileExtension>(new GameFileExtensionProvider(fileLibrary, gameFs));

            gameLibrary.AddExtension <IGameConfigurationExtensionProvider,
                                      IGameConfigurationExtension>(new GameConfigurationExtensionProvider(configStore));

            // register game library.
            serviceContainer.Get <IServiceRegistrationProvider>()
            .RegisterService <IGameLibrary>(gameLibrary);

            var pluginLibrary = new PluginConfigurationStore(optionsBuilder);

            // plugin config store

            serviceContainer.Get <IServiceRegistrationProvider>()
            .RegisterService <IPluginConfigurationStore>(pluginLibrary);

            // controller elements

            var inputStore = new ControllerElementMappingProfileStore(optionsBuilder);

            serviceContainer.Get <IServiceRegistrationProvider>()
            .RegisterService <IControllerElementMappingProfileStore>(inputStore);

            // ports
            var portStore = new EmulatedPortStore(optionsBuilder);

            serviceContainer.Get <IServiceRegistrationProvider>()
            .RegisterService <IEmulatedPortStore>(portStore);
        }