public void GetKeysFromPrefix_ReturnsUniqueTopLevelEntries_WhenPrefixIsEmpty() { // Arrange var keys = new[] { "[0].name", "[0].address.street", "[item1].name", "[item1].age", "foo", "foo.bar" }; var container = new PrefixContainer(keys); // Act var result = container.GetKeysFromPrefix(prefix: string.Empty); // Assert Assert.Collection(result.OrderBy(k => k.Key, StringComparer.OrdinalIgnoreCase), item => { Assert.Equal("0", item.Key); Assert.Equal("[0]", item.Value); }, item => { Assert.Equal("foo", item.Key); Assert.Equal("foo", item.Value); }, item => { Assert.Equal("item1", item.Key); Assert.Equal("[item1]", item.Value); }); }
public void GetKeysFromPrefix_ReturnsSubKeysThatStartWithPrefix() { // Arrange var keys = new[] { "foo[0].name", "foo.age", "foo[1].name", "food[item].spice" }; var container = new PrefixContainer(keys); // Act var result = container.GetKeysFromPrefix("foo"); // Assert Assert.Collection(result.OrderBy(k => k.Key, StringComparer.OrdinalIgnoreCase), item => { Assert.Equal("0", item.Key); Assert.Equal("foo[0]", item.Value); }, item => { Assert.Equal("1", item.Key); Assert.Equal("foo[1]", item.Value); }, item => { Assert.Equal("age", item.Key); Assert.Equal("foo.age", item.Value); }); }
public void GetKeysFromPrefix_ReturnsEmptyDictionaryWhenNoKeysStartWithPrefix() { // Arrange var keys = new[] { "foo[0].name", "foo.age", "[1].name", "[item].age" }; var container = new PrefixContainer(keys); // Act var result = container.GetKeysFromPrefix("baz"); // Assert Assert.Empty(result); }
public void GetKeysFromPrefix_ReturnsEmptySequenceWhenContainerIsEmpty(string prefix) { // Arrange var keys = new string[0]; var container = new PrefixContainer(keys); // Act var result = container.GetKeysFromPrefix(prefix); // Assert Assert.Empty(result); }
public void GetKeysFromPrefix_ReturnsSubKeysThatStartWithPrefix_ForNestedSubKeys() { // Arrange var keys = new[] { "person[0].address[0].street", "person[0].address[1].street", "person[0].address[1].zip" }; var container = new PrefixContainer(keys); // Act var result = container.GetKeysFromPrefix("person[0].address"); // Assert Assert.Collection(result.OrderBy(k => k.Key, StringComparer.OrdinalIgnoreCase), item => { Assert.Equal("0", item.Key); Assert.Equal("person[0].address[0]", item.Value); }, item => { Assert.Equal("1", item.Key); Assert.Equal("person[0].address[1]", item.Value); }); }
public void GetKeysFromPrefix_ReturnsSubKeysThatStartWithPrefix_ForNestedSubKeys() { // Arrange var keys = new[] { "person[0].address[0].street", "person[0].address[1].street", "person[0].address[1].zip" }; var container = new PrefixContainer(keys); // Act var result = container.GetKeysFromPrefix("person[0].address"); // Assert Assert.Collection(result.OrderBy(k => k.Key, StringComparer.OrdinalIgnoreCase), item => { Assert.Equal("0", item.Key); Assert.Equal("person[0].address[0]", item.Value); }, item => { Assert.Equal("1", item.Key); Assert.Equal("person[0].address[1]", item.Value); }); }
public void GetKeysFromPrefix_ReturnsSubKeysThatStartWithPrefix() { // Arrange var keys = new[] { "foo[0].name", "foo.age", "foo[1].name", "food[item].spice" }; var container = new PrefixContainer(keys); // Act var result = container.GetKeysFromPrefix("foo"); // Assert Assert.Collection(result.OrderBy(k => k.Key, StringComparer.OrdinalIgnoreCase), item => { Assert.Equal("0", item.Key); Assert.Equal("foo[0]", item.Value); }, item => { Assert.Equal("1", item.Key); Assert.Equal("foo[1]", item.Value); }, item => { Assert.Equal("age", item.Key); Assert.Equal("foo.age", item.Value); }); }
public void GetKeysFromPrefix_ReturnsEmptyDictionaryWhenNoKeysStartWithPrefix() { // Arrange var keys = new[] { "foo[0].name", "foo.age", "[1].name", "[item].age" }; var container = new PrefixContainer(keys); // Act var result = container.GetKeysFromPrefix("baz"); // Assert Assert.Empty(result); }
public void GetKeysFromPrefix_ReturnsUniqueTopLevelEntries_WhenPrefixIsEmpty() { // Arrange var keys = new[] { "[0].name", "[0].address.street", "[item1].name", "[item1].age", "foo", "foo.bar" }; var container = new PrefixContainer(keys); // Act var result = container.GetKeysFromPrefix(prefix: string.Empty); // Assert Assert.Collection(result.OrderBy(k => k.Key, StringComparer.OrdinalIgnoreCase), item => { Assert.Equal("0", item.Key); Assert.Equal("[0]", item.Value); }, item => { Assert.Equal("foo", item.Key); Assert.Equal("foo", item.Value); }, item => { Assert.Equal("item1", item.Key); Assert.Equal("[item1]", item.Value); }); }
public void GetKeysFromPrefix_ReturnsEmptySequenceWhenContainerIsEmpty(string prefix) { // Arrange var keys = new string[0]; var container = new PrefixContainer(keys); // Act var result = container.GetKeysFromPrefix(prefix); // Assert Assert.Empty(result); }