Permalink
Browse files

make JsonSettings support native value

  • Loading branch information...
1 parent da074f7 commit 5cc07a121e3207f04c8005b83dd499a9b5086544 @suwatch suwatch committed Jan 14, 2013
@@ -55,24 +55,35 @@ public void ConstructorWithValuesTest()
[Fact]
public void SetGetValueTest()
{
- var value = new KeyValuePair<string, string>(Guid.NewGuid().ToString(), Guid.NewGuid().ToString());
+ 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);
- Assert.Equal(null, settings.GetValue(value.Key));
+ foreach (KeyValuePair<string, JToken> value in values)
+ {
+ Assert.Equal(null, settings.GetValue(value.Key));
- settings.SetValue(value.Key, value.Value);
+ settings.SetValue(value.Key, value.Value);
- Assert.Equal(value.Value, settings.GetValue(value.Key));
+ Assert.Equal(value.Value, settings.GetValue(value.Key));
+ }
}
[Fact]
public void SetGetValuesTest()
{
- var values = new Dictionary<string, string>
+ Random random = new Random((int)DateTime.Now.Ticks);
+ var values = new Dictionary<string, JToken>
{
{ Guid.NewGuid().ToString(), Guid.NewGuid().ToString() },
- { Guid.NewGuid().ToString(), Guid.NewGuid().ToString() },
- { 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);
@@ -83,7 +94,7 @@ public void SetGetValuesTest()
Assert.Equal(values.Count, settings.GetValues().Count());
- foreach (KeyValuePair<string, string> value in settings.GetValues())
+ foreach (KeyValuePair<string, JToken> value in settings.GetValues())
{
Assert.Equal(values[value.Key], value.Value);
}
@@ -93,7 +104,7 @@ public void SetGetValuesTest()
settings.SetValues(values);
- foreach (KeyValuePair<string, string> value in settings.GetValues())
+ foreach (KeyValuePair<string, JToken> value in settings.GetValues())
{
Assert.Equal(values[value.Key], value.Value);
}
@@ -102,15 +113,16 @@ public void SetGetValuesTest()
[Fact]
public void SetGetJObjectTest()
{
- var values = new Dictionary<string, string>
+ 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, string> value in values)
+ foreach (KeyValuePair<string, JToken> value in values)
{
json[value.Key] = value.Value;
}
@@ -123,9 +135,9 @@ public void SetGetJObjectTest()
Assert.Equal(values.Count, settings.GetValues().Count());
- foreach (KeyValuePair<string, string> value in settings.GetValues())
+ foreach (KeyValuePair<string, JToken> value in settings.GetValues())
{
- Assert.Equal(json[value.Key].Value<string>(), value.Value);
+ Assert.Equal(json[value.Key], value.Value);
}
}
@@ -37,13 +37,13 @@ public string GetValue(string key)
return Read().Value<string>(key);
}
- public IEnumerable<KeyValuePair<string, string>> GetValues()
+ public IEnumerable<KeyValuePair<string, JToken>> GetValues()
{
var dict = (IDictionary<string, JToken>)Read();
- return dict.ToDictionary(pair => pair.Key, pair => pair.Value.Value<string>());
+ return dict.ToDictionary(pair => pair.Key, pair => pair.Value);
}
- public void SetValue(string key, string value)
+ public void SetValue(string key, JToken value)
{
JObject json = Read();
json[key] = value;
@@ -55,16 +55,16 @@ public void SetValues(JObject values)
JObject json = Read();
foreach (KeyValuePair<string, JToken> pair in values)
{
- json[pair.Key] = pair.Value.Value<string>();
+ json[pair.Key] = pair.Value;
}
Save(json);
}
- public void SetValues(IEnumerable<KeyValuePair<string, string>> values)
+ public void SetValues(IEnumerable<KeyValuePair<string, JToken>> values)
{
JObject json = Read();
- foreach (KeyValuePair<string, string> pair in values)
+ foreach (KeyValuePair<string, JToken> pair in values)
{
json[pair.Key] = pair.Value;
}
@@ -981,13 +981,13 @@ public void HangProcessTest()
// Otherwise process and its child will be terminated
appManager.SettingsManager.SetValue(SettingsKeys.CommandIdleTimeout, "10").Wait();
- // This HangProcess repo spew out activity at 2s, 4s, 6s and 20s respectively
+ // This HangProcess repo spew out activity at 2s, 4s, 6s and 30s respectively
// we should receive the one < 10s and terminate otherwise.
GitDeploymentResult result = appManager.GitDeploy(repo.PhysicalPath);
Assert.Contains("remote: Sleep(2000)", result.GitTrace);
Assert.Contains("remote: Sleep(4000)", result.GitTrace);
Assert.Contains("remote: Sleep(6000)", result.GitTrace);
- Assert.DoesNotContain("remote: Sleep(20000)", result.GitTrace);
+ Assert.DoesNotContain("remote: Sleep(30000)", result.GitTrace);
Assert.Contains("remote: Process 'starter.cmd' aborted due to idle timeout.", result.GitTrace);
});
}
@@ -89,7 +89,7 @@ public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, o
if (_enableTrace)
{
var settings = new JsonSettings(Path.Combine(_environment.DiagnosticsPath, Constants.SettingsJsonFile));
- settings.SetValue(AzureDriveEnabledKey, "true");
+ settings.SetValue(AzureDriveEnabledKey, true);
}
return result;
@@ -16,7 +16,7 @@ class TestRepositories
new TestRepositoryInfo("https://github.com/KuduApps/ConditionalCompilation.git", "a104578"),
new TestRepositoryInfo("https://github.com/KuduApps/CustomBuildScript.git", "2c156bd"),
new TestRepositoryInfo("https://github.com/KuduApps/CustomDeploymentSettingsTest.git", "66e15f2"),
- new TestRepositoryInfo("https://github.com/KuduApps/HangProcess.git", "2e53ab6"),
+ new TestRepositoryInfo("https://github.com/KuduApps/HangProcess.git", "dd426b2"),
new TestRepositoryInfo("https://github.com/KuduApps/HelloKudu.git", "2370e44"),
new TestRepositoryInfo("https://github.com/KuduApps/HelloWorld.git", "1f3dfd8"),
new TestRepositoryInfo("https://github.com/KuduApps/Mvc3Application_NoSolution.git", "4e36ca3"),

0 comments on commit 5cc07a1

Please sign in to comment.