コード例 #1
0
        public async Task WriteAsync_ShouldWriteFileToNonExistingFolder()
        {
            var file = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "test", "tmp.unit-test-file_0.ini");

            var doc = GenerateIniObject(GenerateIniDocument(1));
            await doc.WriteAsync(file);

            await IniDocument.WriteAsync(file, "Alien", "kind", "log jaw");

            var sec = await IniDocument.ReadSectionAsync(file, "Person");

            Assert.Collection(sec.Properties(),
                              s => Assert.Equal("FirstName", s.Key),
                              s => Assert.Equal("LastName", s.Key),
                              s => Assert.Equal("Age", s.Key));

            sec = await IniDocument.ReadSectionAsync(file, "Alien");

            Assert.Collection(sec.Properties(),
                              s => Assert.Equal("kind", s.Key));
            Assert.Collection(sec.Properties(),
                              s => Assert.Equal("log jaw", s.Value));

            File.Delete(file);
            Assert.False(File.Exists(file));
            Directory.Delete(Path.GetDirectoryName(file));
            Assert.False(Directory.Exists(Path.GetDirectoryName(file)));
        }
コード例 #2
0
        public async Task WriteAsync_GivenGivenExistingFileAndExistingSectionAndExistingPropertyWithDifferentValueDontUpdateProperty_ShouldAddPropertyAsync()
        {
            var file = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "tmp.unit-test-file_7.ini");

            var doc = GenerateIniObject(GenerateIniDocument(1));
            await doc.WriteAsync(file);

            //Assert.True(File.Exists(file));
            //Assert.True(new FileInfo(file).Length > 0);

            await IniDocument.WriteAsync(file, "Person", "Age", "90");

            //Assert.True(File.Exists(file));

            var sec = await IniDocument.ReadSectionAsync(file, "Person");

            Assert.Collection(sec.Properties(),
                              s => Assert.Equal("FirstName", s.Key),
                              s => Assert.Equal("LastName", s.Key),
                              s => Assert.Equal("Age", s.Key),
                              s => Assert.Equal("Age", s.Key));

            File.Delete(file);
            Assert.False(File.Exists(file));
        }
コード例 #3
0
        public async Task ReadSection_ShouldReadSectionIfItExistsAsync()
        {
            var createFile = await CreateIniFileAsync();

            Assert.True(createFile.success);
            Assert.True(createFile.path.IsValidFile());

            var section = await IniDocument.ReadSectionAsync(createFile.path, "Animal");

            Assert.Equal("Animal", section.Name);

            File.Delete(createFile.path);
            Assert.False(File.Exists(createFile.path));
        }