public void SaveConfiguration_ShouldSaveCorrectComplexType()
        {
            var testString = "test_string_to_save";
            var config     = new ComplexTestConfiguration()
            {
                TestConfiguration = new TestConfiguration()
                {
                    TestString   = testString,
                    TestChar     = 'T',
                    TestInt      = 10,
                    TestUint     = 100u,
                    TestUintList = new List <uint>()
                    {
                        1, 2, 3, 4
                    }
                }
            };

            _iniWrapper.SaveConfiguration(config);

            _iniParser.Received(1).Write(nameof(TestConfiguration), nameof(TestConfiguration.TestString), testString);
            _iniParser.Received(1).Write(nameof(TestConfiguration), nameof(TestConfiguration.TestChar), config.TestConfiguration.TestChar.ToString());
            _iniParser.Received(1).Write(nameof(TestConfiguration), nameof(TestConfiguration.TestInt), config.TestConfiguration.TestInt.ToString());
            _iniParser.Received(1).Write(nameof(TestConfiguration), nameof(TestConfiguration.TestUint), config.TestConfiguration.TestUint.ToString());
            _iniParser.Received(1).Write(nameof(TestConfiguration), nameof(TestConfiguration.TestUintList), "1,2,3,4");
        }
        public void SaveConfiguration_ShouldThrowException_WhenKeyInDictionaryConfigurationHasCollectionOfComplexType()
        {
            var config = new KeyInDictionaryOfComplexDataConfiguration();

            Action saveConfiguration = () => _iniWrapper.SaveConfiguration(config);

            saveConfiguration.Should().Throw <CollectionOfComplexTypeException>();
        }
Esempio n. 3
0
        public void SaveConfiguration_ShouldSaveCorrectWriteString()
        {
            var testString = "test_string_to_save";
            var config     = new AttributeWithOnlyKeyTestConfiguration()
            {
                TestString = testString,
            };

            _iniWrapper.SaveConfiguration(config);
            _iniParser.Received(1).Write(nameof(AttributeWithOnlyKeyTestConfiguration), AttributeWithOnlyKeyTestConfiguration.Key, testString);
        }
        public void SaveConfiguration_ShouldSaveCorrectWriteString()
        {
            var testString = "test_string_to_save";
            var config     = new TestConfigurationField()
            {
                TestString = testString,
            };

            _iniWrapper.SaveConfiguration(config);
            _iniParser.Received(1).Write(nameof(TestConfigurationField), nameof(TestConfigurationField.TestString), testString);
        }
        public void SaveConfiguration_ShouldSaveCorrectWriteString()
        {
            var testString = "test_string_to_save";
            var config     = new AttributeTestConfiguration()
            {
                TestString = testString,
            };

            _iniWrapper.SaveConfiguration(config);
            _iniParser.Received(1).Write(AttributeTestConfigurationConstants.Section, AttributeTestConfigurationConstants.Key, testString);
        }
        public void SaveConfiguration_ShouldSaveCorrectWriteIntIntDictionary()
        {
            var config = new DictionaryConfiguration()
            {
                IntsDictionary = new Dictionary <int, int>()
                {
                    [1] = 2,
                    [2] = 3
                }
            };

            _iniWrapper.SaveConfiguration(config);
            _iniParser.Received(1).Write(nameof(DictionaryConfiguration.IntsDictionary), "1", "2");
            _iniParser.Received(1).Write(nameof(DictionaryConfiguration.IntsDictionary), "2", "3");
        }
Esempio n. 7
0
        public void SaveConfiguration_ShouldIgnoreNullsForString()
        {
            var config = new NullIEnumerableConfiguration()
            {
                TestStringList = new List <string>()
                {
                    "a", "b", null, "c", null, "d", "f"
                }
            };

            _iniWrapper.SaveConfiguration(config);

            _iniParser.Received(1).Write(nameof(NullIEnumerableConfiguration), nameof(NullIEnumerableConfiguration.TestStringList), "a,b,c,d,f");
            _iniParser.Received(1).Write(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>());
        }
