Beispiel #1
0
        public void RaceConfigurationPresets_Test()
        {
            RaceConfigurationPresets cfgPresets = new RaceConfigurationPresets(".");

            var configs = cfgPresets.GetConfigurations();

            Assert.AreEqual(2, configs.Count);
            Assert.IsTrue(configs.ContainsKey("DSV Erwachsene"));
            Assert.IsTrue(configs.ContainsKey("FIS Rennen Men"));

            // Create new Config
            var newConfig = new RaceConfiguration(configs["FIS Rennen Men"]);

            newConfig.Runs = 3;
            cfgPresets.SaveConfiguration("FIS Rennen - neu", newConfig);
            Assert.AreEqual(3, configs.Count);
            Assert.IsTrue(configs.ContainsKey("DSV Erwachsene"));
            Assert.IsTrue(configs.ContainsKey("FIS Rennen Men"));
            Assert.IsTrue(configs.ContainsKey("FIS Rennen - neu"));

            // Delete a config
            cfgPresets.DeleteConfiguration("FIS Rennen Men");
            Assert.AreEqual(2, configs.Count);
            Assert.IsTrue(configs.ContainsKey("DSV Erwachsene"));
            Assert.IsTrue(configs.ContainsKey("FIS Rennen - neu"));
            Assert.AreEqual(3, cfgPresets.GetConfigurations()["FIS Rennen - neu"].Runs);

            // Create new Config with unsafe name
            var newConfig2 = new RaceConfiguration(configs["DSV Erwachsene"]);

            newConfig.Runs = 3;
            cfgPresets.SaveConfiguration(@"abc\*:;? 123", newConfig);
            Assert.AreEqual(3, configs.Count);
            Assert.IsTrue(configs.ContainsKey("DSV Erwachsene"));
            Assert.IsTrue(configs.ContainsKey(@"abc; 123"));
            Assert.IsTrue(configs.ContainsKey("FIS Rennen - neu"));
        }
        private void btnTemplateSave_Click(object sender, RoutedEventArgs e)
        {
            RaceConfiguration newConfig = new RaceConfiguration();

            StoreConfigurationSelectionUI(ref newConfig);

            // Ask for the name to store
            string configName = string.Empty;

            if (cmbTemplate.SelectedValue is CBItem selected && selected.Value is string selConfigName)
            {
                configName = selConfigName;
            }

            RaceConfigurationSaveDlg dlg = new RaceConfigurationSaveDlg(configName);

            dlg.ShowDialog();
            if (dlg.TemplateName == null)
            {
                return;
            }

            configName = dlg.TemplateName;

            if (_raceConfigurationPresets.GetConfigurations().ContainsKey(configName))
            {
                var res = MessageBox.Show(string.Format("Die Konfiguration \"{0}\" existiert schon. Wollen Sie die Konfiguration überschreiben?", configName), "Konfiguration speichern", MessageBoxButton.YesNo, MessageBoxImage.Question);
                if (res == MessageBoxResult.No)
                {
                    return;
                }
            }

            _raceConfigurationPresets.SaveConfiguration(configName, newConfig);
            refreshConfigPresetsUI();
        }