private static async Task AddValueProviderAsync(ValueProviderFactoryContext context, HttpRequest request)
    {
        IFormCollection form;

        try
        {
            form = await request.ReadFormAsync();
        }
        catch (InvalidDataException ex)
        {
            // ReadFormAsync can throw InvalidDataException if the form content is malformed.
            // Wrap it in a ValueProviderException that the CompositeValueProvider special cases.
            throw new ValueProviderException(Resources.FormatFailedToReadRequestForm(ex.Message), ex);
        }
        catch (IOException ex)
        {
            // ReadFormAsync can throw IOException if the client disconnects.
            // Wrap it in a ValueProviderException that the CompositeValueProvider special cases.
            throw new ValueProviderException(Resources.FormatFailedToReadRequestForm(ex.Message), ex);
        }

        if (form.Files.Count > 0)
        {
            var valueProvider = new FormFileValueProvider(form.Files);
            context.ValueProviders.Add(valueProvider);
        }
    }
    public void GetValue_ReturnsNoneResult()
    {
        // Arrange
        var httpContext = new DefaultHttpContext();

        httpContext.Request.ContentType = "multipart/form-data";
        var formFiles = new FormFileCollection();

        formFiles.Add(new FormFile(Stream.Null, 0, 10, "file", "file"));
        httpContext.Request.Form = new FormCollection(new Dictionary <string, StringValues>(), formFiles);

        var valueProvider = new FormFileValueProvider(formFiles);

        // Act
        var result = valueProvider.GetValue("file");

        // Assert
        Assert.Equal(ValueProviderResult.None, result);
    }
    public void ContainsPrefix_ReturnsTrue_IfFileExists()
    {
        // Arrange
        var httpContext = new DefaultHttpContext();

        httpContext.Request.ContentType = "multipart/form-data";
        var formFiles = new FormFileCollection();

        formFiles.Add(new FormFile(Stream.Null, 0, 10, "file", "file"));
        httpContext.Request.Form = new FormCollection(new Dictionary <string, StringValues>(), formFiles);

        var valueProvider = new FormFileValueProvider(formFiles);

        // Act
        var result = valueProvider.ContainsPrefix("file");

        // Assert
        Assert.True(result);
    }