public void GetValueProvider_GetValue_SkipValidation() { // Arrange Mock <MockableUnvalidatedRequestValues> mockUnvalidatedValues = new Mock <MockableUnvalidatedRequestValues>(); mockUnvalidatedValues.Setup(o => o.Form).Returns(_unvalidatedBackingStore); FormValueProviderFactory factory = new FormValueProviderFactory( _ => 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(FormValueProvider), valueProvider.GetType()); ValueProviderResult vpResult = valueProvider.GetValue("foo", skipValidation: true); Assert.NotNull(vpResult); Assert.Equal("fooUnvalidated", vpResult.AttemptedValue); Assert.Equal(CultureInfo.CurrentCulture, vpResult.Culture); }
public void GetValueProvider_ThrowsIfControllerContextIsNull() { // Arrange FormValueProviderFactory factory = new FormValueProviderFactory(); // Act & assert Assert.ThrowsArgumentNull( delegate { factory.GetValueProvider(null); }, "controllerContext"); }
public void GetValueProvider_ThrowsIfControllerContextIsNull() { // Arrange FormValueProviderFactory factory = new FormValueProviderFactory(); // Act & assert ExceptionHelper.ExpectArgumentNullException( delegate { factory.GetValueProvider(null); }, "controllerContext"); }
public void GetValueProvider_ReturnsNull_WhenContentTypeIsNotFormUrlEncoded() { // Arrange var context = CreateContext("some-content-type"); var factory = new FormValueProviderFactory(); // Act var result = factory.GetValueProvider(context); // Assert Assert.Null(result); }
public void GetValueProvider_ReturnsValueProviderInstanceWithInvariantCulture(string contentType) { // Arrange var context = CreateContext(contentType); var factory = new FormValueProviderFactory(); // Act var result = factory.GetValueProvider(context); // Assert var valueProvider = Assert.IsType<ReadableStringCollectionValueProvider>(result); Assert.Equal(CultureInfo.CurrentCulture, valueProvider.Culture); }
public void GetValueProvider_ReturnsValueProviderInstanceWithInvariantCulture(string contentType) { // Arrange var context = CreateContext(contentType); var factory = new FormValueProviderFactory(); // Act var result = factory.GetValueProvider(context); // Assert var valueProvider = Assert.IsType <ReadableStringCollectionValueProvider>(result); Assert.Equal(CultureInfo.CurrentCulture, valueProvider.Culture); }
public void GetValueProvider() { // Arrange FormValueProviderFactory factory = new FormValueProviderFactory(); Mock<ControllerContext> mockControllerContext = new Mock<ControllerContext>(); mockControllerContext.Expect(o => o.HttpContext.Request.Form).Returns(_backingStore); // Act IValueProvider valueProvider = factory.GetValueProvider(mockControllerContext.Object); // Assert Assert.AreEqual(typeof(FormValueProvider), 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.CurrentCulture, vpResult.Culture); }
public void GetValueProvider_GetValue_SkipValidation() { // Arrange Mock<MockableUnvalidatedRequestValues> mockUnvalidatedValues = new Mock<MockableUnvalidatedRequestValues>(); mockUnvalidatedValues.Setup(o => o.Form).Returns(_unvalidatedBackingStore); FormValueProviderFactory factory = new FormValueProviderFactory(_ => 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.AreEqual(typeof(FormValueProvider), 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.CurrentCulture, vpResult.Culture); }
public void GetValueProvider() { // Arrange Mock<MockableUnvalidatedRequestValues> mockUnvalidatedValues = new Mock<MockableUnvalidatedRequestValues>(); FormValueProviderFactory factory = new FormValueProviderFactory(_ => 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(FormValueProvider), valueProvider.GetType()); ValueProviderResult vpResult = valueProvider.GetValue("foo"); Assert.NotNull(vpResult); Assert.Equal("fooValue", vpResult.AttemptedValue); Assert.Equal(CultureInfo.CurrentCulture, vpResult.Culture); }
public void GetValueProvider() { // Arrange FormValueProviderFactory factory = new FormValueProviderFactory(); Mock <ControllerContext> mockControllerContext = new Mock <ControllerContext>(); mockControllerContext.Expect(o => o.HttpContext.Request.Form).Returns(_backingStore); // Act IValueProvider valueProvider = factory.GetValueProvider(mockControllerContext.Object); // Assert Assert.AreEqual(typeof(FormValueProvider), 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.CurrentCulture, vpResult.Culture); }