473,563 Members | 2,884 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4465
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.co m

"Luigi" <ci************ ****@inwind.itw rote in message
news:03******** *************** ***********@mic rosoft.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:\myf ile.txt");
Assert.AreEqual (true,b);
That looks like the basic setup to me.

"Luigi" <ci************ ****@inwind.itw rote in message
news:03******** *************** ***********@mic rosoft.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.Delet e();
string line = String.Empty;
StreamWriter oSWriter = new StreamWriter(fi leName);
oSWriter.WriteL ine("TEST:" +
DateTime.Today. ToString("yyMMd d"));
oSWriter.Close( );

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

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

aSR.Close();
oSWriter.Dispos e(); //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
1955
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 checked into VSS along with all the associated projects. Many developers need to work on the same solution. The problem that I am having is getting a...
2
14233
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 following examples that came with NUnit and when I tried to compile Nunit test file here is the error i received: ...
5
4634
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 new connection is established. My Server code is : ---------------------------------------------------------------------
6
8343
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 express at home (the labs may have an earlier version). does anyone know how to tell visual studio to use this dll? thanks
20
1991
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. Hence can someone who has used them before share his/her experience on them so that I can get a better idea and make a proper choice ? Any link or...
6
6062
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 Client Name, phone number, email, etc. I want to the NUNIT to read this data from a file. This way I can change the data in a file easily and test...
0
1990
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 AutoCompleteMode Property (AutoCompleteMode.Append) for the Combo at runtime and also have hidden these properties at design time. Now, when I am...
2
5150
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 (e.g. nunit.util.tests.dll) so the install of NUnit seems OK. I've compiled one of the sample projects (csharp-sample_VS2005). When I do so I get...
1
2991
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 myCurrentToken = new UsernameToken("xxxx", "YYY", PasswordOption.SendPlainText); MyServicesWse adminServices = new MyServicesWse();
5
4466
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 one of the classes in this application needs to read a file from file system. The path is one directory below app path. e.g. if application is in...
0
7664
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7583
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7885
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8106
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7638
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7948
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5484
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3642
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
923
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.