public void ContainsPrefix_ReturnsTrue_IfKeyIsPresent()
        {
            // Arrange
            var values = new RouteValueDictionary(new Dictionary<string, object>
            {
                { "test-key", "test-value" }
            });
            var provider = new RouteValueProvider(BindingSource.Query, values);

            // Act
            var result = provider.ContainsPrefix("test-key");

            // Assert
            Assert.True(result);
        }
Exemple #2
0
        public void GetValue_ReturnsValue_WithDefaultCulture()
        {
            // Arrange
            var values = new RouteValueDictionary(new Dictionary <string, object>
            {
                { "test-key", "test-value" }
            });
            var provider = new RouteValueProvider(BindingSource.Query, values);

            // Act
            var result = provider.GetValue("test-key");

            // Assert
            Assert.Equal(CultureInfo.InvariantCulture, result.Culture);
        }
        /// <inheritdoc />
        public Task CreateValueProviderAsync(ValueProviderFactoryContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var valueProvider = new RouteValueProvider(
                BindingSource.Path,
                context.ActionContext.RouteData.Values);

            context.ValueProviders.Add(valueProvider);

            return(Task.CompletedTask);
        }
Exemple #4
0
        public void GetValueProvider_ReturnsValue_IfKeyIsPresent()
        {
            // Arrange
            var values = new RouteValueDictionary(new Dictionary <string, object>
            {
                { "test-key", "test-value" }
            });
            var provider = new RouteValueProvider(BindingSource.Query, values);

            // Act
            var result = provider.GetValue("test-key");

            // Assert
            Assert.Equal("test-value", (string)result);
        }
        public void GetValueProvider_ReturnsValue_UsesInvariantCulture()
        {
            // Arrange
            var values = new RouteValueDictionary(new Dictionary <string, object>
            {
                { "test-key", new DateTimeOffset(2018, 10, 31, 7, 37, 38, TimeSpan.FromHours(-7)) },
            });
            var provider = new RouteValueProvider(BindingSource.Query, values);

            // Act
            var result = provider.GetValue("test-key");

            // Assert
            Assert.Equal("10/31/2018 07:37:38 -07:00", (string)result);
        }
Exemple #6
0
        public void ContainsPrefix_ReturnsTrue_IfKeyIsPresent()
        {
            // Arrange
            var values = new RouteValueDictionary(new Dictionary <string, object>
            {
                { "test-key", "test-value" }
            });
            var provider = new RouteValueProvider(BindingSource.Query, values);

            // Act
            var result = provider.ContainsPrefix("test-key");

            // Assert
            Assert.True(result);
        }
Exemple #7
0
        public void GetValueProvider_ReturnsNull_WhenKeyIsNotFound()
        {
            // Arrange
            var values = new RouteValueDictionary(new Dictionary <string, object>
            {
                { "test-key", "value" }
            });
            var provider = new RouteValueProvider(BindingSource.Query, values);

            // Act
            var result = provider.GetValue("not-test-key");

            // Assert
            Assert.Equal(ValueProviderResult.None, result);
        }
        public void ContainsPrefix_ReturnsNullValue_IfKeyIsPresent()
        {
            // Arrange
            var values = new RouteValueDictionary(new Dictionary<string, object>
            {
                { "test-key", null }
            });
            var provider = new RouteValueProvider(BindingSource.Query, values);

            // Act
            var result = provider.GetValue("test-key");

            // Assert
            Assert.Equal(string.Empty, (string)result);
        }
Exemple #9
0
        public void ContainsPrefix_ReturnsNullValue_IfKeyIsPresent()
        {
            // Arrange
            var values = new RouteValueDictionary(new Dictionary <string, object>
            {
                { "test-key", null }
            });
            var provider = new RouteValueProvider(BindingSource.Query, values);

            // Act
            var result = provider.GetValue("test-key");

            // Assert
            Assert.Equal(string.Empty, (string)result);
        }
Exemple #10
0
        public void GetValue_DoesNotReturnAValue_ForAKeyPrefix()
        {
            // Arrange
            var values = new RouteValueDictionary(new Dictionary <string, object>
            {
                { "bar.baz", 2 },
            });

            var valueProvider = new RouteValueProvider(BindingSource.Query, values);

            // Act
            var result = valueProvider.GetValue("bar");

            // Assert
            Assert.Equal(ValueProviderResult.None, result);
        }
        public void ContainsPrefix_ReturnsTrue_ForKnownPrefixes(string prefix)
        {
            // Arrange
            var values = new RouteValueDictionary(new Dictionary<string, object>
            {
                { "foo", 1 },
                { "bar.baz", 1 },
            });

            var valueProvider = new RouteValueProvider(BindingSource.Query, values);

            // Act
            var result = valueProvider.ContainsPrefix(prefix);

            // Assert
            Assert.True(result);
        }
