public async Task BindModelCoreAsync_UsesFirstFormatterWhichCanRead() { // Arrange var canReadFormatter1 = new TestInputFormatter(canRead: true); var canReadFormatter2 = new TestInputFormatter(canRead: true); var inputFormatters = new List <IInputFormatter>() { new TestInputFormatter(canRead: false), new TestInputFormatter(canRead: false), canReadFormatter1, canReadFormatter2 }; var provider = new TestModelMetadataProvider(); provider.ForType <Person>().BindingDetails(d => d.BindingSource = BindingSource.Body); var bindingContext = GetBindingContext(typeof(Person), metadataProvider: provider); var binder = CreateBinder(inputFormatters); // Act await binder.BindModelAsync(bindingContext); // Assert Assert.True(bindingContext.Result.IsModelSet); Assert.Same(canReadFormatter1, bindingContext.Result.Model); }
public void ConstructorSets_InputFormatterInstanceAndType() { // Arrange var testFormatter = new TestInputFormatter(); // Act var descriptor = new InputFormatterDescriptor(testFormatter); // Assert Assert.Same(testFormatter, descriptor.Instance); Assert.Equal(testFormatter.GetType(), descriptor.OptionType); }
public void GetBinder_DoesNotThrowNullReferenceException() { // Arrange var context = new TestModelBinderProviderContext(typeof(Person)); context.BindingInfo.BindingSource = BindingSource.Body; var formatter = new TestInputFormatter(); var formatterList = new List <IInputFormatter> { formatter }; var provider = new BodyModelBinderProvider(formatterList, new TestHttpRequestStreamReaderFactory()); // Act & Assert (does not throw) provider.GetBinder(context); }
public async Task BindModelCoreAsync_UsesFirstFormatterWhichCanRead() { // Arrange var canReadFormatter1 = new TestInputFormatter(canRead: true); var canReadFormatter2 = new TestInputFormatter(canRead: true); var inputFormatters = new List<IInputFormatter>() { new TestInputFormatter(canRead: false), new TestInputFormatter(canRead: false), canReadFormatter1, canReadFormatter2 }; var provider = new TestModelMetadataProvider(); provider.ForType<Person>().BindingDetails(d => d.BindingSource = BindingSource.Body); var bindingContext = GetBindingContext(typeof(Person), inputFormatters, metadataProvider: provider); var binder = bindingContext.OperationBindingContext.ModelBinder; // Act var binderResult = await binder.BindModelAsync(bindingContext); // Assert Assert.True(binderResult.IsModelSet); Assert.Same(canReadFormatter1, binderResult.Model); }