public void LoadConfiguration_ShouldLoadString()
        {
            var testString = "test_string_to_save";

            _iniParser.Read(nameof(ImmutableConfiguration), nameof(ImmutableConfiguration.TestString)).Returns(testString);

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

            result.TestString.Should().Be(testString);
        }
Esempio n. 2
0
        public void LoadConfiguration_ShouldLoadString()
        {
            var testString = "test_string_to_save";

            _iniParser.Read(AttributeWithOnlySectionReadTestConfigurationConstants.TestStringSection, nameof(AttributeWithOnlySectionReadTestConfiguration.TestString)).Returns(testString);

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

            _iniParser.Received(1).Read(AttributeWithOnlySectionReadTestConfigurationConstants.TestStringSection, nameof(AttributeWithOnlySectionReadTestConfiguration.TestString));
            result.TestString.Should().Be(testString);
        }
        public void LoadConfiguration_ShouldSaveCorrectLoadString()
        {
            var testString = "test_string_to_save";

            _iniParser.Read(AttributeReadTestConfigurationConstants.TestStringSection, AttributeReadTestConfigurationConstants.TestStringKey).Returns(testString);
            var result = _iniWrapper.LoadConfiguration <AttributeReadTestConfiguration>();

            _iniParser.Received(1).Read(AttributeReadTestConfigurationConstants.TestStringSection, AttributeReadTestConfigurationConstants.TestStringKey);
            result.TestString.Should().Be(testString);
        }
Esempio n. 4
0
        public void LoadConfiguration_CorrectReadIntIntIReadonlyDictionary()
        {
            _iniParser.Read(nameof(ReadonlyCollectionsConfiguration.IReadonlyDictionary), null).Returns("1=1\02=2\03=3");
            var expected = new Dictionary <int, int>
            {
                [1] = 1,
                [2] = 2,
                [3] = 3
            };

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

            result.IReadonlyDictionary.Should().BeEquivalentTo(expected);
        }
Esempio n. 5
0
        public void LoadConfiguration_ShouldThrow_WhenWrongFormattedIntIsInFile()
        {
            _iniParser.Read(nameof(TestConfigurationField), nameof(TestConfigurationField.TestInt)).Returns("wrong_formatted_int");

            Action result = () => _iniWrapper.LoadConfiguration<TestConfigurationField>();

            result.Should().Throw<IniWrongFormatException>();
        }
Esempio n. 6
0
        public void LoadConfiguration_CorrectEnumOutOfRange()
        {
            _iniParser.Read(nameof(TestConfiguration), nameof(TestConfiguration.TestEnum)).Returns("1000");

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

            result.TestEnum.Should().Be((TestEnum)1000);
        }
Esempio n. 7
0
        public void LoadConfiguration_ShouldHaveCorrectDefaultValues()
        {
            var result = _iniWrapper.LoadConfiguration <DefaultValuesConfiguration>();

            result.DefaultInt.Should().Be(DefaultValuesConfigurationConsts.DefaultInt);
            result.DefaultString.Should().Be(DefaultValuesConfigurationConsts.DefaultString);
            result.DefaultList.Should().BeEquivalentTo(new List <int> {
                10, 11, 12, 13
            });
        }
        public void LoadConfiguration_CorrectReadNullableIntList()
        {
            _iniParser.Read(nameof(NullableIEnumerableConfiguration), nameof(NullableIEnumerableConfiguration.NullableIntList)).Returns("1,2,3,4,5,6,7,8");
            var expected = new List <int?> {
                1, 2, 3, 4, 5, 6, 7, 8
            };

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

            result.NullableIntList.Should().BeEquivalentTo(expected);
        }
