コード例 #1
0
        public void TestPersistentLoadError()
        {
            const string key1 = "key1";
            const string key2 = "key2";
            const string val1 = "val1";

            string[] toWrite = new[]
            {
                "[NetworkTables Storage 3.0]",
                $"string \"{key1}\"=\"{val1}\"",
                $"boolean \"{key2}\"=invalid",
                ""
            };

            string fileName = "testfile.txt";

            if (File.Exists(fileName))
            {
                File.Delete(fileName);
            }

            File.WriteAllLines(fileName, toWrite);

            string[] errors = NtCore.LoadPersistent(fileName);

            Assert.That(errors.Length, Is.EqualTo(1));
            Assert.That(errors[0], Contains.Substring("3: unrecognized boolean value, not 'true' or 'false'"));
        }
コード例 #2
0
        public void TestLoadPersistent()
        {
            const string key1 = "key1";
            const string key2 = "key2";
            const string val1 = "val1";

            string[] toWrite = new[]
            {
                "[NetworkTables Storage 3.0]",
                $"string \"{key1}\"=\"{val1}\"",
                $"boolean \"{key2}\"=true",
                ""
            };

            string fileName = "testfile.txt";

            if (File.Exists(fileName))
            {
                File.Delete(fileName);
            }

            File.WriteAllLines(fileName, toWrite);

            string[] errors = NtCore.LoadPersistent(fileName);

            Assert.That(errors.Length, Is.EqualTo(0));

            var entries = CoreMethods.GetEntryInfo("", 0);

            Assert.That(entries.Count, Is.EqualTo(2));

            Assert.That(CoreMethods.GetEntryString(key1, ""), Is.EqualTo(val1));
            Assert.That(CoreMethods.GetEntryBoolean(key2, false), Is.EqualTo(true));
        }