Beispiel #1
0
        public void ConstructorTest()
        {
            IFileSystem fileSystem = GetMockFileSystem(SettingsPath);

            var settings = new JsonSettings(SettingsPath);

            Assert.Equal(null, settings.GetValue("non_existing"));

            Assert.Equal(0, settings.GetValues().Count());

            Assert.False(settings.DeleteValue("non_existing"));

            Assert.False(FileSystemHelpers.FileExists(SettingsPath));
        }
        public void ConstructorWithValuesTest()
        {
            var values = new[]
            {
                new KeyValuePair<string, string>(Guid.NewGuid().ToString(), Guid.NewGuid().ToString()),
                new KeyValuePair<string, string>(Guid.NewGuid().ToString(), Guid.NewGuid().ToString())
            };

            var settings = new JsonSettings(GetMockFileSystem(SettingsPath, values), SettingsPath);

            foreach (KeyValuePair<string, string> value in values)
            {
                Assert.Equal(value.Value, settings.GetValue(value.Key));
            }

            Assert.Equal(null, settings.GetValue("non_existing"));

            Assert.Equal(values.Length, settings.GetValues().Count());
        }
Beispiel #3
0
        public void SetGetValuesTest()
        {
            Random random = new Random((int)DateTime.Now.Ticks);
            var values = new Dictionary<string, JToken>
            {
                { Guid.NewGuid().ToString(), Guid.NewGuid().ToString() },
                { Guid.NewGuid().ToString(), random.Next() },
                { Guid.NewGuid().ToString(), random.Next() % 2 == 0 }
            };

            FileSystemHelpers.Instance = GetMockFileSystem(SettingsPath);

            var settings = new JsonSettings(SettingsPath);

            Assert.Equal(0, settings.GetValues().Count());

            settings.SetValues(values);

            Assert.Equal(values.Count, settings.GetValues().Count());

            foreach (KeyValuePair<string, JToken> value in settings.GetValues())
            {
                Assert.Equal(values[value.Key], value.Value);
            }

            // Update
            values[values.Keys.ElementAt(0)] = Guid.NewGuid().ToString();

            settings.SetValues(values);

            foreach (KeyValuePair<string, JToken> value in settings.GetValues())
            {
                Assert.Equal(values[value.Key], value.Value);
            }
        }
Beispiel #4
0
        public void SetGetJObjectTest()
        {
            var values = new Dictionary<string, JToken>
            {
                { Guid.NewGuid().ToString(), null },
                { Guid.NewGuid().ToString(), String.Empty },
                { Guid.NewGuid().ToString(), Guid.NewGuid().ToString() }
            };

            JObject json = new JObject();
            foreach (KeyValuePair<string, JToken> value in values)
            {
                json[value.Key] = value.Value;
            }

            FileSystemHelpers.Instance = GetMockFileSystem(SettingsPath);

            var settings = new JsonSettings(SettingsPath);

            Assert.Equal(0, settings.GetValues().Count());

            settings.SetValues(json);

            Assert.Equal(values.Count, settings.GetValues().Count());

            foreach (KeyValuePair<string, JToken> value in settings.GetValues())
            {
                Assert.Equal(json[value.Key], value.Value);
            }
        }
        public void SetGetValuesTest()
        {
            var values = new Dictionary<string, string>
            {
                { Guid.NewGuid().ToString(), Guid.NewGuid().ToString() },
                { Guid.NewGuid().ToString(), Guid.NewGuid().ToString() },
                { Guid.NewGuid().ToString(), Guid.NewGuid().ToString() }
            };

            var settings = new JsonSettings(GetMockFileSystem(SettingsPath), SettingsPath);

            Assert.Equal(0, settings.GetValues().Count());

            settings.SetValues(values);

            Assert.Equal(values.Count, settings.GetValues().Count());

            foreach (KeyValuePair<string, string> value in settings.GetValues())
            {
                Assert.Equal(values[value.Key], value.Value);
            }

            // Update
            values[values.Keys.ElementAt(0)] = Guid.NewGuid().ToString();

            settings.SetValues(values);

            foreach (KeyValuePair<string, string> value in settings.GetValues())
            {
                Assert.Equal(values[value.Key], value.Value);
            }
        }
Beispiel #6
0
        public void SetGetJObjectTest()
        {
            Random random = new Random((int)DateTime.Now.Ticks);
            var values = new Dictionary<string, JToken>
            {
                { Guid.NewGuid().ToString(), null },
                { Guid.NewGuid().ToString(), String.Empty },
                { Guid.NewGuid().ToString(), Guid.NewGuid().ToString() }
            };

            JObject json = new JObject();
            foreach (KeyValuePair<string, JToken> value in values)
            {
                json[value.Key] = value.Value;
            }

            var settings = new JsonSettings(GetMockFileSystem(SettingsPath), SettingsPath);

            Assert.Equal(0, settings.GetValues().Count());

            settings.SetValues(json);

            Assert.Equal(values.Count, settings.GetValues().Count());

            foreach (KeyValuePair<string, JToken> value in settings.GetValues())
            {
                Assert.Equal(json[value.Key], value.Value);
            }
        }