Esempio n. 9
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);
        }
        public void LoadConfiguration_ShouldLoadListOfComplexType()
        {
            var testString = "xteststring";

            _iniParser.Read($"{nameof(TestConfigurationField)}_0", nameof(TestConfigurationField.TestInt)).Returns("20");
            _iniParser.Read($"{nameof(TestConfigurationField)}_0", nameof(TestConfigurationField.TestChar)).Returns("x");
            _iniParser.Read($"{nameof(TestConfigurationField)}_0", nameof(TestConfigurationField.TestEnum)).Returns("Five");
            _iniParser.Read($"{nameof(TestConfigurationField)}_0", nameof(TestConfigurationField.TestString)).Returns(testString);
            _iniParser.Read($"{nameof(TestConfigurationField)}_0", nameof(TestConfigurationField.TestIntList)).Returns("10,20,30,40");
            _iniParser.Read($"{nameof(TestConfigurationField)}_0", nameof(TestConfigurationField.TestStringList)).Returns("10aa,xxx20,3www0,40ddd");

            var testString1 = "sdasdaoiu2mn2k";

            _iniParser.Read($"{nameof(TestConfigurationField)}_1", nameof(TestConfigurationField.TestInt)).Returns("25");
            _iniParser.Read($"{nameof(TestConfigurationField)}_1", nameof(TestConfigurationField.TestChar)).Returns("y");
            _iniParser.Read($"{nameof(TestConfigurationField)}_1", nameof(TestConfigurationField.TestEnum)).Returns("Four");
            _iniParser.Read($"{nameof(TestConfigurationField)}_1", nameof(TestConfigurationField.TestString)).Returns(testString1);
            _iniParser.Read($"{nameof(TestConfigurationField)}_1", nameof(TestConfigurationField.TestIntList)).Returns("101,202,303,404");
            _iniParser.Read($"{nameof(TestConfigurationField)}_1", nameof(TestConfigurationField.TestStringList)).Returns("10sssaa,xxxrer20,3rewrwwww0,40erwreddd");

            _iniParser.Read($"{nameof(TestConfigurationField)}_0", null).Returns(x => "notEmptySectionResult");
            _iniParser.Read($"{nameof(TestConfigurationField)}_1", null).Returns(x => "notEmptySectionResult");

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

            result.TestConfigurations.Should().HaveCount(2);

            result.TestConfigurations.ElementAt(0).TestInt.Should().Be(20);
            result.TestConfigurations.ElementAt(0).TestChar.Should().Be('x');
            result.TestConfigurations.ElementAt(0).TestEnum.Should().Be(TestEnum.Five);
            result.TestConfigurations.ElementAt(0).TestString.Should().Be(testString);
            result.TestConfigurations.ElementAt(0).TestIntList.Should().BeEquivalentTo(new List <int> {
                10, 20, 30, 40
            });
            result.TestConfigurations.ElementAt(0).TestStringList.Should().BeEquivalentTo(new List <string> {
                "10aa", "xxx20", "3www0", "40ddd"
            });


            result.TestConfigurations.ElementAt(1).TestInt.Should().Be(25);
            result.TestConfigurations.ElementAt(1).TestChar.Should().Be('y');
            result.TestConfigurations.ElementAt(1).TestEnum.Should().Be(TestEnum.Four);
            result.TestConfigurations.ElementAt(1).TestString.Should().Be(testString1);
            result.TestConfigurations.ElementAt(1).TestIntList.Should().BeEquivalentTo(new List <int> {
                101, 202, 303, 404
            });
            result.TestConfigurations.ElementAt(1).TestStringList.Should().BeEquivalentTo(new List <string> {
                "10sssaa", "xxxrer20", "3rewrwwww0", "40erwreddd"
            });
        }
        public void LoadConfiguration_ShouldLoadGuid()
        {
            var configuration = new GuidConfiguration()
            {
                Guid = Guid.NewGuid(),
                Uri  = new Uri("http://testttt.com/")
            };

            _iniParser.Read(nameof(GuidConfiguration), nameof(GuidConfiguration.Guid)).Returns(configuration.Guid.ToString());
            _iniParser.Read(nameof(GuidConfiguration), nameof(GuidConfiguration.Uri)).Returns(configuration.Uri.ToString());

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

            result.Guid.Should().Be(configuration.Guid);
            result.Uri.Should().Be(configuration.Uri);
        }
Esempio n. 12
0
        public void LoadConfiguration_ShouldLoadDateTimeAndTimeSpan()
        {
            var dateTime       = new DateTime(2019, 02, 07, 18, 58, 58);
            var timeSpan       = new TimeSpan(10, 10, 10);
            var datetimeOffset = new DateTimeOffset(2019, 02, 07, 18, 58, 10, TimeSpan.FromMinutes(20));

            _iniParser.Read(nameof(TimeConfiguration), nameof(TimeConfiguration.DateTime)).Returns(dateTime.ToString("O"));
            _iniParser.Read(nameof(TimeConfiguration), nameof(TimeConfiguration.TimeSpan)).Returns(timeSpan.ToString());
            _iniParser.Read(nameof(TimeConfiguration), nameof(TimeConfiguration.DateTimeOffset)).Returns(datetimeOffset.ToString());

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

            result.DateTime.Should().Be(dateTime);
            result.TimeSpan.Should().Be(timeSpan);
            result.DateTimeOffset.Should().Be(datetimeOffset);
        }
