473,386 Members | 1,693 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,386 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 4457
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.