Ejemplo n.º 1
0
        public async Task BindingSourceModelBinder_ReturnsNonNull_MatchingSource(bool isModelSet)
        {
            // Arrange
            var provider = new TestModelMetadataProvider();

            provider.ForType <string>().BindingDetails(d => d.BindingSource = BindingSource.Body);
            var modelMetadata = provider.GetMetadataForType(typeof(string));
            var context       = new ModelBindingContext()
            {
                ModelMetadata   = modelMetadata,
                BindingSource   = modelMetadata.BindingSource,
                BinderModelName = modelMetadata.BinderModelName
            };

            var binder = new TestableBindingSourceModelBinder(BindingSource.Body, isModelSet);

            // Act
            var result = await binder.BindModelAsync(context);

            // Assert
            Assert.NotNull(result);
            Assert.Equal(isModelSet, result.IsModelSet);
            Assert.Null(result.Model);
            Assert.True(binder.WasBindModelCoreCalled);
        }
Ejemplo n.º 2
0
        public async Task BindingSourceModelBinder_ReturnsFalse_WithNoSource()
        {
            // Arrange
            var context = new ModelBindingContext();
            context.ModelMetadata = new EmptyModelMetadataProvider().GetMetadataForType(typeof(string));

            var binder = new TestableBindingSourceModelBinder(BindingSource.Body);

            // Act 
            var result = await binder.BindModelAsync(context);

            // Assert
            Assert.Null(result);
            Assert.False(binder.WasBindModelCoreCalled);
        }
Ejemplo n.º 3
0
        public async Task BindingSourceModelBinder_ReturnsFalse_WithNoSource()
        {
            // Arrange
            var context = new ModelBindingContext();

            context.ModelMetadata = new EmptyModelMetadataProvider().GetMetadataForType(typeof(string));

            var binder = new TestableBindingSourceModelBinder(BindingSource.Body);

            // Act
            var result = await binder.BindModelAsync(context);

            // Assert
            Assert.Null(result);
            Assert.False(binder.WasBindModelCoreCalled);
        }
Ejemplo n.º 4
0
        public async Task BindingSourceModelBinder_ReturnsFalse_NonMatchingSource()
        {
            // Arrange
            var provider = new TestModelMetadataProvider();
            provider.ForType<string>().BindingDetails(d => d.BindingSource = BindingSource.Query);

            var context = new ModelBindingContext();
            context.ModelMetadata = provider.GetMetadataForType(typeof(string));

            var binder = new TestableBindingSourceModelBinder(BindingSource.Body);

            // Act 
            var result = await binder.BindModelAsync(context);

            // Assert
            Assert.Null(result);
            Assert.False(binder.WasBindModelCoreCalled);
        }
Ejemplo n.º 5
0
        public async Task BindingSourceModelBinder_ReturnsFalse_NonMatchingSource()
        {
            // Arrange
            var provider = new TestModelMetadataProvider();

            provider.ForType <string>().BindingDetails(d => d.BindingSource = BindingSource.Query);

            var context = new ModelBindingContext();

            context.ModelMetadata = provider.GetMetadataForType(typeof(string));

            var binder = new TestableBindingSourceModelBinder(BindingSource.Body);

            // Act
            var result = await binder.BindModelAsync(context);

            // Assert
            Assert.Null(result);
            Assert.False(binder.WasBindModelCoreCalled);
        }
Ejemplo n.º 6
0
        public async Task BindingSourceModelBinder_ReturnsTrue_MatchingSource()
        {
            // Arrange
            var provider = new TestModelMetadataProvider();
            provider.ForType<string>().BindingDetails(d => d.BindingSource = BindingSource.Body);
            var modelMetadata = provider.GetMetadataForType(typeof(string));
            var context = new ModelBindingContext()
            {
                ModelMetadata = modelMetadata,
                BindingSource = modelMetadata.BindingSource,
                BinderModelName = modelMetadata.BinderModelName
            };

            var binder = new TestableBindingSourceModelBinder(BindingSource.Body);

            // Act 
            var result = await binder.BindModelAsync(context);

            // Assert
            Assert.NotNull(result);
            Assert.True(result.IsModelSet);
            Assert.True(binder.WasBindModelCoreCalled);
        }