Table of Contents

Uploading files to the InputFile component

bUnit comes with integrated support for the InputFile component and makes it easy to simulate uploading files.

To upload a file, first find the InputFile component in the component under test. Afterward, call the method UploadFile:

// Create an InputFileContent with string content
InputFileContent fileToUpload = InputFileContent.CreateFromText("Text content", "Filename.txt");

// Render the component under test which contains the InputFile component as a child component
IRenderedComponent<ComponentUnderTest> cut = RenderComponent<ComponentUnderTest>();

// Find the InputFile component
IRenderedComponent<InputFile> inputFile = cut.FindComponent<InputFile>();

// Upload the file to upload to the InputFile component

// Assertions...

To upload binary content, create an InputFileContent with the InputFileContent.CreateFromBinary() method.

Progress Telerik

Premium sponsor: Progress Telerik.


Editorial support provided by Packt.

.NET Foundation

Supported by the .NET Foundation.