Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2008-09-30
1
Medium Priority
?
275 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 750 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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

972 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