Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use the file Asserts in Nunit and check the files are present or not

how to use the file Asserts in Nunit and check the files are present or not.Need some examples for clear and basic understanding.Can any one please help me

like image 513
Vamsi Krishna Avatar asked Sep 26 '14 03:09

Vamsi Krishna


People also ask

How do I use Assert in NUnit?

Asserts that a condition is true. If the condition is false the method throws an AssertionException. Asserts that a condition is true. If the condition is false the method throws an AssertionException.

Which of the following are assertion models in NUnit?

There are two assertion models in NUnit Test: Classic Model: Before NUnit 2.4, each assertion was handled by various types of Assert class functions. This is referred to as the classic model. Constraint Model: A revolutionary constraint-based framework is being introduced with NUnit 2.4.


2 Answers

NUnit 3.0 includes a FileOrDirectoryExistsConstraint.

var filePath = "C:\pathtofile.txt";
Assert.That(filePath, Does.Exist);
like image 88
Matthew Bald Avatar answered Oct 21 '22 05:10

Matthew Bald


You should use:

var fileName = @"C:\somedirectory\somefile.txt";

Assert.IsTrue(File.Exists(fileName));

FileAssert can be only used for comparison of two actual files from disc of from some abstract stream

like image 24
rufanov Avatar answered Oct 21 '22 05:10

rufanov