Solved

how can i set App.Config values while testing with nunit?

Posted on 2008-09-30
1
265 Views
Last Modified: 2013-12-17
how can i set values in order to test my code.

   public Hashtable MyMethod()
        {
            string _pathFTP = ConfigurationSettings.AppSettings["FTP_HOST_FEEDING_CONTAINER"];
            string _user = ConfigurationSettings.AppSettings["FTP_USER"];
            string _pass = ConfigurationSettings.AppSettings["FTP_PASS"];

          ...
         }


  now , i'd like to test this with Nunit,
i have a test method as follow.

 [Test]
public void testing MyMethod(){
                      <---- how can i set my ftp values, as they are not existent in my method process while testing
    assert(...);
}

the aim is not to change my method code,
0
Comment
Question by:toshi_
1 Comment
 
LVL 10

Accepted Solution

by:
oxyoo earned 250 total points
ID: 22603702
One solution would be to put those variables as parameters instead.
public Hashtable MyMethod(string pathFTP, string user, string pass)

{

   ...

}
 
 

[Test]

public void MyMethodTest(){

    // Instantiate myObj, etc..

    Hashtable table = myObj.MyMethod(pathFTP, user, pass);

    assert(tableExcepected, table);

}

Open in new window

0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video discusses moving either the default database or any database to a new volume.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now