...

/

Assertion Methods Available in Fluent Assertions

Assertion Methods Available in Fluent Assertions

Discover the extension methods supported by the Fluent Assertions library.

In this lesson, we ’ll cover most of the main assertion extension methods supported by Fluent Assertions. We’ll do so with the aid of the following playground:

namespace MainApp;

public class DataManager
{
    private readonly List<string?> _collection;

    public DataManager()
    {
        _collection = new List<string?>();
    }

    public List<string?> ReadAll()
    {
        return _collection;
    }

    public void DeleteAt(int index)
    {
        _collection.RemoveAt(index);
    }

    public void DeleteAll()
    {
        _collection.Clear();
    }

    public void Insert(string? newItem)
    {
        _collection.Add(newItem);
    }
}
xUnit setup with a wide range of Fluent Assertions examples

In this playground, we add multiple redundant assertions to demonstrate several ways of testing the outputs.

Extension methods supported by Fluent Assertions

As with the standard xUnit assertions, the assertions enabled by the Fluent Assertions libraries fall under several categories. Let’s walk through all of them. In the playground above, all our test codes are in the DataManagerTestsWithFluentAssertions.cs file under the MainApp.Tests project folder.

Value assertions

These assertions verify the values of variables, fields, and properties.

The Be() method

This extension method is used to check for a specific value. We have the following example of this method on line 26, where we validate ...