Beispiel #1
0
        public async Task ServiceModelBinder_ReturnsNothing_ForNonServiceBindingSource()
        {
            // Arrange
            var type = typeof(IService);

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

            modelBindingContext.BindingSource = BindingSource.Body;

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

            // Assert
            Assert.Equal(default(ModelBindingResult), result);
        }
Beispiel #2
0
        public async Task ServiceModelBinder_BindsService()
        {
            // Arrange
            var type = typeof(IService);

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

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

            // Assert
            Assert.NotEqual(default(ModelBindingResult), 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);
        }