Esempio n. 1
0
        public void GameLibraryIntegrationCreate_Test()
        {
            var path = new DirectoryInfo(Path.GetTempPath())
                       .CreateSubdirectory(Path.GetFileNameWithoutExtension(Path.GetTempFileName()));
            var fs  = new PhysicalFileSystem();
            var gfs = fs.GetOrCreateSubFileSystem(fs.ConvertPathFromInternal(path.FullName));

            var optionsBuilder = new DbContextOptionsBuilder <DatabaseContext>();

            optionsBuilder.UseSqlite($"Data Source={Path.GetTempFileName()}");
            var glib = new GameRecordLibrary(optionsBuilder);
            var gl   = new GameLibrary(glib);
            var game = gl.CreateGame("NINTENDO_NES");
        }
Esempio n. 2
0
        public async Task TestCopyInstaller_IntegrationTest()
        {
            using var testStream = TestUtilities.GetResource("TestRoms.test.nes");
            using var fileStream = File.Create(Path.GetTempFileName() + ".nes");
            await testStream.CopyToAsync(fileStream);

            string fname = fileStream.Name;

            fileStream.Dispose();

            var path = new DirectoryInfo(Path.GetTempPath())
                       .CreateSubdirectory(Path.GetFileNameWithoutExtension(Path.GetTempFileName()));
            var fs  = new PhysicalFileSystem();
            var gfs = fs.GetOrCreateSubFileSystem(fs.ConvertPathFromInternal(path.FullName));

            var optionsBuilder = new DbContextOptionsBuilder <DatabaseContext>();

            optionsBuilder.UseSqlite($"Data Source={Path.GetTempFileName()}");
            var glib = new GameRecordLibrary(optionsBuilder);
            var flib = new FileRecordLibrary(optionsBuilder);

            var gl = new GameLibrary(glib);

            gl.AddExtension <GameFileExtensionProvider, IGameFileExtension
                             >(new GameFileExtensionProvider(flib, gfs));

            var game = gl.CreateGame("NINTENDO_NES");

            var stone   = new StoneProvider();
            var install = new SingleFileCopyInstaller(stone);

            var installables = install.GetInstallables("NINTENDO_NES", new List <FileSystemInfo>()
            {
                new FileInfo(fname)
            });

            Assert.True(installables.Select(i => i.Source).All(i => i == install.Name));

            foreach (var i in installables)
            {
                await foreach (var res in install.Install(game, i.Artifacts))
                {
                }
            }

            Assert.NotEmpty(game.WithFiles().GetFileRecords());
        }
Esempio n. 3
0
        public async Task GameLibraryIntegrationQuery_Test()
        {
            var path = new DirectoryInfo(Path.GetTempPath())
                       .CreateSubdirectory(Path.GetFileNameWithoutExtension(Path.GetTempFileName()));
            var fs  = new PhysicalFileSystem();
            var gfs = fs.GetOrCreateSubFileSystem(fs.ConvertPathFromInternal(path.FullName));

            var optionsBuilder = new DbContextOptionsBuilder <DatabaseContext>();

            optionsBuilder.UseSqlite($"Data Source={Path.GetTempFileName()}");
            var glib = new GameRecordLibrary(optionsBuilder);
            var gl   = new GameLibrary(glib);
            var game = gl.CreateGame("NINTENDO_NES");

            Assert.NotEmpty(gl.QueryGames(g => g.PlatformID == "NINTENDO_NES"));
            Assert.NotEmpty(gl.GetGames(g => g.PlatformID == "NINTENDO_NES"));
            Assert.NotEmpty(gl.GetAllGames());
            Assert.NotNull(gl.GetGame(game.Record.RecordID));
        }