Esempio n. 13
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);
            });
        }
        public void LoadConfiguration_ShouldLoadCorrectIEnumerableOfNullableComplexType()
        {
            var config = new ListOfComplexDataNullableConfiguration()
            {
                TestConfigurations = new List <NullableConfiguration>()
                {
                    new NullableConfiguration
                    {
                        TestNullableChar = 'x',
                        TestNullableEnum = TestEnum.Five,
                        TestNullableInt  = null,
                        TestNullableUint = 10,
                    },
                    new NullableConfiguration
                    {
                        TestNullableChar = 'y',
                        TestNullableEnum = TestEnum.Three,
                        TestNullableInt  = 100,
                        TestNullableUint = null,
                    },
                }
            };

            _iniParser.Read($"{nameof(NullableConfiguration)}_0", null).Returns("notEmpty");
            _iniParser.Read($"{nameof(NullableConfiguration)}_0", nameof(NullableConfiguration.TestNullableChar)).Returns("x");
            _iniParser.Read($"{nameof(NullableConfiguration)}_0", nameof(NullableConfiguration.TestNullableEnum)).Returns("5");
            _iniParser.Read($"{nameof(NullableConfiguration)}_0", nameof(NullableConfiguration.TestNullableInt)).Returns("");
            _iniParser.Read($"{nameof(NullableConfiguration)}_0", nameof(NullableConfiguration.TestNullableUint)).Returns("10");

            _iniParser.Read($"{nameof(NullableConfiguration)}_1", null).Returns("notEmpty");
            _iniParser.Read($"{nameof(NullableConfiguration)}_1", nameof(NullableConfiguration.TestNullableChar)).Returns("y");
            _iniParser.Read($"{nameof(NullableConfiguration)}_1", nameof(NullableConfiguration.TestNullableEnum)).Returns("3");
            _iniParser.Read($"{nameof(NullableConfiguration)}_1", nameof(NullableConfiguration.TestNullableInt)).Returns("100");
            _iniParser.Read($"{nameof(NullableConfiguration)}_1", nameof(NullableConfiguration.TestNullableUint)).Returns("");

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

            result.Should().BeEquivalentTo(config);
        }
Esempio n. 15
0
        public void LoadConfiguration_ShouldLoadCorrectComplexType()
        {
            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
                    }
                }
            };

            _iniParser.Read(nameof(TestConfiguration), nameof(TestConfiguration.TestString)).Returns(testString);
            _iniParser.Read(nameof(TestConfiguration), nameof(TestConfiguration.TestChar)).Returns(config.TestConfiguration.TestChar.ToString());
            _iniParser.Read(nameof(TestConfiguration), nameof(TestConfiguration.TestInt)).Returns(config.TestConfiguration.TestInt.ToString());
            _iniParser.Read(nameof(TestConfiguration), nameof(TestConfiguration.TestUint)).Returns(config.TestConfiguration.TestUint.ToString());
            _iniParser.Read(nameof(TestConfiguration), nameof(TestConfiguration.TestUintList)).Returns("1,2,3,4");
            _iniParser.Read(nameof(TestConfiguration), nameof(TestConfiguration.TestUintIList)).Returns("1,2,3,4");

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


            result.TestConfiguration.TestChar.Should().Be(config.TestConfiguration.TestChar);
            result.TestConfiguration.TestStringList.Should().BeEquivalentTo(config.TestConfiguration.TestStringList);
            result.TestConfiguration.TestEnum.Should().Be(config.TestConfiguration.TestEnum);
            result.TestConfiguration.TestEnumList.Should().BeEquivalentTo(config.TestConfiguration.TestEnumList);
            result.TestConfiguration.TestInt.Should().Be(config.TestConfiguration.TestInt);
            result.TestConfiguration.TestUint.Should().Be(config.TestConfiguration.TestUint);
            result.TestConfiguration.TestUintList.Should().BeEquivalentTo(config.TestConfiguration.TestUintList);
            result.TestConfiguration.TestUintIList.Should().BeEquivalentTo(config.TestConfiguration.TestUintList);
            result.TestConfiguration.TestString.Should().Be(config.TestConfiguration.TestString);
            result.TestConfiguration.TestIntList.Should().BeEquivalentTo(config.TestConfiguration.TestIntList);
        }
Esempio n. 16
0
        public void ShouldThrow_WhenConfigurationIsWithoutParameterlessConstructor_And_WithoutIniConstructorAttribute()
        {
            Action loading = () => _iniWrapper.LoadConfiguration <ConfigurationWithoutParameterlessCtorAndAttribute>();

            loading.Should().Throw <MissingMethodException>().WithMessage($"Please provide parameterless constructor or decorate constructor with IniConstructorAttribute attribute for type {typeof(ConfigurationWithoutParameterlessCtorAndAttribute)}.");
        }
Esempio n. 17
0
 public void IniWrapperRead()
 {
     _iniWrapper.LoadConfiguration <ConfigurationBenchmark>();
 }
Esempio n. 18
0
 public object ParseReadValue(string readValue, Type destinationType, IniContext iniContext)
 {
     return(_iniWrapper.LoadConfiguration(destinationType));
 }