Legacy Documentation. View NUnit 3 Documentation

Path Constraints (NUnit 2.5)

Path constraints perform tests on paths, without reference to any actual files or directories. This allows testing paths that are created by an application for reference or later use, without any effect on the environment.

Path constraints are intended to work across multiple file systems, and convert paths to a canonical form before comparing them.

It is usually not necessary to know the file system of the paths in order to compare them. Where necessary, the programmer may use the IgnoreCase and RespectCase modifiers to provide behavior other than the system default.

SamePathConstraint

Action

Tests that two paths are equivalent.

Constructor

SamePathConstraint( string expectedPath )

Syntax

Is.SamePath( string expectedPath )

Modifiers

...IgnoreCase
...RespectCase

Examples of Use

Assert.That( "/folder1/./junk/../folder2",
	Is.SamePath( "/folder1/folder2" ) );
Assert.That( "/folder1/./junk/../folder2/x",
	Is.Not.SamePath( "/folder1/folder2" ) );

Assert.That( @"C:\folder1\folder2",
	Is.SamePath( @"C:\Folder1\Folder2" ).IgnoreCase );
Assert.That( "/folder1/folder2",
	Is.Not.SamePath( "/Folder1/Folder2" ).RespectCase );

SamePathOrUnderConstraint

Action

Tests that one path is equivalent another path or that it is under it.

Constructor

SamePathOrUnderConstraint( string expectedPath )

Syntax

Is.SamePathOrUnder( string expectedPath )

Modifiers

...IgnoreCase
...RespectCase

Examples of Use

Assert.That( "/folder1/./junk/../folder2",
	Is.SamePathOrUnder( "/folder1/folder2" ) );
Assert.That( "/folder1/junk/../folder2/./folder3",
	Is.SamePathOrUnder( "/folder1/folder2" ) );
Assert.That( "/folder1/junk/folder2/folder3",
	Is.Not.SamePathOrUnder( "/folder1/folder2" ) );

Assert.That( @"C:\folder1\folder2\folder3",
	Is.SamePathOrUnder( @"C:\Folder1\Folder2" ).IgnoreCase );
Assert.That( "/folder1/folder2/folder3",
	Is.Not.SamePathOrUnder( "/Folder1/Folder2" ).RespectCase );