Click here to Skip to main content
15,867,756 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am doing the unit testing of application service using Xunit.net.

My unit test case is not getting partially executed because of following statement:
StringCipher stringCipher = new StringCipher();

StringCipher is class in which I have written the logic for password encryption and decryption.

Even it goes inside the constructor of StringCipher class but throwing exception inside the constructor:

C#
public class StringCipher
{
private readonly byte[] _initVectorBytes = null;       
        private const int KeySize = 256;
        public StringCipher()
        {
            _initVectorBytes = Encoding.ASCII.GetBytes(ConfigurationManager.AppSettings["PasswordEncryptionKey"]);
        }
}



Please let me know how can I resolve this issue?
Posted
Updated 6-Apr-15 20:50pm
v4
Comments
CHill60 7-Apr-15 3:20am    
You may need to include the application settings from the main project in the test project (so that the tests can access your AppSettings)
Prasad Kalamkar 7-Apr-15 5:56am    
Thanks a lot!. That's the solution.

I have copied appsettings values to my test project class.
 
Share this answer
 
An alternative to just copying the appsettings to the test project is as follows:

In your test project right-click, Add, Existing Item.

Navigate to the App.Config for the project you are trying to test.
Instead of just clicking "Add" click the down-arrow next to it and select "Add as Link".

This means that both projects in the solution are "pointing at" exactly the same file - which means you don't have to keep the two of them synchronised.

You can see that the icons in Solution Explorer are slightly different - in the test project there is "shortcut" marker on the icon. In fact if you click on App.config in the Test project it will "jump" to the actual file in the other project.

Note - if you Add As Link a file from the bin folder you may get an error in the test project when you rebuild the solution saying that the file does not exist - if you rebuild again this will go away (because the first build will have copied the project app.config to the correct folder) - as long as you have "Copy Always" set as the "Copy to Output Directory" option.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900