public void GetValueProvider_ThrowsIfControllerContextIsNull()
        {
            // Arrange
            QueryStringValueProviderFactory factory = new QueryStringValueProviderFactory();

            // Act & assert
            Assert.ThrowsArgumentNull(
                delegate { factory.GetValueProvider(null); }, "controllerContext");
        }
        public void GetValueProvider_ThrowsIfControllerContextIsNull()
        {
            // Arrange
            QueryStringValueProviderFactory factory = new QueryStringValueProviderFactory();

            // Act & assert
            Assert.ThrowsArgumentNull(
                delegate { factory.GetValueProvider(null); }, "controllerContext");
        }
        public void GetValueProvider_ThrowsIfControllerContextIsNull() {
            // Arrange
            QueryStringValueProviderFactory factory = new QueryStringValueProviderFactory();

            // Act & assert
            ExceptionHelper.ExpectArgumentNullException(
                delegate {
                    factory.GetValueProvider(null);
                }, "controllerContext");
        }
        public void GetValueProvider_ThrowsIfControllerContextIsNull()
        {
            // Arrange
            QueryStringValueProviderFactory factory = new QueryStringValueProviderFactory();

            // Act & assert
            ExceptionHelper.ExpectArgumentNullException(
                delegate {
                factory.GetValueProvider(null);
            }, "controllerContext");
        }
        public async Task DoesNotCreateValueProvider_WhenQueryStringIsEmpty()
        {
            // Arrange
            var actionContext  = new ActionContext(new DefaultHttpContext(), new RouteData(), new ActionDescriptor());
            var factoryContext = new ValueProviderFactoryContext(actionContext);
            var factory        = new QueryStringValueProviderFactory();

            // Act
            await factory.CreateValueProviderAsync(factoryContext);

            // Assert
            Assert.Empty(factoryContext.ValueProviders);
        }
        public void GetValueProvider() {
            // Arrange
            QueryStringValueProviderFactory factory = new QueryStringValueProviderFactory();

            Mock<ControllerContext> mockControllerContext = new Mock<ControllerContext>();
            mockControllerContext.Expect(o => o.HttpContext.Request.QueryString).Returns(_backingStore);

            // Act
            IValueProvider valueProvider = factory.GetValueProvider(mockControllerContext.Object);

            // Assert
            Assert.AreEqual(typeof(QueryStringValueProvider), valueProvider.GetType());
            ValueProviderResult vpResult = valueProvider.GetValue("foo");

            Assert.IsNotNull(vpResult, "Should have contained a value for key 'foo'.");
            Assert.AreEqual("fooValue", vpResult.AttemptedValue);
            Assert.AreEqual(CultureInfo.InvariantCulture, vpResult.Culture);
        }
        public async Task GetValueProvider_ReturnsQueryStringValueProviderInstanceWithInvariantCulture()
        {
            // Arrange
            var request = new Mock<HttpRequest>();
            request.SetupGet(f => f.Query).Returns(Mock.Of<IQueryCollection>());
            var context = new Mock<HttpContext>();
            context.SetupGet(c => c.Items).Returns(new Dictionary<object, object>());
            context.SetupGet(c => c.Request).Returns(request.Object);
            var actionContext = new ActionContext(context.Object, new RouteData(), new ActionDescriptor());
            var factory = new QueryStringValueProviderFactory();

            // Act
            var result = await factory.GetValueProviderAsync(actionContext);

            // Assert
            var valueProvider = Assert.IsType<QueryStringValueProvider>(result);
            Assert.Equal(CultureInfo.InvariantCulture, valueProvider.Culture);
        }
        public void GetValueProvider()
        {
            // Arrange
            QueryStringValueProviderFactory factory = new QueryStringValueProviderFactory();

            Mock <ControllerContext> mockControllerContext = new Mock <ControllerContext>();

            mockControllerContext.Expect(o => o.HttpContext.Request.QueryString).Returns(_backingStore);

            // Act
            IValueProvider valueProvider = factory.GetValueProvider(mockControllerContext.Object);

            // Assert
            Assert.AreEqual(typeof(QueryStringValueProvider), valueProvider.GetType());
            ValueProviderResult vpResult = valueProvider.GetValue("foo");

            Assert.IsNotNull(vpResult, "Should have contained a value for key 'foo'.");
            Assert.AreEqual("fooValue", vpResult.AttemptedValue);
            Assert.AreEqual(CultureInfo.InvariantCulture, vpResult.Culture);
        }
        public void GetValueProvider()
        {
            // Arrange
            Mock<MockableUnvalidatedRequestValues> mockUnvalidatedValues = new Mock<MockableUnvalidatedRequestValues>();
            QueryStringValueProviderFactory factory = new QueryStringValueProviderFactory(_ => mockUnvalidatedValues.Object);

            Mock<ControllerContext> mockControllerContext = new Mock<ControllerContext>();
            mockControllerContext.Setup(o => o.HttpContext.Request.QueryString).Returns(_backingStore);

            // Act
            IValueProvider valueProvider = factory.GetValueProvider(mockControllerContext.Object);

            // Assert
            Assert.Equal(typeof(QueryStringValueProvider), valueProvider.GetType());
            ValueProviderResult vpResult = valueProvider.GetValue("foo");

            Assert.NotNull(vpResult);
            Assert.Equal("fooValue", vpResult.AttemptedValue);
            Assert.Equal(CultureInfo.InvariantCulture, vpResult.Culture);
        }
        public void GetValueProvider_GetValue_SkipValidation() {
            // Arrange
            Mock<MockableUnvalidatedRequestValues> mockUnvalidatedValues = new Mock<MockableUnvalidatedRequestValues>();
            mockUnvalidatedValues.Setup(o => o.QueryString).Returns(_unvalidatedBackingStore);
            QueryStringValueProviderFactory factory = new QueryStringValueProviderFactory(_ => mockUnvalidatedValues.Object);

            Mock<ControllerContext> mockControllerContext = new Mock<ControllerContext>();
            mockControllerContext.Setup(o => o.HttpContext.Request.QueryString).Returns(_backingStore);

            // Act
            IUnvalidatedValueProvider valueProvider = (IUnvalidatedValueProvider)factory.GetValueProvider(mockControllerContext.Object);

            // Assert
            Assert.AreEqual(typeof(QueryStringValueProvider), valueProvider.GetType());
            ValueProviderResult vpResult = valueProvider.GetValue("foo", skipValidation: true);

            Assert.IsNotNull(vpResult, "Should have contained a value for key 'foo'.");
            Assert.AreEqual("fooUnvalidated", vpResult.AttemptedValue);
            Assert.AreEqual(CultureInfo.InvariantCulture, vpResult.Culture);
        }
        public async Task GetValueProvider_ReturnsQueryStringValueProviderInstanceWithInvariantCulture()
        {
            // Arrange
            var queryValues = new Dictionary <string, StringValues>();

            queryValues.Add("foo", "bar");
            var context = new DefaultHttpContext();

            context.Request.Query = new QueryCollection(queryValues);
            var actionContext  = new ActionContext(context, new RouteData(), new ActionDescriptor());
            var factoryContext = new ValueProviderFactoryContext(actionContext);
            var factory        = new QueryStringValueProviderFactory();

            // Act
            await factory.CreateValueProviderAsync(factoryContext);

            // Assert
            var valueProvider = Assert.IsType <QueryStringValueProvider>(Assert.Single(factoryContext.ValueProviders));

            Assert.Equal(CultureInfo.InvariantCulture, valueProvider.Culture);
        }
