Precept 0.14.0

Precept.Files

Excel, CSV, JSON and XML files for Precept tests. Write a workbook or a CSV from a data table or a query result, append a row to a file the system under test produced, read a file back as rows, and build, query, change and assert on JSON and XML documents. Every file a test writes lands in its artifacts and is attached to its result.

dotnet add package Precept.Files
services.AddPreceptFiles();
// A Reqnroll DataTable's rows in, a spreadsheet out. The package never references Reqnroll:
// a row is anything dictionary-shaped, or an object whose properties are the columns.
var path = await Excel.WriteAsync("clients.xlsx", table.Rows, sheet: "Clients");

// A row appended under the columns the sheet already has, whatever their order:
using var export = Excel.Open("export.xlsx");
export.Sheet("Clients").AddRow(new { Name = "Acme", Email = "acme@example.test" });
await export.SaveAsync();

await Assert.That(export.Sheet("Clients")).ToContainRowsAsync(table.Rows);

var order = Json.New().Set("customer.id", 42).Set("lines", Json.Array(table.Rows));
await Assert.That(Json.Parse(response.Body).At("lines")).ToContainRowsAsync(table.Rows);

var shipment = Xml.Load("shipment.xml").WithDefaultNamespace("s");
await Assert.That(shipment).ToHaveValueAsync("/s:shipment/s:status", "accepted");

A sheet, a CSV file and a JSON array share one model, a header with rows under it by column name, and one set of row assertions. A bare file name is written into the running test's artifact directory, which is unique to the test and one step from every report. It is read from there first, then from beside the test binary. The ClosedXML worksheet, the JsonNode and the XDocument underneath are one property away, so nothing the libraries can do is out of reach.


Part of Precept, a .NET 10 test framework built on Microsoft.Testing.Platform. Full documentation: files · Excel · CSV · JSON · XML · where files go

Precept 0.14.0 · MIT · © 2026

Esc