Exemple #12
0
        public void GetValue_ReturnsCorrectValue_ForKnownKeys(string prefix, string expectedValue)
        {
            // Arrange
            var values = new RouteValueDictionary(new Dictionary <string, object>
            {
                { "bar", 1 },
                { "bar.baz", 2 },
            });

            var valueProvider = new RouteValueProvider(BindingSource.Query, values);

            // Act
            var result = valueProvider.GetValue(prefix);

            // Assert
            Assert.Equal(expectedValue, (string)result);
        }
Exemple #13
0
        public void ContainsPrefix_ReturnsTrue_ForKnownPrefixes(string prefix)
        {
            // Arrange
            var values = new RouteValueDictionary(new Dictionary <string, object>
            {
                { "foo", 1 },
                { "bar.baz", 1 },
            });

            var valueProvider = new RouteValueProvider(BindingSource.Query, values);

            // Act
            var result = valueProvider.ContainsPrefix(prefix);

            // Assert
            Assert.True(result);
        }
        public void GetValueProvider_ReturnsValue_UsesSpecifiedCulture()
        {
            // Arrange
            var values = new RouteValueDictionary(new Dictionary <string, object>
            {
                { "test-key", new DateTimeOffset(2018, 10, 31, 7, 37, 38, TimeSpan.FromHours(-7)) },
            });
            var provider = new RouteValueProvider(BindingSource.Query, values, new CultureInfo("de-CH"));
            // The formatting was changed in netcoreapp3.0 to be consistent across platforms.
            var expected = "31.10.2018 07:37:38 -07:00";

            // Act
            var result = provider.GetValue("test-key");

            // Assert
            Assert.Equal(expected, (string)result);
        }
Exemple #15
0
        public void FilterExclude()
        {
            // Arrange
            var values   = new RouteValueDictionary();
            var provider = new RouteValueProvider(BindingSource.Query, values);

            var bindingSource = new BindingSource(
                "Test",
                displayName: null,
                isGreedy: true,
                isFromRequest: true);

            // Act
            var result = provider.Filter(bindingSource);

            // Assert
            Assert.Null(result);
        }
        public void GetValueProvider_ReturnsValue_UsesSpecifiedCulture()
        {
            // Arrange
            var values = new RouteValueDictionary(new Dictionary <string, object>
            {
                { "test-key", new DateTimeOffset(2018, 10, 31, 7, 37, 38, TimeSpan.FromHours(-7)) },
            });
            var provider = new RouteValueProvider(BindingSource.Query, values, new CultureInfo("de-CH"));

            // de-CH culture is slightly different on Windows versus other platforms.
            var expected = TestPlatformHelper.IsWindows ? "31.10.2018 07:37:38 -07:00" : "31.10.18 07:37:38 -07:00";

            // Act
            var result = provider.GetValue("test-key");

            // Assert
            Assert.Equal(expected, (string)result);
        }
        public void FilterExclude()
        {
            // Arrange
            var values = new RouteValueDictionary();
            var provider = new RouteValueProvider(BindingSource.Query, values);

            var bindingSource = new BindingSource(
                "Test",
                displayName: null,
                isGreedy: true,
                isFromRequest: true);

            // Act
            var result = provider.Filter(bindingSource);

            // Assert
            Assert.Null(result);
        }
        public void GetValueProvider_ReturnsNull_WhenKeyIsNotFound()
        {
            // Arrange
            var values = new RouteValueDictionary(new Dictionary<string, object>
            {
                { "test-key", "value" }
            });
            var provider = new RouteValueProvider(BindingSource.Query, values);

            // Act
            var result = provider.GetValue("not-test-key");

            // Assert
            Assert.Equal(ValueProviderResult.None, result);
        }
        public void GetValue_DoesNotReturnAValue_ForAKeyPrefix()
        {
            // Arrange
            var values = new RouteValueDictionary(new Dictionary<string, object>
            {
                { "bar.baz", 2 },
            });

            var valueProvider = new RouteValueProvider(BindingSource.Query, values);

            // Act
            var result = valueProvider.GetValue("bar");

            // Assert
            Assert.Equal(ValueProviderResult.None, result);
        }
        public void GetValueProvider_ReturnsValue_IfKeyIsPresent()
        {
            // Arrange
            var values = new RouteValueDictionary(new Dictionary<string, object>
            {
                { "test-key", "test-value" }
            });
            var provider = new RouteValueProvider(BindingSource.Query, values);

            // Act
            var result = provider.GetValue("test-key");

            // Assert
            Assert.Equal("test-value", (string)result);
        }
        public void GetValue_ReturnsCorrectValue_ForKnownKeys(string prefix, string expectedValue)
        {
            // Arrange
            var values = new RouteValueDictionary(new Dictionary<string, object>
            {
                { "bar", 1 },
                { "bar.baz", 2 },
            });

            var valueProvider = new RouteValueProvider(BindingSource.Query, values);

            // Act
            var result = valueProvider.GetValue(prefix);

            // Assert
            Assert.Equal(expectedValue, (string)result);
        }