コード例 #1
0
        public async Task ServiceModelBinder_ReturnsNoResult_ForNonServiceBindingSource()
        {
            // Arrange
            var type = typeof(IService);

            var binder = new ServicesModelBinder();
            var modelBindingContext = GetBindingContext(type);
            modelBindingContext.BindingSource = BindingSource.Body;

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

            // Assert
            Assert.Equal(ModelBindingResult.NoResult, result);
        }
コード例 #2
0
        public async Task ServiceModelBinder_ReturnsNoResult_ForNonServiceBindingSource()
        {
            // Arrange
            var type = typeof(IService);

            var binder = new ServicesModelBinder();
            var modelBindingContext = GetBindingContext(type);

            modelBindingContext.BindingSource = BindingSource.Body;

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

            // Assert
            Assert.Equal(ModelBindingResult.NoResult, result);
        }
コード例 #3
0
        public async Task ServiceModelBinder_BindsService()
        {
            // Arrange
            var type = typeof(IService);

            var binder = new ServicesModelBinder();
            var modelBindingContext = GetBindingContext(type);

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

            // Assert
            Assert.NotEqual(ModelBindingResult.NoResult, result);
            Assert.True(result.IsModelSet);
            Assert.NotNull(result.Model);
            Assert.Equal("modelName", result.Key);

            var entry = modelBindingContext.ValidationState[result.Model];
            Assert.True(entry.SuppressValidation);
            Assert.Null(entry.Key);
            Assert.Null(entry.Metadata);
        }
コード例 #4
0
        public async Task ServiceModelBinder_BindsService()
        {
            // Arrange
            var type = typeof(IService);

            var binder = new ServicesModelBinder();
            var modelBindingContext = GetBindingContext(type);

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

            // Assert
            Assert.NotEqual(ModelBindingResult.NoResult, result);
            Assert.True(result.IsModelSet);
            Assert.NotNull(result.Model);
            Assert.Equal("modelName", result.Key);

            var entry = modelBindingContext.ValidationState[result.Model];

            Assert.True(entry.SuppressValidation);
            Assert.Null(entry.Key);
            Assert.Null(entry.Metadata);
        }