public void ShouldInitializeRepositoriesWhenLoaded()
        {
            var context =
                new OneLaunchContextMock().WithUserSettings(new UserSettings()
            {
                Repositories =
                    new Dictionary <string, List <Repository> >()
                {
                    {
                        "REPO1", new List <Repository>()
                        {
                            new Repository()
                            {
                                Path = "Path1", Name = "Name1"
                            },
                            new Repository()
                            {
                                Path = "Path2", Name = "Name2"
                            }
                        }
                    },
                    {
                        "REPO2", new List <Repository>()
                        {
                            new Repository()
                            {
                                Path = "Path3", Name = "Name3"
                            },
                        }
                    }
                }
            });

            var vm = new SettingsViewViewModel()
            {
                Context = context
            };

            Assert.That(vm.Repositories, Has.Count.EqualTo(0));
            Assert.That(vm.SettingsChanged, Is.False);

            vm.LoadedCommand.Execute(null);

            WaitUtils.WaitFor(() => vm.Repositories.Count == 3, 10);

            // The repository dico should have been flatten
            Assert.That(vm.Repositories, Has.Count.EqualTo(3));
            AssertRepositoryViewModel(vm.Repositories[0], "REPO1", "Name1", "Path1");
            AssertRepositoryViewModel(vm.Repositories[1], "REPO1", "Name2", "Path2");
            AssertRepositoryViewModel(vm.Repositories[2], "REPO2", "Name3", "Path3");

            Assert.That(vm.SettingsChanged, Is.False);
        }
        public void ShouldInitializeLaunchersWhenLoaded()
        {
            var context =
                new OneLaunchContextMock().WithUserSettings(new UserSettings()
            {
                ExcludedLauncherFilePaths = new List <string>()
                {
                    "Path1",
                    "OldPath"     // This one does not exist any more (it's not part of the discovered launchers)
                }
            });

            var loader = new Mock <IConfigurationLoader>(MockBehavior.Strict);

            loader.Setup(mock => mock.DiscoverFiles(Environment.CurrentDirectory))
            .Returns(new[]
            {
                new DiscoveredLauncher()
                {
                    FilePath = "Path1"
                },                                                   // Is in the exclusion list, so will be excluded
                new DiscoveredLauncher()
                {
                    FilePath = "Path2"
                }                                                   // Is not in the list, so will be active
            })
            .Verifiable();

            var vm = new SettingsViewViewModel()
            {
                Context = context,
                Loader  = loader.Object
            };

            Assert.That(vm.Repositories, Has.Count.EqualTo(0));
            Assert.That(vm.SettingsChanged, Is.False);

            vm.LoadedCommand.Execute(null);

            WaitUtils.WaitFor(() => vm.Launchers.Count == 2, 10);

            // This file was excluded, according to the settings
            Assert.That(vm.Launchers[0].Path, Is.EqualTo("Path1"));
            Assert.That(vm.Launchers[0].Active, Is.False);

            // It was not in the user settings, so we'll suppose it's active
            Assert.That(vm.Launchers[1].Path, Is.EqualTo("Path2"));
            Assert.That(vm.Launchers[1].Active, Is.True);

            loader.VerifyAll();
        }
Example #3
0
        public void ShouldShowErrorWhenTheTemplateRepoCannotBeFoundInTheUserSettings()
        {
            var message = new Mock <IMessageService>(MockBehavior.Strict);

            message
            .Setup(mock => mock.ShowErrorMessage("Unable to find repo type UNKNOWN in config file MyDocs/OneLauncher/UserSettings.json"))
            .Verifiable();

            var loader = new Mock <IXmlLauncherConfigurationReader>(MockBehavior.Strict);

            loader
            .Setup(mock => mock.LoadFile(It.IsAny <string>())).Returns(new XmlLauncherConfiguration()
            {
                RepoType = "UNKNOWN", GenericTemplate = new XmlLauncherNode()
            })
            .Verifiable();

            var context = new OneLaunchContextMock()
            {
                UserSettings = new UserSettings()
                {
                    Repositories = new Dictionary <string, List <Repository> >() // No repo, so "UNKNOWN" repo type won't be found
                },
                ApplicationSettings = new ApplicationSettings()
                {
                    UserSettingsDirectory = "MyDocs/OneLauncher",
                    UserSettingsFileName  = "UserSettings.json"
                }
            };
            var processor = new XmlLauncherConfigurationProcessor()
            {
                MessageService = message.Object, ConfigurationReader = loader.Object, Context = context
            };

            Assert.That(processor.Load("").ToList(), Has.Count.EqualTo(0));

            message.VerifyAll();
        }
Example #4
0
        public void ShouldInitializeLaunchersWhenLoaded(bool defaultSettings)
        {
            var settings = new Mock <ISettingsView>(MockBehavior.Strict);

            // When the settings are the default ones, it means it's the first time the app is launched
            // We'll open the settings view, before the load is completed, to let the user defines his repositories location
            if (defaultSettings)
            {
                settings
                .Setup(mock => mock.ShowDialog())
                .Returns(true)
                .Verifiable();
            }

            var containerBuilder = new ContainerBuilder();

            containerBuilder.RegisterInstance(settings.Object).As <ISettingsView>();

            using (ContainerOverrider.Override(containerBuilder.Build()))
            {
                var launchersNodes = new[] { new LaunchersNode()
                                             {
                                                 Header = "Header1"
                                             } };

                var loader = new Mock <IConfigurationLoader>(MockBehavior.Strict);
                loader
                .Setup(mock => mock.LoadConfiguration(Environment.CurrentDirectory))
                .Returns(launchersNodes)
                .Verifiable();

                var context = new OneLaunchContextMock().WithUserSettings(new UserSettings()
                {
                    IsDefaultSettings = defaultSettings
                });

                var vm = new OneLauncherViewModel()
                {
                    ConfigurationLoader = loader.Object,
                    Context             = context
                };

                var builder  = new Mock <IRadialMenuItemBuilder>(MockBehavior.Strict);
                var menuItem = new RadialMenuItem();
                builder
                .Setup(mock => mock.BuildMenuItems(It.IsIn <IEnumerable <LaunchersNode> >(launchersNodes), It.IsIn(vm)))
                .Returns(new[] { menuItem })
                .Verifiable();

                vm.RadialMenuItemBuilder = builder.Object;

                // As long as the load is not completed, the VM should maintain the view closed
                Assert.That(vm.IsOpened, Is.False);

                var initialLaunchers = vm.Launchers;
                Assert.That(initialLaunchers, Has.Count.EqualTo(0));

                vm.LoadedCommand.Execute(null);

                WaitUtils.WaitFor(() => vm.IsOpened, 10, 1);

                Assert.That(vm.Launchers, Has.Count.EqualTo(1));
                Assert.That(vm.Launchers[0], Is.SameAs(menuItem));

                // Now it should be opened
                Assert.That(vm.IsOpened, Is.True);

                loader.VerifyAll();
                builder.VerifyAll();
                settings.VerifyAll();
            }
        }