public void ContainsPrefix_GuardClauses() { // Arrange var valueProvider = new NameValuePairsValueProvider(_backingStore, null); // Act & assert Assert.ThrowsArgumentNull(() => valueProvider.ContainsPrefix(null), "prefix"); }
public void GetValue_GuardClauses() { // Arrange var valueProvider = new NameValuePairsValueProvider(_backingStore, null); // Act & assert Assert.ThrowsArgumentNull(() => valueProvider.GetValue(null), "key"); }
public void ContainsPrefix_WithNonEmptyCollection_ReturnsTrueForKnownPrefixes() { // Arrange var valueProvider = new NameValuePairsValueProvider(_backingStore, null); // Act & Assert Assert.True(valueProvider.ContainsPrefix("foo")); Assert.True(valueProvider.ContainsPrefix("bar")); Assert.True(valueProvider.ContainsPrefix("bar.baz")); }
public void ContainsPrefix_GuardClauses() { // Arrange var valueProvider = new NameValuePairsValueProvider(_backingStore, null); // Act & assert Assert.ThrowsArgumentNull( () => valueProvider.ContainsPrefix(null), "prefix"); }
public void ContainsPrefix_WithNonEmptyCollection_ReturnsTrueForKnownPrefixes() { // Arrange var valueProvider = new NameValuePairsValueProvider(_backingStore, null); // Act & Assert Assert.True(valueProvider.ContainsPrefix("foo")); Assert.True(valueProvider.ContainsPrefix("bar")); Assert.True(valueProvider.ContainsPrefix("bar.baz")); }
public void ContainsPrefix_WithNonEmptyCollection_ReturnsTrueForEmptyPrefix() { // Arrange var valueProvider = new NameValuePairsValueProvider(_backingStore, null); // Act bool result = valueProvider.ContainsPrefix(""); // Assert Assert.True(result); }
public void ContainsPrefix_WithEmptyCollection_ReturnsFalseForEmptyPrefix() { // Arrange var valueProvider = new NameValuePairsValueProvider(Enumerable.Empty<KeyValuePair<string, string>>(), null); // Act bool result = valueProvider.ContainsPrefix(""); // Assert Assert.False(result); }
public void GetKeysFromPrefix_UnknownPrefix_ReturnsEmptyDictionary() { // Arrange var valueProvider = new NameValuePairsValueProvider(_backingStore, null); // Act IDictionary <string, string> result = valueProvider.GetKeysFromPrefix("abc"); // Assert Assert.Empty(result); }
public void GetValue_ReturnsNullIfKeyNotFound() { // Arrange var valueProvider = new NameValuePairsValueProvider(_backingStore, null); // Act ValueProviderResult vpResult = valueProvider.GetValue("bar"); // Assert Assert.Null(vpResult); }
public void ContainsPrefix_WithEmptyCollection_ReturnsFalseForEmptyPrefix() { // Arrange var valueProvider = new NameValuePairsValueProvider(Enumerable.Empty <KeyValuePair <string, string> >(), null); // Act bool result = valueProvider.ContainsPrefix(""); // Assert Assert.False(result); }
public void ContainsPrefix_WithNonEmptyCollection_ReturnsFalseForUnknownPrefix() { // Arrange var valueProvider = new NameValuePairsValueProvider(_backingStore, null); // Act bool result = valueProvider.ContainsPrefix("biff"); // Assert Assert.False(result); }
public void GetKeysFromPrefix_EmptyPrefix_ReturnsAllPrefixes() { // Arrange var valueProvider = new NameValuePairsValueProvider(_backingStore, null); // Act IDictionary <string, string> result = valueProvider.GetKeysFromPrefix(""); // Assert Assert.Equal(2, result.Count); Assert.Equal("foo", result["foo"]); Assert.Equal("bar", result["bar"]); }
public void GetKeysFromPrefix_KnownPrefix_ReturnsMatchingItems() { // Arrange var valueProvider = new NameValuePairsValueProvider(_backingStore, null); // Act IDictionary <string, string> result = valueProvider.GetKeysFromPrefix("bar"); // Assert KeyValuePair <string, string> kvp = Assert.Single(result); Assert.Equal("baz", kvp.Key); Assert.Equal("bar.baz", kvp.Value); }
public void GetKeysFromPrefix_EmptyPrefix_ReturnsAllPrefixes() { // Arrange var valueProvider = new NameValuePairsValueProvider(_backingStore, null); // Act IDictionary <string, string> result = valueProvider.GetKeysFromPrefix(""); // Assert Assert.Equal <KeyValuePair <string, string> >( result.OrderBy(kvp => kvp.Key), new Dictionary <string, string> { { "bar", "bar" }, { "foo", "foo" }, { "null_value", "null_value" }, { "prefix", "prefix" } }); }
public void GetValue_NullValue(string key) { // Arrange var culture = CultureInfo.GetCultureInfo("fr-FR"); var valueProvider = new NameValuePairsValueProvider(_backingStore, culture); // Act ValueProviderResult vpResult = valueProvider.GetValue(key); // Assert Assert.NotNull(vpResult); Assert.Null(vpResult.RawValue); Assert.Null(vpResult.AttemptedValue); Assert.Equal(culture, vpResult.Culture); }
public void GetValue_SingleValue() { // Arrange var culture = CultureInfo.GetCultureInfo("fr-FR"); var valueProvider = new NameValuePairsValueProvider(_backingStore, culture); // Act ValueProviderResult vpResult = valueProvider.GetValue("bar.baz"); // Assert Assert.NotNull(vpResult); Assert.Equal("someOtherValue", vpResult.RawValue); Assert.Equal("someOtherValue", vpResult.AttemptedValue); Assert.Equal(culture, vpResult.Culture); }
static void Main(string[] args) { Dictionary<string, string> dictionary = new Dictionary<string, string>(); dictionary.Add("contacts[0].Name", "张三"); dictionary.Add("contacts[0].PhoneNo", "123456789"); dictionary.Add("contacts[0].EmailAddress", "*****@*****.**"); dictionary.Add("contacts[1].Name", "李四"); dictionary.Add("contacts[1].PhoneNo", "987654321"); dictionary.Add("contacts[1].EmailAddress", "*****@*****.**"); NameValuePairsValueProvider valueProvider = new NameValuePairsValueProvider(dictionary.ToArray(), null); //Prefix="" Console.WriteLine("Prefix: <Empty>"); Console.WriteLine("{0,-14}{1}", "Key", "Value"); IDictionary<string, string> keys = valueProvider.GetKeysFromPrefix(string.Empty); foreach (var item in keys) { Console.WriteLine("{0,-14}{1}", item.Key, item.Value); } //Prefix="contact" Console.WriteLine("\nPrefix: contact"); Console.WriteLine("{0,-14}{1}", "Key", "Value"); keys = valueProvider.GetKeysFromPrefix("contact"); foreach (var item in keys) { Console.WriteLine("{0,-14}{1}", item.Key, item.Value); } //Prefix="contacts[0]" Console.WriteLine("\nPrefix: contacts[0]"); Console.WriteLine("{0,-14}{1}", "Key", "Value"); keys = valueProvider.GetKeysFromPrefix("contacts[0]"); foreach (var item in keys) { Console.WriteLine("{0,-14}{1}", item.Key, item.Value); } //Prefix="contacts[1]" Console.WriteLine("\nPrefix: contacts[1]"); Console.WriteLine("{0,-14}{1}", "Key", "Value"); keys = valueProvider.GetKeysFromPrefix("contacts[1]"); foreach (var item in keys) { Console.WriteLine("{0,-14}{1}", item.Key, item.Value); } }
// Read the body upfront , add as a ValueProvider public override Task ExecuteBindingAsync(HttpActionContext actionContext, CancellationToken cancellationToken) { HttpRequestMessage request = actionContext.ControllerContext.Request; HttpContent content = request.Content; if (content != null) { FormDataCollection fd = content.ReadAsAsync<FormDataCollection>().Result; if (fd != null) { IValueProvider vp = new NameValuePairsValueProvider(fd, CultureInfo.InvariantCulture); request.Properties.Add(Key, vp); } } return base.ExecuteBindingAsync(actionContext, cancellationToken); }
static void Main(string[] args) { List<KeyValuePair<string, string>> list = new List<KeyValuePair<string, string>>(); list.Add(new KeyValuePair<string, string>("foobar", "1")); list.Add(new KeyValuePair<string, string>("foobar", "2")); list.Add(new KeyValuePair<string, string>("foobar", "3")); NameValuePairsValueProvider valueProvider = new NameValuePairsValueProvider(list, null); var result = valueProvider.GetValue("foobar"); int[] value1 = (int[])result.ConvertTo(typeof(int[])); int value2 = (int)result.ConvertTo(typeof(int)); Console.WriteLine("{0,-16}{1}", "RawValue", "NewValue"); Console.WriteLine("{0,-16}{1}", result.RawValue.ConvertToString(), value1.ConvertToString()); Console.WriteLine("{0,-16}{1}", result.RawValue.ConvertToString(), value2.ConvertToString()); }
public void GetValue_MultiValue() { // Arrange var culture = CultureInfo.GetCultureInfo("fr-FR"); var valueProvider = new NameValuePairsValueProvider(_backingStore, culture); // Act ValueProviderResult vpResult = valueProvider.GetValue("foo"); // Assert Assert.NotNull(vpResult); Assert.Equal(new List <string>() { "fooValue1", "fooValue2" }, (List <string>)vpResult.RawValue); Assert.Equal("fooValue1,fooValue2", vpResult.AttemptedValue); Assert.Equal(culture, vpResult.Culture); }
public void GetValue_NullMultipleValue() { // Arrange var backingStore = new KeyValuePair <string, string>[] { new KeyValuePair <string, string>("key", null), new KeyValuePair <string, string>("key", null), new KeyValuePair <string, string>("key", "value") }; var culture = CultureInfo.GetCultureInfo("fr-FR"); var valueProvider = new NameValuePairsValueProvider(backingStore, culture); // Act ValueProviderResult vpResult = valueProvider.GetValue("key"); // Assert Assert.Equal(new[] { null, null, "value" }, vpResult.RawValue as IEnumerable <string>); Assert.Equal(",,value", vpResult.AttemptedValue); }
static void Main(string[] args) { Dictionary<string, string> dictionary = new Dictionary<string, string>(); dictionary.Add("contact.Name", "张三"); dictionary.Add("contact.PhoneNo", "123456789"); dictionary.Add("contact.EmailAddress", "*****@*****.**"); dictionary.Add("contact.Address.Province", "江苏"); dictionary.Add("contact.Address.City", "苏州"); dictionary.Add("contact.Address.District", "工业园区"); dictionary.Add("contact.Address.Street", "星湖街328号"); NameValuePairsValueProvider valueProvider = new NameValuePairsValueProvider(dictionary.ToArray(), null); //Prefix="" Console.WriteLine("Prefix: <Empty>"); Console.WriteLine("{0,-14}{1}", "Key", "Value"); IDictionary<string, string> keys = valueProvider.GetKeysFromPrefix(string.Empty); foreach (var item in keys) { Console.WriteLine("{0,-14}{1}", item.Key, item.Value); } //Prefix="contact" Console.WriteLine("\nPrefix: contact"); Console.WriteLine("{0,-14}{1}", "Key", "Value"); keys = valueProvider.GetKeysFromPrefix("contact"); foreach (var item in keys) { Console.WriteLine("{0,-14}{1}", item.Key, item.Value); } //Prefix="contact.Address" Console.WriteLine("\nPrefix: contact.Address"); Console.WriteLine("{0,-14}{1}", "Key", "Value"); keys = valueProvider.GetKeysFromPrefix("contact.Address"); foreach (var item in keys) { Console.WriteLine("{0,-14}{1}", item.Key, item.Value); } }
public void GetKeysFromPrefix_EmptyPrefix_ReturnsAllPrefixes() { // Arrange var valueProvider = new NameValuePairsValueProvider(_backingStore, null); // Act IDictionary<string, string> result = valueProvider.GetKeysFromPrefix(""); // Assert Assert.Equal<KeyValuePair<string, string>>( result.OrderBy(kvp => kvp.Key), new Dictionary<string, string> { { "bar", "bar" }, { "foo", "foo" }, { "null_value", "null_value" }, { "prefix", "prefix" } }); }
public void GetValue_NullValue(string key) { // Arrange var culture = CultureInfo.GetCultureInfo("fr-FR"); var valueProvider = new NameValuePairsValueProvider(_backingStore, culture); // Act ValueProviderResult vpResult = valueProvider.GetValue(key); // Assert Assert.NotNull(vpResult); Assert.Equal(null, vpResult.RawValue); Assert.Equal(null, vpResult.AttemptedValue); Assert.Equal(culture, vpResult.Culture); }
public void GetValue_NullMultipleValue() { // Arrange var backingStore = new KeyValuePair<string, string>[] { new KeyValuePair<string, string>("key", null), new KeyValuePair<string, string>("key", null), new KeyValuePair<string, string>("key", "value") }; var culture = CultureInfo.GetCultureInfo("fr-FR"); var valueProvider = new NameValuePairsValueProvider(backingStore, culture); // Act ValueProviderResult vpResult = valueProvider.GetValue("key"); // Assert Assert.Equal(new[] { null, null, "value" }, vpResult.RawValue as IEnumerable<string>); Assert.Equal(",,value", vpResult.AttemptedValue); }
public void GetKeysFromPrefix_EmptyPrefix_ReturnsAllPrefixes() { // Arrange var valueProvider = new NameValuePairsValueProvider(_backingStore, null); // Act IDictionary<string, string> result = valueProvider.GetKeysFromPrefix(""); // Assert Assert.Equal(2, result.Count); Assert.Equal("foo", result["foo"]); Assert.Equal("bar", result["bar"]); }
public void GetKeysFromPrefix_UnknownPrefix_ReturnsEmptyDictionary() { // Arrange var valueProvider = new NameValuePairsValueProvider(_backingStore, null); // Act IDictionary<string, string> result = valueProvider.GetKeysFromPrefix("abc"); // Assert Assert.Empty(result); }
public void GetKeysFromPrefix_KnownPrefix_ReturnsMatchingItems() { // Arrange var valueProvider = new NameValuePairsValueProvider(_backingStore, null); // Act IDictionary<string, string> result = valueProvider.GetKeysFromPrefix("bar"); // Assert KeyValuePair<string, string> kvp = Assert.Single(result); Assert.Equal("baz", kvp.Key); Assert.Equal("bar.baz", kvp.Value); }
public void GetValue_GuardClauses() { // Arrange var valueProvider = new NameValuePairsValueProvider(_backingStore, null); // Act & assert Assert.ThrowsArgumentNull( () => valueProvider.GetValue(null), "key"); }
public void GetValue_SingleValue() { // Arrange var culture = CultureInfo.GetCultureInfo("fr-FR"); var valueProvider = new NameValuePairsValueProvider(_backingStore, culture); // Act ValueProviderResult vpResult = valueProvider.GetValue("bar.baz"); // Assert Assert.NotNull(vpResult); Assert.Equal("someOtherValue", vpResult.RawValue); Assert.Equal("someOtherValue", vpResult.AttemptedValue); Assert.Equal(culture, vpResult.Culture); }
public void GetValue_MultiValue() { // Arrange var culture = CultureInfo.GetCultureInfo("fr-FR"); var valueProvider = new NameValuePairsValueProvider(_backingStore, culture); // Act ValueProviderResult vpResult = valueProvider.GetValue("foo"); // Assert Assert.NotNull(vpResult); Assert.Equal(new List<string>() { "fooValue1", "fooValue2" }, (List<string>)vpResult.RawValue); Assert.Equal("fooValue1,fooValue2", vpResult.AttemptedValue); Assert.Equal(culture, vpResult.Culture); }
public void GetValue_ReturnsNullIfKeyNotFound() { // Arrange var valueProvider = new NameValuePairsValueProvider(_backingStore, null); // Act ValueProviderResult vpResult = valueProvider.GetValue("bar"); // Assert Assert.Null(vpResult); }