public void GetValueProvider_GetValue_SkipValidation() { // Arrange Mock <MockableUnvalidatedRequestValues> mockUnvalidatedValues = new Mock <MockableUnvalidatedRequestValues>(); mockUnvalidatedValues.Setup(o => o.Form).Returns(_unvalidatedBackingStore); JQueryFormValueProviderFactory factory = new JQueryFormValueProviderFactory(_ => mockUnvalidatedValues.Object); Mock <ControllerContext> mockControllerContext = new Mock <ControllerContext>(); mockControllerContext.Setup(o => o.HttpContext.Request.Form).Returns(_backingStore); // Act IUnvalidatedValueProvider valueProvider = (IUnvalidatedValueProvider)factory.GetValueProvider(mockControllerContext.Object); // Assert Assert.Equal(typeof(JQueryFormValueProvider), valueProvider.GetType()); ValueProviderResult vpResult = valueProvider.GetValue("fooArray[0].bar1[0].nested", skipValidation: true); Assert.NotNull(vpResult); Assert.Equal("fooNestedUnvalidatedValue", vpResult.AttemptedValue); Assert.Equal(CultureInfo.CurrentCulture, vpResult.Culture); }
public void GetValueProvider_ThrowsIfControllerContextIsNull() { // Arrange JQueryFormValueProviderFactory factory = new JQueryFormValueProviderFactory(); // Act & assert Assert.ThrowsArgumentNull( delegate { factory.GetValueProvider(null); }, "controllerContext"); }
public void GetValueProvider_ReturnsNull_WhenContentTypeIsNotFormUrlEncoded() { // Arrange var context = CreateContext("some-content-type", formValues: null); var factory = new JQueryFormValueProviderFactory(); // Act var result = factory.GetValueProvider(context); // Assert Assert.Null(result); }
public void GetValueProvider_ReturnsExpectedValueProviderInstanceWithCurrentCulture(string contentType) { // Arrange var context = CreateContext(contentType, formValues: null); var factory = new JQueryFormValueProviderFactory(); // Act var result = factory.GetValueProvider(context); // Assert var valueProvider = Assert.IsType<JQueryFormValueProvider>(result); Assert.Equal(CultureInfo.CurrentCulture, valueProvider.Culture); }
public void GetValueProvider_ReturnsExpectedValueProviderInstanceWithCurrentCulture(string contentType) { // Arrange var context = CreateContext(contentType, formValues: null); var factory = new JQueryFormValueProviderFactory(); // Act var result = factory.GetValueProvider(context); // Assert var valueProvider = Assert.IsType <JQueryFormValueProvider>(result); Assert.Equal(CultureInfo.CurrentCulture, valueProvider.Culture); }
public async Task GetValueProvider_ReturnsValueProvider_ContainingExpectedKeys(string key) { // Arrange var context = CreateContext("application/x-www-form-urlencoded", formValues: _backingStore); var factory = new JQueryFormValueProviderFactory(); // Act var valueProvider = factory.GetValueProvider(context); var result = await valueProvider.GetValueAsync(key); // Assert Assert.NotNull(result); Assert.NotNull(result.RawValue); var value = Assert.IsType <string>(result.RawValue); Assert.Equal("found", value); }
public void GetValueProvider() { // Arrange Mock<MockableUnvalidatedRequestValues> mockUnvalidatedValues = new Mock<MockableUnvalidatedRequestValues>(); JQueryFormValueProviderFactory factory = new JQueryFormValueProviderFactory(_ => mockUnvalidatedValues.Object); Mock<ControllerContext> mockControllerContext = new Mock<ControllerContext>(); mockControllerContext.Setup(o => o.HttpContext.Request.Form).Returns(_backingStore); // Act IValueProvider valueProvider = factory.GetValueProvider(mockControllerContext.Object); // Assert Assert.Equal(typeof(JQueryFormValueProvider), valueProvider.GetType()); ValueProviderResult vpResult = valueProvider.GetValue("fooArray[0].bar1"); Assert.NotNull(vpResult); Assert.Equal("fooArrayValue", vpResult.AttemptedValue); Assert.Equal(CultureInfo.CurrentCulture, vpResult.Culture); }
public async Task GetValueProvider_ReturnsValueProvider_ContainingExpectedKeys(string key) { // Arrange var context = CreateContext("application/x-www-form-urlencoded", formValues: _backingStore); var factory = new JQueryFormValueProviderFactory(); // Act var valueProvider = factory.GetValueProvider(context); var result = await valueProvider.GetValueAsync(key); // Assert Assert.NotNull(result); Assert.NotNull(result.RawValue); var value = Assert.IsType<string>(result.RawValue); Assert.Equal("found", value); }