public void GetKeysFromPrefix_GuardClauses() { // Arrange var valueProvider = new NameValueCollectionValueProvider(_backingStore, null); // Act & assert Assert.ThrowsArgumentNull( () => valueProvider.GetKeysFromPrefix(null), "prefix"); }
public void ContainsPrefix_WithNonEmptyCollection_ReturnsTrueForKnownPrefixes() { // Arrange var valueProvider = new NameValueCollectionValueProvider(_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 NameValueCollectionValueProvider(_backingStore, null); // Act & assert Assert.ThrowsArgumentNull( () => valueProvider.ContainsPrefix(null), "prefix"); }
public void ContainsPrefix_WithNonEmptyCollection_ReturnsFalseForUnknownPrefix() { // Arrange var valueProvider = new NameValueCollectionValueProvider(_backingStore, null); // Act bool result = valueProvider.ContainsPrefix("biff"); // Assert Assert.False(result); }
public void ContainsPrefix_WithEmptyCollection_ReturnsFalseForEmptyPrefix() { // Arrange var valueProvider = new NameValueCollectionValueProvider(new NameValueCollection(), null); // Act bool result = valueProvider.ContainsPrefix(""); // Assert Assert.False(result); }
public void GetValue_ReturnsNullIfKeyNotFound() { // Arrange var valueProvider = new NameValueCollectionValueProvider(_backingStore, null); // Act ValueProviderResult vpResult = valueProvider.GetValue("bar"); // Assert Assert.Null(vpResult); }
public void GetKeysFromPrefix_UnknownPrefix_ReturnsEmptyDictionary() { // Arrange var valueProvider = new NameValueCollectionValueProvider(_backingStore, null); // Act IDictionary <string, string> result = valueProvider.GetKeysFromPrefix("abc"); // Assert Assert.Empty(result); }
public void GetKeysFromPrefix_EmptyPrefix_ReturnsAllPrefixes() { // Arrange var valueProvider = new NameValueCollectionValueProvider(_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 NameValueCollectionValueProvider(_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_MultiValue() { // Arrange var culture = CultureInfo.GetCultureInfo("fr-FR"); var valueProvider = new NameValueCollectionValueProvider(_backingStore, culture); // Act ValueProviderResult vpResult = valueProvider.GetValue("foo"); // Assert Assert.NotNull(vpResult); Assert.Equal(new[] { "fooValue1", "fooValue2" }, (string[])vpResult.RawValue); Assert.Equal("fooValue1,fooValue2", vpResult.AttemptedValue); Assert.Equal(culture, vpResult.Culture); }
public void GetValue_SingleValue() { // Arrange var culture = CultureInfo.GetCultureInfo("fr-FR"); var valueProvider = new NameValueCollectionValueProvider(_backingStore, culture); // Act ValueProviderResult vpResult = valueProvider.GetValue("bar.baz"); // Assert Assert.NotNull(vpResult); Assert.Equal(new[] { "someOtherValue" }, (string[])vpResult.RawValue); Assert.Equal("someOtherValue", vpResult.AttemptedValue); Assert.Equal(culture, vpResult.Culture); }
// 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) { NameValueCollection nvc = fd.ReadAsNameValueCollection(); IValueProvider vp = new NameValueCollectionValueProvider(nvc, CultureInfo.InvariantCulture); request.Properties.Add(Key, vp); } } return base.ExecuteBindingAsync(actionContext, cancellationToken); }
public void GetKeysFromPrefix_EmptyPrefix_ReturnsAllPrefixes() { // Arrange var valueProvider = new NameValueCollectionValueProvider(_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 GetValue_GuardClauses() { // Arrange var valueProvider = new NameValueCollectionValueProvider(_backingStore, null); // Act & assert Assert.ThrowsArgumentNull( () => valueProvider.GetValue(null), "key"); }
public void GetKeysFromPrefix_KnownPrefix_ReturnsMatchingItems() { // Arrange var valueProvider = new NameValueCollectionValueProvider(_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_UnknownPrefix_ReturnsEmptyDictionary() { // Arrange var valueProvider = new NameValueCollectionValueProvider(_backingStore, null); // Act IDictionary<string, string> result = valueProvider.GetKeysFromPrefix("abc"); // Assert Assert.Empty(result); }