Solved

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

Posted on 2008-09-30
1
272 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_
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

What is a Denial of Service (DoS)?

A DoS is a malicious attempt to prevent the normal operation of a computer system. You may frequently see the terms 'DDoS' (Distributed Denial of Service) and 'DoS' used interchangeably, but there are some subtle differences.

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…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

623 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