public void ToJson()
        {
            MOCK_ConfigurationDump((IntPtr config, ref IntPtr json, ref int jsonsize, int resvars, int indent) =>
            {
                Assert.Equal(pointer, config);
                Assert.Equal(1, resvars);
                Assert.Equal(-1, indent);
                json     = validJsonBytes;
                jsonsize = validJsonSize;
                return((int)Yogi.ErrorCode.Ok);
            });

            Assert.Equal(5, cfg.ToJson()["x"]);

            MOCK_ConfigurationDump((IntPtr config, ref IntPtr json, ref int jsonsize, int resvars, int indent) =>
            {
                Assert.Equal(pointer, config);
                Assert.Equal(0, resvars);
                Assert.Equal(-1, indent);
                json     = validJsonBytes;
                jsonsize = validJsonSize;
                return((int)Yogi.ErrorCode.Ok);
            });

            Assert.Equal(5, cfg.ToJson(false)["x"]);
        }
Example #2
0
        public void UpdateFromJson()
        {
            var cfg = new Yogi.Configuration();

            cfg.UpdateFromJson("{\"age\": 42}");
            Assert.Equal(42, (int)cfg.ToJson()["age"]);
            cfg.UpdateFromJson(JObject.Parse("{\"age\": 88}"));
            Assert.Equal(88, (int)cfg.ToJson()["age"]);
        }
Example #3
0
        public void ToJson()
        {
            var cfg = new Yogi.Configuration(Yogi.ConfigurationFlags.DisableVariables);

            cfg.UpdateFromJson("{\"age\": 42}");

            Assert.Throws <Yogi.FailureException>(() => cfg.ToJson(true));

            Assert.Equal(42, (int)cfg.ToJson()["age"]);
        }
Example #4
0
        public void UpdateFromCommandLine()
        {
            var cfg = new Yogi.Configuration();

            cfg.UpdateFromCommandLine(new[] { "exe", "-o", "{\"age\": 25}" },
                                      Yogi.CommandLineOptions.Overrides);
            Assert.Equal(25, (int)cfg.ToJson()["age"]);

            cfg.UpdateFromCommandLine(new List <string> {
                "exe", "-o", "{\"age\": 18}"
            },
                                      Yogi.CommandLineOptions.Overrides);
            Assert.Equal(18, (int)cfg.ToJson()["age"]);
        }
Example #5
0
        public void UpdateFromFile()
        {
            var filename = Path.Combine(tempDir, "cfg.json");

            File.WriteAllText(filename, "{\"age\": 66}");

            var cfg = new Yogi.Configuration();

            cfg.UpdateFromFile(filename);

            Assert.Equal(66, (int)cfg.ToJson()["age"]);
        }