Esempio n. 8
0
        public ReadBenchmark()
        {
            Directory.CreateDirectory(TestDirectory);
            _rawIniParser = new IniParser($"{TestDirectory}rawBenchmark.ini", BufferSize);
            _iniWrapper   = new IniWrapperFactory().CreateWithDefaultIniParser(x =>
            {
                x.IniFilePath = $"{TestDirectory}benchmark.ini";
                x.DefaultIniWrapperBufferSize = BufferSize;
            });

            _configurationBenchmark = new ConfigurationBenchmark()
            {
                Test        = 10,
                Age         = 20,
                Description = "TestDescription",
                ListInt     = new List <int>()
                {
                    1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16
                },
                InnerConfiguration = new InnerConfiguration()
                {
                    Description = "Description1234",
                    Age         = 100
                }
            };

            _iniWrapper.SaveConfiguration(_configurationBenchmark);
        }
        public void SaveConfiguration_ShouldSaveCorrectDefaultValues()
        {
            _iniWrapper.SaveConfiguration(new DefaultValuesConfiguration());

            _iniParser.Received(1).Write(nameof(DefaultValuesConfiguration), nameof(DefaultValuesConfiguration.DefaultInt), DefaultValuesConfigurationConsts.DefaultInt.ToString());
            _iniParser.Received(1).Write(nameof(DefaultValuesConfiguration), nameof(DefaultValuesConfiguration.DefaultString), DefaultValuesConfigurationConsts.DefaultString);
            _iniParser.Received(1).Write(nameof(DefaultValuesConfiguration), nameof(DefaultValuesConfiguration.DefaultList), DefaultValuesConfigurationConsts.DefaultList);
        }
Esempio n. 10
0
        public void SaveConfiguration_ShouldIgnoreEveryProperty_WithIngoreAttribute()
        {
            var config = new IgnoreAttributeTestConfiguration();

            _iniWrapper.SaveConfiguration(config);

            _iniParser.Received(0).Write(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>());
        }
Esempio n. 11
0
        public void SaveConfiguration_ShouldSaveCorrectWriteNullableInt()
        {
            var config = new NullableConfiguration()
            {
                TestNullableInt = 10,
            };

            _iniWrapper.SaveConfiguration(config);
            _iniParser.Received(1).Write(nameof(NullableConfiguration), nameof(NullableConfiguration.TestNullableInt), "10");
        }
Esempio n. 12
0
        public void SaveConfiguration_ShouldIgnoreNullsForStringValues()
        {
            var config = new NullStringDictionaryConfiguration()
            {
                ValueStringDictionary = new Dictionary <int, string>()
                {
                    [10] = "test",
                    [20] = null,
                    [25] = "test2"
                }
            };

            _iniWrapper.SaveConfiguration(config);
            _iniParser.Received(1).Write(nameof(NullStringDictionaryConfiguration.ValueStringDictionary), "10", "test");
            _iniParser.Received(1).Write(nameof(NullStringDictionaryConfiguration.ValueStringDictionary), "25", "test2");

            _iniParser.Received(2).Write(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>());
        }
Esempio n. 13
0
        public void SaveConfiguration_ShouldSaveListOfComplexType()
        {
            var config = new ListOfComplexDataConfiguration()
            {
                TestConfigurations = new List <TestConfiguration>()
                {
                    new TestConfiguration()
                    {
                        TestInt        = 100,
                        TestChar       = 'x',
                        TestEnum       = TestEnum.One,
                        TestStringList = new List <string> {
                            "sda", "sda"
                        },
                        TestString = "teststring"
                    },
                    new TestConfiguration()
                    {
                        TestInt        = 200,
                        TestChar       = 'u',
                        TestEnum       = TestEnum.Three,
                        TestStringList = new List <string> {
                            "sdaxxxxxxxx", "sda23223232"
                        },
                        TestString = "teststringsadxxx"
                    },
                }
            };

            _iniWrapper.SaveConfiguration(config);

            _iniParser.Received(1).Write($"{nameof(TestConfiguration)}_0", nameof(TestConfiguration.TestInt), "100");
            _iniParser.Received(1).Write($"{nameof(TestConfiguration)}_0", nameof(TestConfiguration.TestChar), "x");
            _iniParser.Received(1).Write($"{nameof(TestConfiguration)}_0", nameof(TestConfiguration.TestEnum), "1");
            _iniParser.Received(1).Write($"{nameof(TestConfiguration)}_0", nameof(TestConfiguration.TestStringList), "sda,sda");
            _iniParser.Received(1).Write($"{nameof(TestConfiguration)}_0", nameof(TestConfiguration.TestString), "teststring");

            _iniParser.Received(1).Write($"{nameof(TestConfiguration)}_1", nameof(TestConfiguration.TestInt), "200");
            _iniParser.Received(1).Write($"{nameof(TestConfiguration)}_1", nameof(TestConfiguration.TestChar), "u");
            _iniParser.Received(1).Write($"{nameof(TestConfiguration)}_1", nameof(TestConfiguration.TestEnum), "3");
            _iniParser.Received(1).Write($"{nameof(TestConfiguration)}_1", nameof(TestConfiguration.TestStringList), "sdaxxxxxxxx,sda23223232");
            _iniParser.Received(1).Write($"{nameof(TestConfiguration)}_1", nameof(TestConfiguration.TestString), "teststringsadxxx");
        }
