Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions dot-net/Centroid.Tests/ConfigTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.IO;
using System.Text.RegularExpressions;
using Microsoft.CSharp.RuntimeBinder;
Expand Down Expand Up @@ -168,9 +168,9 @@ public void test_enumerated_json_object_values_are_still_shiny()
}
}";
dynamic config = new Config(json);
foreach (var kvp in config.Connections)
foreach (var kvp in config.Connections)
{
Assert.That(kvp.Value.Password, Is.EqualTo("secret"));
Assert.That(kvp.Value.Password, Is.EqualTo("secret"));
}
}

Expand Down Expand Up @@ -215,5 +215,13 @@ public void test_contains_key()
Assert.That(config.ContainsKey("theEnvironment"), Is.True);
Assert.That(config.ContainsKey("DoesNotExist"), Is.False);
}

[Test]
public void test_key_as_index()
{
dynamic config = new Config(JsonConfig);
var myString = "thekey";
Assert.That(config.theEnvironment[myString], Is.EqualTo("TheValue"));
}
}
}
5 changes: 4 additions & 1 deletion dot-net/Centroid.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_AROUND_MULTIPLICATIVE_OP/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_WITHIN_SINGLE_LINE_ARRAY_INITIALIZER_BRACES/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/STICK_COMMENT/@EntryValue">False</s:Boolean>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=TypesAndNamespaces/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String></wpf:ResourceDictionary>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=TypesAndNamespaces/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EAddAccessorOwnerDeclarationBracesMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateThisQualifierSettings/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
8 changes: 7 additions & 1 deletion dot-net/Centroid/Config.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Dynamic;
Expand Down Expand Up @@ -35,6 +35,12 @@ public object this[int index]
set { RawConfig[index] = value; }
}

public object this[string index]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is object the right return type here? You'd have to do some kind of type manipulation with the result, which would make it less fluent...

Copy link
Copy Markdown
Contributor Author

@pdenny pdenny Oct 12, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason this returns an object is to mimic this[int index].

{
get { return GetValue(index); }
set { RawConfig[index] = value; }
}

public bool ContainsKey(string key)
{
return GetActualKey(key) != null;
Expand Down
10 changes: 9 additions & 1 deletion python/tests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import unittest
import json
import os.path
from centroid import Config

class ConfigTest(unittest.TestCase):
Expand All @@ -14,7 +15,7 @@ def _json_config_with_array(self):

@property
def _shared_file_path(self):
return 'config.json'
return os.path.normpath('../config.json')
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably roll this back, since the rakefile calls the test from the root directory instead of the test directory.


def test_create_from_string(self):
config = Config(self._json_config)
Expand Down Expand Up @@ -132,3 +133,10 @@ def test_has_key(self):
config = Config(self._json_config)
self.assertTrue("the_environment" in config)
self.assertTrue("does_not_exist" not in config)

def test_key_as_index(self):
config = Config(self._json_config)
my_string = "thekey"
self.assertEqual(config.the_environment[my_string], "TheValue")

unittest.main()
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like I should remove unittest.main() as I was running python without the -m option that the rakefile calls it with.

67 changes: 37 additions & 30 deletions ruby/test/centroid_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def json_config_with_array
end

def shared_file_path
'config.json'
File.join('..','..','config.json')
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably roll this back, since the rakefile calls the test from the root directory instead of the test directory.

end

def test_create_from_string
Expand Down Expand Up @@ -95,35 +95,6 @@ def test_environment_specific_config_overrides_all
assert_equal(config.shared, "production!")
end

def test_all_environment_is_not_case_sensitive
config = Centroid::Config.new('{"Prod": {"Shared": "production!"}, "All": {"Shared": "none", "AllOnly": "works"}}')
config = config.for_environment("Prod")
assert_equal(config.all_only, "works")

config = Centroid::Config.new('{"Prod": {"Shared": "production!"}, "all": {"Shared": "none", "AllOnly": "works"}}')
config = config.for_environment("Prod")
assert_equal(config.all_only, "works")
end

def test_supports_deep_merge
config = Centroid::Config.new('{"Prod": {"Database": {"Server": "prod-sql"}}, "All": {"Database": {"MigrationsPath": "path/to/migrations"}}}')
config = config.for_environment("Prod")
assert_equal(config.database.server, "prod-sql")
assert_equal(config.database.migrations_path, "path/to/migrations")
end

def test_has_key
config = Centroid::Config.new(json_config)
assert(config.has_key?("the_environment"))
assert(!config.has_key?("does_not_exist"))
end

def test_respond_to
config = Centroid::Config.new(json_config)
assert(config.respond_to?(:the_environment))
assert(!config.respond_to?(:does_not_exist))
end

def test_indexing_json_array
config = Centroid::Config.new(json_config_with_array)
assert_equal(config.the_array[0].the_key, "Value1")
Expand Down Expand Up @@ -169,4 +140,40 @@ def test_enumerated_json_object_values_are_still_shiny
assert_equal(v.password, "secret")
end
end

def test_all_environment_is_not_case_sensitive
config = Centroid::Config.new('{"Prod": {"Shared": "production!"}, "All": {"Shared": "none", "AllOnly": "works"}}')
config = config.for_environment("Prod")
assert_equal(config.all_only, "works")

config = Centroid::Config.new('{"Prod": {"Shared": "production!"}, "all": {"Shared": "none", "AllOnly": "works"}}')
config = config.for_environment("Prod")
assert_equal(config.all_only, "works")
end

def test_supports_deep_merge
config = Centroid::Config.new('{"Prod": {"Database": {"Server": "prod-sql"}}, "All": {"Database": {"MigrationsPath": "path/to/migrations"}}}')
config = config.for_environment("Prod")
assert_equal(config.database.server, "prod-sql")
assert_equal(config.database.migrations_path, "path/to/migrations")
end

def test_has_key
config = Centroid::Config.new(json_config)
assert(config.has_key?("the_environment"))
assert(!config.has_key?("does_not_exist"))
end

def test_key_as_index
config = Centroid::Config.new(json_config)
my_string = "thekey"
assert_equal(config.the_environment[my_string], "TheValue")
end

def test_respond_to
config = Centroid::Config.new(json_config)
assert(config.respond_to?(:the_environment))
assert(!config.respond_to?(:does_not_exist))
end

end