Click here to Skip to main content
15,880,725 members
Articles / Web Development / ASP.NET

Configuration Manager for the Enterprise

Rate me:
Please Sign up or sign in to vote.
4.58/5 (27 votes)
8 Aug 2007CPOL20 min read 62.8K   341   73  
SysConfiguration is a component that allows the storing of configuration data for an enterprise application. It is intended to be an improved version of the System.Configuration class or the Enterprise Library (Microsoft Patterns and Practices).
//////////////////////////////////////////////////////////////////////////////////////////
// Copyright : Randar Puust
// 
// Email : Developer@Puust.com 
// 
// This code may be used in compiled form in any way you desire. This
// file may be redistributed by any means providing that this 
// notice and the authors name is included.
//
// This software and documentation is provided "as is," and copyright holders 
// make no representations or warranties, express or implied, including but not limited to, 
// warranties of merchantability or fitness for any particular purpose or that the use 
// of the software or documentation will not infringe any third party patents, copyrights, 
// trademarks or other rights.
// 
// Copyright holders will not be liable for any direct, indirect, special or consequential 
// damages arising out of any use of the software or documentation.
//////////////////////////////////////////////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.Text;

// NUnit Unit Testing Framework
using NUnit.Framework;
using NUnit.Extensions.Asp;
using NUnit.Extensions.Asp.AspTester;

// Namespace for configuration class
using Name.Randar.Configuration;

namespace Name.Randar.UnitTests
{
    /// <summary>
    /// These tests make sure the projects work in a web context
    /// </summary>
    [TestFixture]
    public class TestWeb : WebFormTestCase
    {
        #region Web Test Helpers
        /// <summary>
        /// This is what the text box will be set to if it passes.
        /// </summary>
        private const string _passString = "Pass";
        private const string _webURL = "http://localhost:1621/WebTests.aspx";

        /// <summary>
        /// A wrapper function that helps prepare and validate the result of a test
        /// </summary>
        /// <param name="buttonName"></param>
        private void ExecuteTest(string buttonName)
        {
            // This test assumes that the result of the test will be in this text box
            TextBoxTester textResult = new TextBoxTester("txtResult", CurrentWebForm);
            // If a test failed, a message should be here as to the reason
            TextBoxTester textMessage = new TextBoxTester("txtMessage", CurrentWebForm);

            // This is the button to press to execute the test
            ButtonTester buttonTestSettings = new ButtonTester(buttonName, CurrentWebForm);

            // Second, visit the page being tested:
            Browser.GetPage(_webURL);

            buttonTestSettings.Click();
            AssertEquals(textMessage.Text, _passString, textResult.Text);
        }
        #endregion

// This macro shows\hides functionality that will only work with the sample configuration file.  This allows the other unit test to still be used if the unit tests are re-used for another project.
#if USING_SAMPLE_CONFIGURATION
        /// <summary>
        /// This will call the configuration class and get it to return the structure.  It will then validate that structure.  
        /// It does not actually check what is in the data.
        /// </summary>
        [Test]
        public void TestConfigurationStructure()
        {
            ExecuteTest("btnConfigurationStructure");
        }

        /// <summary>
        /// This test will call the web page and see if the sturcture passed in a web context
        /// </summary>
        [Test]
        public void TestConnectionString()
        {
            ExecuteTest("btnTestConnectionString");
        }
#endif
        /// <summary>
        /// This test verifies that the same object comes back out of the singleton.
        /// </summary>
        [Test]
        public void TestSameObject()
        {
            ExecuteTest("btnSameObject");
        }

        /// <summary>
        /// This checks the value of the GetXMLPath method.
        /// </summary>
        [Test]
        public void TestGetXMLPath()
        {
            ExecuteTest("btnGetXMLPath");
        }

        /// <summary>
        /// This checks the value of the GetSchemaPath method.
        /// </summary>
        [Test]
        public void TestGetSchemaPath()
        {
            ExecuteTest("btnGetSchemaPath");
        }

        /// <summary>
        /// This will clear out the class and then access it again.  This should refresh the data
        /// that has been cached.
        /// </summary>
        [Test]
        public void TestRefreshingData()
        {
            ExecuteTest("btnTestRefreshingData");
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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


Written By
Architect OrderDynamics
Canada Canada
Shipping product and getting teams to work at peak efficiency are my passions. I’m a firm believer in Agile methodologies, proper engineering practices with a focus on Software as a Service (SaaS). My extensive knowledge of technology as well as my passion, loyalty and ability to learn quickly will add value to any company. Many of my duties have included working closely with customers and I am known for being a great communicator of ideas and concepts.

Comments and Discussions