public void DeleteValueTest()
        {
            var value = new KeyValuePair<string, string>(Guid.NewGuid().ToString(), Guid.NewGuid().ToString());
            var settings = new JsonSettings(GetMockFileSystem(SettingsPath), SettingsPath);

            Assert.Equal(null, settings.GetValue(value.Key));

            settings.SetValue(value.Key, value.Value);
            Assert.Equal(value.Value, settings.GetValue(value.Key));

            // Delete existing value
            Assert.Equal(true, settings.DeleteValue(value.Key));

            Assert.Equal(null, settings.GetValue(value.Key));

            // Delete non-existing value
            Assert.False(settings.DeleteValue(value.Key));
        }
        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());
        }
        public void SetGetValueTest()
        {
            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 }
            };

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

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

                settings.SetValue(value.Key, value.Value);

                Assert.Equal(value.Value, settings.GetValue(value.Key));
            }
        }
Beispiel #4
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));
        }
Beispiel #5
0
        public void NullOrEmptyTest()
        {
            var key = Guid.NewGuid().ToString();
            FileSystemHelpers.Instance = GetMockFileSystem(SettingsPath);
            var settings = new JsonSettings(SettingsPath);

            Assert.Equal(null, settings.GetValue(key));

            settings.SetValue(key, String.Empty);
            Assert.Equal(String.Empty, settings.GetValue(key));

            settings.SetValue(key, null);
            Assert.Equal(null, settings.GetValue(key));
        }
        public void SetGetValueTest()
        {
            var value = new KeyValuePair<string, string>(Guid.NewGuid().ToString(), Guid.NewGuid().ToString());
            var settings = new JsonSettings(GetMockFileSystem(SettingsPath), SettingsPath);

            Assert.Equal(null, settings.GetValue(value.Key));

            settings.SetValue(value.Key, value.Value);

            Assert.Equal(value.Value, settings.GetValue(value.Key));
        }