示例#1
0
        public async Task GameLibraryIntegrationConfigAsync_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 = await gl.CreateGameAsync("NINTENDO_NES");

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

            var profileGuid = profile.CollectionGuid;

            Assert.NotNull(await game.WithConfigurations()
                           .GetProfileAsync <ExampleConfigurationCollection>("TestConfiguration", profileGuid));

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

            profile.Configuration.ExampleConfiguration.FullscreenResolution =
                Configuration.FullscreenResolution.Resolution1600X1050;
            await gl.WithConfigurationLibrary().UpdateProfileAsync(profile);

            var newProfile = await game.WithConfigurations()
                             .GetProfileAsync <ExampleConfigurationCollection>("TestConfiguration", profileGuid);

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

            await game.WithConfigurations().DeleteProfileAsync("TestConfiguration", profileGuid);

            Assert.Empty(game.WithConfigurations().GetProfileNames());
        }