Exemplo n.º 12
0
        public void GetValueProvider()
        {
            // Arrange
            Mock <MockableUnvalidatedRequestValues> mockUnvalidatedValues = new Mock <MockableUnvalidatedRequestValues>();
            QueryStringValueProviderFactory         factory = new QueryStringValueProviderFactory(_ => mockUnvalidatedValues.Object);

            Mock <ControllerContext> mockControllerContext = new Mock <ControllerContext>();

            mockControllerContext.Setup(o => o.HttpContext.Request.QueryString).Returns(_backingStore);

            // Act
            IValueProvider valueProvider = factory.GetValueProvider(mockControllerContext.Object);

            // Assert
            Assert.Equal(typeof(QueryStringValueProvider), valueProvider.GetType());
            ValueProviderResult vpResult = valueProvider.GetValue("foo");

            Assert.NotNull(vpResult);
            Assert.Equal("fooValue", vpResult.AttemptedValue);
            Assert.Equal(CultureInfo.InvariantCulture, vpResult.Culture);
        }
Exemplo n.º 13
0
        public async Task GetValueProvider_ReturnsQueryStringValueProviderInstanceWithInvariantCulture()
        {
            // Arrange
            var request = new Mock <HttpRequest>();

            request.SetupGet(f => f.Query).Returns(Mock.Of <IQueryCollection>());
            var context = new Mock <HttpContext>();

            context.SetupGet(c => c.Items).Returns(new Dictionary <object, object>());
            context.SetupGet(c => c.Request).Returns(request.Object);
            var actionContext = new ActionContext(context.Object, new RouteData(), new ActionDescriptor());
            var factory       = new QueryStringValueProviderFactory();

            // Act
            var result = await factory.GetValueProviderAsync(actionContext);

            // Assert
            var valueProvider = Assert.IsType <QueryStringValueProvider>(result);

            Assert.Equal(CultureInfo.InvariantCulture, valueProvider.Culture);
        }
        public void GetValueProvider_GetValue_SkipValidation()
        {
            // Arrange
            Mock <MockableUnvalidatedRequestValues> mockUnvalidatedValues = new Mock <MockableUnvalidatedRequestValues>();

            mockUnvalidatedValues.Setup(o => o.QueryString).Returns(_unvalidatedBackingStore);
            QueryStringValueProviderFactory factory = new QueryStringValueProviderFactory(_ => mockUnvalidatedValues.Object);

            Mock <ControllerContext> mockControllerContext = new Mock <ControllerContext>();

            mockControllerContext.Setup(o => o.HttpContext.Request.QueryString).Returns(_backingStore);

            // Act
            IUnvalidatedValueProvider valueProvider = (IUnvalidatedValueProvider)factory.GetValueProvider(mockControllerContext.Object);

            // Assert
            Assert.AreEqual(typeof(QueryStringValueProvider), valueProvider.GetType());
            ValueProviderResult vpResult = valueProvider.GetValue("foo", skipValidation: true);

            Assert.IsNotNull(vpResult, "Should have contained a value for key 'foo'.");
            Assert.AreEqual("fooUnvalidated", vpResult.AttemptedValue);
            Assert.AreEqual(CultureInfo.InvariantCulture, vpResult.Culture);
        }