示例#1
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);
            }
        }
示例#2
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);
            }
        }
示例#3
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());
        }
示例#5
0
 public HttpResponseMessage GetAll()
 {
     return(Request.CreateResponse(HttpStatusCode.OK, _settings.GetValues()));
 }