Exemple #1
0
        public void ShouldLinkRelease()
        {
            // setup
            var env         = new TestEnvironment(Logger);
            var gameManager = env.Locator.GetService <IGameManager>();

            // test
            gameManager.Initialize();
            var game = gameManager.Games[0];

            TestVpdbApi.GetAbraCaDabraDetails().Subscribe(release =>
            {
                gameManager.LinkRelease(game, release, TestVpdbApi.AbraCaDabraV20FileId);

                // assert
                game.HasRelease.Should().BeTrue();
            });
        }
Exemple #2
0
        public TestEnvironment(ILogger logger = null)
        {
            _locator = new ModernDependencyResolver();

            var abracadabra = Menu.Games[0];
            var mm          = Menu.Games[1];

            //--------------------------------------------------------------------------
            // Fixtures
            //--------------------------------------------------------------------------


            // IMarshallManager
            MarshallManager.Setup(m => m.ParseIni(PinballXIniPath)).Returns(GetPinballXIni(_ini));
            MarshallManager.Setup(m => m.UnmarshallPlatformDatabase(VisualPinballDatabaseJsonPath)).Returns(new PlatformDatabase());
            MarshallManager.Setup(m => m.UnmarshallPlatformDatabase(FuturePinballDatabaseJsonPath)).Returns(new PlatformDatabase());
            MarshallManager.Setup(m => m.UnmarshallXml(Path.GetFileName(VisualPinballDatabaseXmlPath))).Returns(Menu);
            _locator.RegisterLazySingleton(() => MarshallManager.Object, typeof(IMarshallManager));

            // IFileSystemWatcher
            FileSystemWatcher.Setup(f => f.FileWatcher(PinballXIniPath)).Returns(PinballXIniWatcher);
            //FileSystemWatcher.Setup(f => f.DatabaseWatcher(It.IsAny<string>(), It.IsAny<IList<PinballXSystem>>())).Returns(DatabaseWatcher);
            //FileSystemWatcher.Setup(f => f.TablesWatcher(It.IsAny<IList<PinballXSystem>>())).Returns(TableWatcher);
            _locator.RegisterLazySingleton(() => FileSystemWatcher.Object, typeof(IFileSystemWatcher));

            // ISettingsManager
            SettingsManager.Setup(s => s.Settings).Returns(Settings);
            SettingsManager.Setup(s => s.ApiAuthenticated).Returns(ApiAuthenticated);
            _locator.RegisterLazySingleton(() => SettingsManager.Object, typeof(ISettingsManager));

            // IDatabaseManager
            _locator.RegisterLazySingleton(() => DatabaseManager.Object, typeof(IDatabaseManager));

            // VPDB API
            VpdbApi.Setup(api => api.GetReleasesBySize(TestVpdbApi.AbraCaDabraV20FileSize, GameItemViewModel.MatchThreshold)).Returns(TestVpdbApi.GetAbraCaDabraIdentify());
            VpdbApi.Setup(api => api.GetRelease(TestVpdbApi.AbraCaDabraReleaseId)).Returns(TestVpdbApi.GetAbraCaDabraDetails());

            // IVpdbClient
            VpdbClient.Setup(v => v.UserChannel).Returns(UserChannel);
            VpdbClient.Setup(v => v.Api).Returns(VpdbApi.Object);
            _locator.RegisterLazySingleton(() => VpdbClient.Object, typeof(IVpdbClient));

            // IVisualPinballManager
            _locator.RegisterLazySingleton(() => VisualPinballManager.Object, typeof(IVisualPinballManager));

            // IFile, IDirectory
            Directory.Setup(d => d.Exists(VisualPinballDatabasePath)).Returns(true);
            Directory.Setup(d => d.GetFiles(VisualPinballDatabasePath)).Returns(new[] { Path.GetFileName(VisualPinballDatabaseXmlPath) });
            File.Setup(f => f.Exists(Path.Combine(VisualPinballTablePath, abracadabra.Filename + ".vpt"))).Returns(true);
            File.Setup(f => f.FileSize(Path.Combine(VisualPinballTablePath, abracadabra.Filename + ".vpt"))).Returns(TestVpdbApi.AbraCaDabraV20FileSize);
            File.Setup(f => f.Exists(Path.Combine(VisualPinballTablePath, mm.Filename + ".vpx"))).Returns(true);
            File.Setup(f => f.FileSize(Path.Combine(VisualPinballTablePath, mm.Filename + ".vpx"))).Returns(10002);
            _locator.RegisterLazySingleton(() => File.Object, typeof(IFile));
            _locator.RegisterLazySingleton(() => Directory.Object, typeof(IDirectory));

            // Logging
            _locator.RegisterLazySingleton(() => logger ?? LogManager.GetCurrentClassLogger(), typeof(ILogger));
            _locator.RegisterLazySingleton(() => new Mock <CrashManager>(_locator.GetService <ILogger>()).Object, typeof(CrashManager));

            // IThreadManager
            _locator.RegisterLazySingleton(() => new TestThreadManager(), typeof(IThreadManager));


            //--------------------------------------------------------------------------
            // Real (non-mocked) services start here. Those are the tested ones.
            //--------------------------------------------------------------------------


            // IVersionManager
            _locator.RegisterLazySingleton(() => new VersionManager(
                                               _locator.GetService <CrashManager>(),
                                               _locator.GetService <ILogger>()
                                               ), typeof(IVersionManager));

            // IMessageManager
            _locator.RegisterLazySingleton(() => new MessageManager(
                                               _locator.GetService <IDatabaseManager>(),
                                               _locator.GetService <CrashManager>()
                                               ), typeof(IMessageManager));

            // IRealtimeManager
            _locator.RegisterLazySingleton(() => new RealtimeManager(
                                               _locator.GetService <IVpdbClient>(),
                                               _locator.GetService <ILogger>()
                                               ), typeof(IRealtimeManager));

            // IJobManager
            _locator.RegisterLazySingleton(() => new JobManager(
                                               _locator.GetService <IDatabaseManager>(),
                                               _locator.GetService <IMessageManager>(),
                                               _locator.GetService <ILogger>(),
                                               _locator.GetService <CrashManager>()
                                               ), typeof(IJobManager));

            // IMenuManager
            _locator.RegisterLazySingleton(() => new PinballX.MenuManager(
                                               _locator.GetService <IFileSystemWatcher>(),
                                               _locator.GetService <ISettingsManager>(),
                                               _locator.GetService <IMarshallManager>(),
                                               _locator.GetService <IThreadManager>(),
                                               _locator.GetService <IFile>(),
                                               _locator.GetService <IDirectory>(),
                                               _locator.GetService <ILogger>()), typeof(IMenuManager));

            // IPlatformManager
            _locator.RegisterLazySingleton(() => new Application.PlatformManager(
                                               _locator.GetService <IMenuManager>(),
                                               _locator.GetService <IThreadManager>(),
                                               _locator.GetService <ILogger>(),
                                               _locator
                                               ), typeof(IPlatformManager));

            // IDownloadManager
            _locator.RegisterLazySingleton(() => new DownloadManager(
                                               _locator.GetService <IPlatformManager>(),
                                               _locator.GetService <IJobManager>(),
                                               _locator.GetService <IVpdbClient>(),
                                               _locator.GetService <ISettingsManager>(),
                                               _locator.GetService <IMessageManager>(),
                                               _locator.GetService <IDatabaseManager>(),
                                               _locator.GetService <ILogger>(),
                                               _locator.GetService <CrashManager>()
                                               ), typeof(IDownloadManager));

            // IGameManager
            _locator.RegisterLazySingleton(() => new Application.GameManager(
                                               _locator.GetService <IMenuManager>(),
                                               _locator.GetService <IVpdbClient>(),
                                               _locator.GetService <ISettingsManager>(),
                                               _locator.GetService <IDownloadManager>(),
                                               _locator.GetService <IDatabaseManager>(),
                                               _locator.GetService <IVersionManager>(),
                                               _locator.GetService <IPlatformManager>(),
                                               _locator.GetService <IMessageManager>(),
                                               _locator.GetService <IRealtimeManager>(),
                                               _locator.GetService <IVisualPinballManager>(),
                                               _locator.GetService <IThreadManager>(),
                                               _locator.GetService <IFile>(),
                                               _locator.GetService <ILogger>()
                                               ), typeof(IGameManager));
        }