public void BinderReturnsDefaultCancellationToken()
        {
            // Arrange
            CancellationTokenModelBinder binder = new CancellationTokenModelBinder();

            // Act
            object binderResult = binder.BindModel(controllerContext: null, bindingContext: null);

            // Assert
            Assert.Equal(default(CancellationToken), binderResult);
        }
        public async Task CancellationTokenModelBinder_ReturnsNull_ForNonCancellationTokenType(Type t)
        {
            // Arrange
            var bindingContext = GetBindingContext(t);
            var binder = new CancellationTokenModelBinder();

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

            // Assert
            Assert.Null(result);
        }
        public async Task CancellationTokenModelBinder_ReturnsFalse_ForNonCancellationTokenType(Type t)
        {
            // Arrange
            var bindingContext = GetBindingContext(t);
            var binder         = new CancellationTokenModelBinder();

            // Act
            var bound = await binder.BindModelAsync(bindingContext);

            // Assert
            Assert.Null(bound);
        }
        public async Task CancellationTokenModelBinder_ReturnsNull_ForNonCancellationTokenType(Type t)
        {
            // Arrange
            var bindingContext = GetBindingContext(t);
            var binder         = new CancellationTokenModelBinder();

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

            // Assert
            Assert.Equal(default(ModelBindingResult), result);
        }
Beispiel #5
0
    public async Task CancellationTokenModelBinder_ReturnsNonEmptyResult_ForCancellationTokenType()
    {
        // Arrange
        var bindingContext = GetBindingContext(typeof(CancellationToken));
        var binder         = new CancellationTokenModelBinder();

        // Act
        await binder.BindModelAsync(bindingContext);

        // Assert
        Assert.True(bindingContext.Result.IsModelSet);
        Assert.Equal(bindingContext.HttpContext.RequestAborted, bindingContext.Result.Model);
    }
        public async Task CancellationTokenModelBinder_ReturnsTrue_ForCancellationTokenType()
        {
            // Arrange
            var bindingContext = GetBindingContext(typeof(CancellationToken));
            var binder         = new CancellationTokenModelBinder();

            // Act
            var bound = await binder.BindModelAsync(bindingContext);

            // Assert
            Assert.NotNull(bound);
            Assert.Equal(bindingContext.OperationBindingContext.HttpContext.RequestAborted, bound.Model);
        }
        public async Task CancellationTokenModelBinder_ReturnsNotNull_ForCancellationTokenType()
        {
            // Arrange
            var bindingContext = GetBindingContext(typeof(CancellationToken));
            var binder = new CancellationTokenModelBinder();

            // Act
            var bound = await binder.BindModelAsync(bindingContext);

            // Assert
            Assert.NotNull(bound);
            Assert.Equal(bindingContext.OperationBindingContext.HttpContext.RequestAborted, bound.Model);
        }
        public async Task CancellationTokenModelBinder_ReturnsNonEmptyResult_ForCancellationTokenType()
        {
            // Arrange
            var bindingContext = GetBindingContext(typeof(CancellationToken));
            var binder = new CancellationTokenModelBinder();

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

            // Assert
            Assert.NotEqual(ModelBindingResult.NoResult, result);
            Assert.True(result.IsModelSet);
            Assert.Equal(bindingContext.OperationBindingContext.HttpContext.RequestAborted, result.Model);
        }
Beispiel #9
0
        public async Task CancellationTokenModelBinder_ReturnsNotNull_ForCancellationTokenType()
        {
            // Arrange
            var bindingContext = GetBindingContext(typeof(CancellationToken));
            var binder         = new CancellationTokenModelBinder();

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

            // Assert
            Assert.NotNull(result);
            Assert.True(result.IsModelSet);
            Assert.Equal(bindingContext.OperationBindingContext.HttpContext.RequestAborted, result.Model);
            Assert.NotNull(result.ValidationNode);
            Assert.True(result.ValidationNode.SuppressValidation);
        }