public void GetCompatibleValueProviderResult_ValueProviderReturnsNull_ReturnsNull() { // Arrange ModelBindingContext bindingContext = GetBindingContext(); bindingContext.ValueProvider = new SimpleHttpValueProvider(); // Act ValueProviderResult vpResult = TypeMatchModelBinder.GetCompatibleValueProviderResult(bindingContext); // Assert Assert.Null(vpResult); // No key matched }
public void GetCompatibleValueProviderResult_ValueProviderResultRawValueIncorrect_ReturnsNull() { // Arrange ModelBindingContext bindingContext = GetBindingContext(); bindingContext.ValueProvider = new SimpleHttpValueProvider { { "theModelName", "not an integer" } }; // Act ValueProviderResult vpResult = TypeMatchModelBinder.GetCompatibleValueProviderResult(bindingContext); // Assert Assert.Null(vpResult); // Raw value is the wrong type }
public void GetCompatibleValueProviderResult_ValueProviderResultValid_ReturnsValueProviderResult() { // Arrange ModelBindingContext bindingContext = GetBindingContext(); bindingContext.ValueProvider = new SimpleHttpValueProvider { { "theModelName", 42 } }; // Act ValueProviderResult vpResult = TypeMatchModelBinder.GetCompatibleValueProviderResult(bindingContext); // Assert Assert.NotNull(vpResult); }
public override IModelBinder GetBinder(HttpActionContext actionContext, ModelBindingContext bindingContext) { return((TypeMatchModelBinder.GetCompatibleValueProviderResult(bindingContext) != null) ? new TypeMatchModelBinder() : null /* no match */); }