예제 #1
0
    public async Task CreateValueProviderAsync_DoesNotAddValueProvider_IfFileCollectionIsEmpty()
    {
        // Arrange
        var factory = new FormFileValueProviderFactory();
        var context = CreateContext("multipart/form-data");

        // Act
        await factory.CreateValueProviderAsync(context);

        // Assert
        Assert.Empty(context.ValueProviders);
    }
예제 #2
0
    public async Task CreateValueProviderAsync_DoesNotAddValueProvider_IfRequestDoesNotHaveFormContent()
    {
        // Arrange
        var factory = new FormFileValueProviderFactory();
        var context = CreateContext("application/json");

        // Act
        await factory.CreateValueProviderAsync(context);

        // Assert
        Assert.Empty(context.ValueProviders);
    }
예제 #3
0
    public async Task GetValueProviderAsync_ThrowsOriginalException_IfReadingFormThrows()
    {
        // Arrange
        var exception            = new TimeZoneNotFoundException();
        var valueProviderContext = CreateThrowingContext(exception);

        var factory = new FormFileValueProviderFactory();

        // Act & Assert
        var ex = await Assert.ThrowsAsync <TimeZoneNotFoundException>(() => factory.CreateValueProviderAsync(valueProviderContext));

        Assert.Same(exception, ex);
    }
예제 #4
0
    public async Task GetValueProviderAsync_ThrowsValueProviderException_IfReadingFormThrowsInvalidOperationException()
    {
        // Arrange
        var exception            = new IOException();
        var valueProviderContext = CreateThrowingContext(exception);

        var factory = new FormFileValueProviderFactory();

        // Act & Assert
        var ex = await Assert.ThrowsAsync <ValueProviderException>(() => factory.CreateValueProviderAsync(valueProviderContext));

        Assert.Same(exception, ex.InnerException);
    }
예제 #5
0
    public async Task CreateValueProviderAsync_AddsValueProvider()
    {
        // Arrange
        var factory = new FormFileValueProviderFactory();
        var context = CreateContext("multipart/form-data; boundary=----WebKitFormBoundarymx2fSWqWSd0OxQqq");
        var files   = (FormFileCollection)context.ActionContext.HttpContext.Request.Form.Files;

        files.Add(new FormFile(Stream.Null, 0, 10, "some-name", "some-name"));

        // Act
        await factory.CreateValueProviderAsync(context);

        // Assert
        Assert.Collection(
            context.ValueProviders,
            v => Assert.IsType <FormFileValueProvider>(v));
    }