public async Task BindModelAsync_ReturnsNull_ForNonHttpRequestMessageType(Type type)
        {
            // Arrange
            var binder         = new HttpRequestMessageModelBinder();
            var bindingContext = GetBindingContext(type);

            // Act
            await binder.BindModelAsync(bindingContext);

            // Assert
            Assert.False(bindingContext.Result.HasValue);
        }
        public async Task BindModelAsync_BindsHttpRequestMessage()
        {
            // Arrange
            var binder = new HttpRequestMessageModelBinder();
            var bindingContext = GetBindingContext(typeof(HttpRequestMessage));
            var expectedModel = bindingContext.HttpContext.GetHttpRequestMessage();

            // Act
            await binder.BindModelAsync(bindingContext);

            // Assert
            var result = bindingContext.Result;
            Assert.True(result.IsModelSet);
            Assert.Same(expectedModel, result.Model);

            var entry = bindingContext.ValidationState[result.Model];
            Assert.True(entry.SuppressValidation);
            Assert.Null(entry.Key);
            Assert.Null(entry.Metadata);
        }
Example #3
0
        public async Task BindModelAsync_BindsHttpRequestMessage()
        {
            // Arrange
            var binder         = new HttpRequestMessageModelBinder();
            var bindingContext = GetBindingContext(typeof(HttpRequestMessage));
            var expectedModel  = bindingContext.HttpContext.GetHttpRequestMessage();

            // Act
            await binder.BindModelAsync(bindingContext);

            // Assert
            var result = bindingContext.Result;

            Assert.True(result.IsModelSet);
            Assert.Same(expectedModel, result.Model);

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

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