Esempio n. 14
0
 private void Window_Closing(object sender, CancelEventArgs e)
 {
     // 本来最後に自身の設定ファイルを保存するが
     // settings.iniを開いていた場合、編集が反映されないので
     // 保存後に編集結果で上書きする
     iniWrapper.SaveConfiguration(DataContext);
     if (SaveCancel())
     {
         e.Cancel = true;
     }
 }
        public void SaveConfiguration_ShouldSaveCorrectWriteDateTime_And_TimeSpan()
        {
            var config = new GuidConfiguration()
            {
                Guid = Guid.NewGuid(),
                Uri  = new Uri("http://testttt.com/")
            };

            _iniWrapper.SaveConfiguration(config);
            _iniParser.Received(1).Write(nameof(GuidConfiguration), nameof(GuidConfiguration.Guid), config.Guid.ToString());
            _iniParser.Received(1).Write(nameof(GuidConfiguration), nameof(GuidConfiguration.Uri), config.Uri.ToString());
        }
Esempio n. 16
0
        public MainWindow()
        {
            InitializeComponent();

            var exePath      = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName);
            var settingsPath = Path.Combine(exePath, "settings.ini");

            var iniSettings = new IniSettings()
            {
                IniFilePath = settingsPath,
            };

            iniWrapper = new IniWrapperFactory().CreateWithDefaultIniParser(iniSettings);

            if (!File.Exists(settingsPath))
            {
                File.WriteAllText(settingsPath, ";this file is IniEditor settings file.");
                iniWrapper.SaveConfiguration(new ViewModel());
            }

            DataContext = iniWrapper.LoadConfiguration <ViewModel>();

            // 強調表示
            textEditor.SyntaxHighlighting = LoadHighlightingDefinition("AvalonEdit.ini.xshd");

            // 折り畳み
            foldingManager = FoldingManager.Install(textEditor.TextArea);
            // 2秒おきに折り畳みチェック(微妙な気がするがサンプルがそうなっている)
            var foldingTimer = new DispatcherTimer {
                Interval = TimeSpan.FromSeconds(2)
            };

            foldingTimer.Tick += (s, e)
                                 => foldingStrategy.UpdateFoldings(foldingManager, textEditor.Document);
            foldingTimer.Start();

            // コード補完
            textEditor.TextArea.TextEntering += TextArea_TextEntering;
            textEditor.TextArea.TextEntered  += TextArea_TextEntered;


            textEditor.Options = new TextEditorOptions
            {
                AllowScrollBelowDocument = true,
                HighlightCurrentLine     = true,
            };

            vm.FilePath = settingsPath;
            textEditor.Load(vm.FilePath);
        }
Esempio n. 17
0
        public void SaveConfiguration_ShouldSaveCorrectWriteDateTime_And_TimeSpan()
        {
            var config = new TimeConfiguration()
            {
                DateTime       = new DateTime(2019, 02, 07, 18, 58, 58),
                TimeSpan       = new TimeSpan(10, 10, 10),
                DateTimeOffset = new DateTimeOffset(2019, 02, 07, 18, 58, 10, TimeSpan.FromMinutes(20))
            };

            _iniWrapper.SaveConfiguration(config);

            _iniParser.Received(1).Write(nameof(TimeConfiguration), nameof(TimeConfiguration.DateTime), config.DateTime.ToString("O"));
            _iniParser.Received(1).Write(nameof(TimeConfiguration), nameof(TimeConfiguration.TimeSpan), config.TimeSpan.ToString());
            _iniParser.Received(1).Write(nameof(TimeConfiguration), nameof(TimeConfiguration.DateTimeOffset), config.DateTimeOffset.ToString());
        }
Esempio n. 18
0
        public void Save_And_LoadConfiguration_ShouldBeInverseFunctions()
        {
            var fixture       = new Fixture();
            var customization = new SupportMutableValueTypesCustomization();

            customization.Customize(fixture);

            var configuration = fixture.Create <MainConfiguration>();

            _iniWrapper.SaveConfiguration(configuration);

            var result = _iniWrapper.LoadConfiguration <MainConfiguration>();

            result.Should().BeEquivalentTo(configuration, options =>
            {
                options.ComparingByMembers <TestConfiguration>();
                options.ComparingByMembers <TestConfigurationField>();
                options.ComparingByMembers <DictionaryConfigurationField>();
                return(options);
            });
        }
Esempio n. 19
0
 public void IniWrapperWrite()
 {
     _iniWrapper.SaveConfiguration(_configurationBenchmark);
 }
Esempio n. 20
0
 public IniValue FormatToWrite(object objectToFormat, IniContext iniContext)
 {
     _iniWrapper.SaveConfiguration(objectToFormat);
     return(null);
 }