public void BindModel_GoodValue_LinqBinary_Succeeds() { // Arrange ExtensibleModelBindingContext bindingContext = new ExtensibleModelBindingContext { ModelMetadata = new EmptyModelMetadataProvider().GetMetadataForType( null, typeof(Binary) ), ModelName = "foo", ValueProvider = new SimpleValueProvider { { "foo", _base64String } } }; BinaryDataModelBinderProvider binderProvider = new BinaryDataModelBinderProvider(); // Act IExtensibleModelBinder binder = binderProvider.GetBinder(null, bindingContext); bool retVal = binder.BindModel(null, bindingContext); // Assert Assert.True(retVal); Binary binaryModel = Assert.IsType <Binary>(bindingContext.Model); Assert.Equal(_base64Bytes, binaryModel.ToArray()); }
public void BindModel_EmptyValue_Fails() { // Arrange ExtensibleModelBindingContext bindingContext = new ExtensibleModelBindingContext() { ModelMetadata = new EmptyModelMetadataProvider().GetMetadataForType(null, typeof(byte[])), ModelName = "foo", ValueProvider = new SimpleValueProvider() { { "foo", "" } } }; BinaryDataModelBinderProvider binderProvider = new BinaryDataModelBinderProvider(); // Act IExtensibleModelBinder binder = binderProvider.GetBinder(null, bindingContext); bool retVal = binder.BindModel(null, bindingContext); // Assert Assert.IsFalse(retVal); }
public void BindModel_GoodValue_ByteArray_Succeeds() { // Arrange ExtensibleModelBindingContext bindingContext = new ExtensibleModelBindingContext() { ModelMetadata = new EmptyModelMetadataProvider().GetMetadataForType(null, typeof(byte[])), ModelName = "foo", ValueProvider = new SimpleValueProvider() { { "foo", _base64String } } }; BinaryDataModelBinderProvider binderProvider = new BinaryDataModelBinderProvider(); // Act IExtensibleModelBinder binder = binderProvider.GetBinder(null, bindingContext); bool retVal = binder.BindModel(null, bindingContext); // Assert Assert.IsTrue(retVal); CollectionAssert.AreEqual(_base64Bytes, (byte[])bindingContext.Model); }
public void GetBinder_WrongModelType_ReturnsNull() { // Arrange ExtensibleModelBindingContext bindingContext = new ExtensibleModelBindingContext() { ModelMetadata = new EmptyModelMetadataProvider().GetMetadataForType(null, typeof(object)), ModelName = "foo", ValueProvider = new SimpleValueProvider() { { "foo", _base64String } } }; BinaryDataModelBinderProvider binderProvider = new BinaryDataModelBinderProvider(); // Act IExtensibleModelBinder modelBinder = binderProvider.GetBinder(null, bindingContext); // Assert Assert.IsNull(modelBinder); }
public void BindModel_GoodValue_LinqBinary_Succeeds() { // Arrange ExtensibleModelBindingContext bindingContext = new ExtensibleModelBindingContext { ModelMetadata = new EmptyModelMetadataProvider().GetMetadataForType(null, typeof(Binary)), ModelName = "foo", ValueProvider = new SimpleValueProvider { { "foo", _base64String } } }; BinaryDataModelBinderProvider binderProvider = new BinaryDataModelBinderProvider(); // Act IExtensibleModelBinder binder = binderProvider.GetBinder(null, bindingContext); bool retVal = binder.BindModel(null, bindingContext); // Assert Assert.True(retVal); Binary binaryModel = Assert.IsType<Binary>(bindingContext.Model); Assert.Equal(_base64Bytes, binaryModel.ToArray()); }