Solved

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

Posted on 2008-09-30
1
268 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

777 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