473,230 Members | 1,414 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,230 software developers and data experts.

NUnit: Test for file system

Hi all,
with NUnit (C#) which is the better way to implement some tests to operate
on a file in the file system?
For instance: file exists, file read and file write.

Thanks in advance.
--
Luigi

Jul 14 '08 #1
5 4452
Luigi,

Why not just use the classes in the System.IO namespace to determine if
the file exists, and to read/write from/to the file?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Luigi" <ci****************@inwind.itwrote in message
news:03**********************************@microsof t.com...
Hi all,
with NUnit (C#) which is the better way to implement some tests to operate
on a file in the file system?
For instance: file exists, file read and file write.

Thanks in advance.
--
Luigi

Jul 14 '08 #2
Use dependency injection or the service pattern to obtain a reference to an
interface that provides these functions, and use mocks to mock them during
testing.

Pete

Jul 14 '08 #3
I'm confused about what you're asking.
bool b = System.IO.File.Exists(@"C:\myfile.txt");
Assert.AreEqual(true,b);
That looks like the basic setup to me.

"Luigi" <ci****************@inwind.itwrote in message
news:03**********************************@microsof t.com...
Hi all,
with NUnit (C#) which is the better way to implement some tests to operate
on a file in the file system?
For instance: file exists, file read and file write.

Thanks in advance.
--
Luigi

Jul 14 '08 #4
Yes, something similar.
Not also verify that the file exists, but also that I can read it.
A full tests for file system access and reading.

Luigi
Jul 15 '08 #5
i od have something like this

public static bool IsFileWritable(string fileName)
{
//write at least one single line into file,
//used by unit test
try
{
//to clear file use
// FileInfo afileinfo = new FileInfo("list.txt");
afileinfo.Delete();
string line = String.Empty;
StreamWriter oSWriter = new StreamWriter(fileName);
oSWriter.WriteLine("TEST:" +
DateTime.Today.ToString("yyMMdd"));
oSWriter.Close();

//Chk segments in created file
StreamReader aSR = new StreamReader(fileName);

line = aSR.ReadLine();
if (line == null) return false;
if (!line.StartsWith("TEST:")) return false;

aSR.Close();
oSWriter.Dispose(); //remove from memory,does not delete file
return true;
}
catch (Exception)
{
return false;
}
}
"Luigi" wrote:
Yes, something similar.
Not also verify that the file exists, but also that I can read it.
A full tests for file system access and reading.

Luigi
Jul 28 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Peter Rilling | last post by:
My development team is using VS.NET with VSS integration. They are able to check in and out from within VS.NET. We also use NUnit for testing our libraries. Currently our entire solution is...
2
by: d2d | last post by:
How are you doing there folks? I just have this newbie question about how to compile an NUnit test file from command line using "csc.exe" I installed NUnit 2.1 using *.msi file. I was...
5
by: Naveen Mukkelli | last post by:
Hi all, How can we use "NUnit" in socket programming. I mean, I'm writing a server program which accepts connection requests from the clients. I want to test the number of clients whenever a...
6
by: Ray Tayek | last post by:
hi, i am preparing to teach a class in c++ and would like to intoduce some unit testing. i can make unit tests in c# using this dll and nant from the command line. i am using visual c++ 2005...
20
by: Parag | last post by:
Hi, I am trying to figure out best testing tool for my project. I have narrowed down my requirements to two tools NUNIT and VSTS unit. But I have used neither and I have to use only one of them....
6
by: tchaiket | last post by:
Hey all, I'm using NUNIT to test our classes. However, I don't want to hard code test data into the NUNIT classes. For example, to test adding a new Client, I don't want to hard code the...
0
by: angshuman.agarwal | last post by:
Hi, I have a owner drawn combo box (using .Net 2.0 Framework). I have written the Nunit test for the same. I am setting the AutoCompleteSource Property (AutoCompleteSource.CustomSource) and...
2
by: JohnGoogle | last post by:
Hi, I'm a newbie so sorry if there is a simple answer to this! I'm using C# in Visual Studio Express at the moment. I've downloaded NUnit v 2.2.8 and can load and run the tests they supply...
1
by: nyathancha | last post by:
Hi, I am using WSE to implement security using x509 certificates. This works when I use a windows client but throws an exception when I use NUnit. My Code looks as follows : UsernameToken...
5
nikpreek
by: nikpreek | last post by:
Hi All, This is my first post, I've been finding lots of solutions from this forum. Thanks to all who helped (and ones who asked questions). I have a strange problem. I'm having a console app and...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.