Skip to content

Assertions

Wesley Baartman edited this page Jun 24, 2018 · 12 revisions

Home > Assertions

Subcategories

Introduction

This page describes how you can write assertions using AssertNET.

Chaining

It is good to know that most AssertNET conditions can be chained. This means you can for example write assertions like this:

AssertThat(4)
	.IsLesserThan(10)
	.IsGreaterThan(0)
	.IsInRange(0, 10);

This is also true for the AssertNet.Moq package:

AssertThat(someMock)
	.HasInvoked(x => x.Stub1()).Once()
	.HasInvoked(x => x.Stub2()).Never();

Custom messages

It is possible to supply optional custom failure messages with the following syntax:

AssertThat(4)
	.IsLesserThan(10, "Smaller than 10 assertion.")
	.IsGreaterThan(0, "Greater than 0 assertion.")
	.IsInRange(0, 10, "In range 0-10 assertion.");