Esempio n. 4
0
        public void GameLibraryIntegrationConfig_Test()
        {
            var path = new DirectoryInfo(Path.GetTempPath())
                       .CreateSubdirectory(Path.GetFileNameWithoutExtension(Path.GetTempFileName()));
            var fs  = new PhysicalFileSystem();
            var gfs = fs.GetOrCreateSubFileSystem(fs.ConvertPathFromInternal(path.FullName));

            var optionsBuilder = new DbContextOptionsBuilder <DatabaseContext>();

            optionsBuilder.UseSqlite($"Data Source={Path.GetTempFileName()}");
            var glib = new GameRecordLibrary(optionsBuilder);
            var ccs  = new ConfigurationCollectionStore(optionsBuilder);

            var gl = new GameLibrary(glib);

            gl.AddExtension <IGameConfigurationExtensionProvider, IGameConfigurationExtension>
                (new GameConfigurationExtensionProvider(ccs));
            var game = gl.CreateGame("NINTENDO_NES");

            var profile = game.WithConfigurations()
                          .CreateNewProfile <ExampleConfigurationCollection>("TestConfiguration", "test");

            Assert.NotNull(game.WithConfigurations()
                           .GetProfile <ExampleConfigurationCollection>("TestConfiguration", "test"));

            Assert.NotEmpty(game.WithConfigurations().GetProfileNames());

            profile.Configuration.ExampleConfiguration.FullscreenResolution =
                Configuration.FullscreenResolution.Resolution1600X1050;
            gl.WithConfigurationLibrary().UpdateProfile(profile);
            var newProfile = game.WithConfigurations()
                             .GetProfile <ExampleConfigurationCollection>("TestConfiguration", "test");

            Assert.Equal(Configuration.FullscreenResolution.Resolution1600X1050,
                         newProfile.Configuration.ExampleConfiguration.FullscreenResolution);

            Assert.ThrowsAny <Exception>(() => game.WithConfigurations()
                                         .CreateNewProfile <ExampleConfigurationCollection>("TestConfiguration", "test"));

            game.WithConfigurations().DeleteProfile("TestConfiguration", "test");
            Assert.Empty(game.WithConfigurations().GetProfileNames());
        }
Esempio n. 5
0
        public void GameLibraryUnknownExtension_Test()
        {
            var path = new DirectoryInfo(Path.GetTempPath())
                       .CreateSubdirectory(Path.GetFileNameWithoutExtension(Path.GetTempFileName()));
            var fs  = new PhysicalFileSystem();
            var gfs = fs.GetOrCreateSubFileSystem(fs.ConvertPathFromInternal(path.FullName));

            var optionsBuilder = new DbContextOptionsBuilder <DatabaseContext>();

            optionsBuilder.UseSqlite($"Data Source={Path.GetTempFileName()}");
            var glib = new GameRecordLibrary(optionsBuilder);
            var ccs  = new ConfigurationCollectionStore(optionsBuilder);

            var gl = new GameLibrary(glib);

            Assert.Throws <KeyNotFoundException>(() => gl.GetExtension <IGameConfigurationExtensionProvider>());
            var game = gl.CreateGame("NINTENDO_NES");

            Assert.Throws <KeyNotFoundException>(() => game.GetExtension <IGameConfigurationExtension>());
        }
Esempio n. 6
0
        public void GameLibraryIntegrationUpdate_Test()
        {
            var path = new DirectoryInfo(Path.GetTempPath())
                       .CreateSubdirectory(Path.GetFileNameWithoutExtension(Path.GetTempFileName()));
            var fs  = new PhysicalFileSystem();
            var gfs = fs.GetOrCreateSubFileSystem(fs.ConvertPathFromInternal(path.FullName));

            var optionsBuilder = new DbContextOptionsBuilder <DatabaseContext>();

            optionsBuilder.UseSqlite($"Data Source={Path.GetTempFileName()}");
            var glib = new GameRecordLibrary(optionsBuilder);
            var flib = new FileRecordLibrary(optionsBuilder);

            var gl = new GameLibrary(glib);

            gl.AddExtension <GameFileExtensionProvider, IGameFileExtension
                             >(new GameFileExtensionProvider(flib, gfs));

            var game = gl.CreateGame("NINTENDO_NES");

            game.Record.Title = "My Awesome Game";
            gl.UpdateGameRecord(game.Record);

            var file = game.WithFiles().MiscRoot.OpenFile("Test.txt");

            file.OpenStream().Close();
            game.WithFiles().RegisterFile(file, "application/text");
            var record = game.WithFiles().GetFileInfo(file);

            record.Metadata.Add("file_metadata", "test");
            gl.GetExtension <GameFileExtensionProvider>().UpdateFile(record);

            var newGame = gl.GetGame(game.Record.RecordId);

            Assert.NotEmpty(newGame.WithFiles().Files);
        }