Click here to Skip to main content
13,143,628 members (32,473 online)
Click here to Skip to main content
Articles » Web Development » ASP.NET » Howto » Downloads

Stats

63K views
676 downloads
35 bookmarked
Posted 7 Jun 2007

Unit Testing a DotNetNuke Private Assembly Module

, 18 Jun 2007
This article describes how to create unit tests that will test out code for a DotNetNuke custom module.
iFinity.DNN.Utilities.dll
DnnUnitTesting
bin
DnnUnitTesting
bin
Debug
obj
Debug
Refactor
TempPE
Properties
DnnUnitTesting.vsmdi
iFinity.DnnUtilities
bin
Debug
Release
iFinity.DNN.Utilities.csproj.vspscc
obj
Debug
Refactor
TempPE
Release
TempPE
Properties
localtestrun.testrunconfig
TestResults
Bruce_WOMBAT 2007-06-08 09_08_45
In
WOMBAT
Out
Bruce_WOMBAT 2007-06-08 09_10_02
In
WOMBAT
Out
Bruce_WOMBAT 2007-06-08 09_11_13
In
WOMBAT
Out
Bruce_WOMBAT 2007-06-08 09_15_14
In
WOMBAT
Out
Bruce_WOMBAT 2007-06-08 09_16_18
In
WOMBAT
Out
Bruce_WOMBAT 2007-06-08 09_16_52
In
WOMBAT
Out
Bruce_WOMBAT 2007-06-08 09_20_35
In
WOMBAT
Out
/*
 * 
 * iFinity Smart Business Solutions - http://www.ifinity.com.au
 * Copyright (c) 2007
  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
 * documentation files (the "Software"), the rights to use, copy, modify, merge, publish, distribute, sublicense
 * copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the 
 * following conditions:

 * 1. The above copyright notice and this permission notice shall be included in all copies or substantial portions 
 *    of the Software.  
 * 2. The software may not be claimed as the original work and may not be sold as a stand alone product

 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
 * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
 * DEALINGS IN THE SOFTWARE.
 * 
 */
using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using DotNetNuke.Data;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace iFinity.DNN.Utilities.Testing
{
    public class DnnUnitTest
    {
        SqlDataProvider _sqlProvider;
        TestContext testContextInstance;
        int _portalId;
        public TestContext TestContext
        {
            get { return testContextInstance; }
            set { testContextInstance = value; }
        }
        public int PortalId
        {
            get
            {
                return _portalId;
            }
        }
        public DnnUnitTest(int portalID)
        {
            DnnUnitTestSection dnnUnitTest = (DnnUnitTestSection)ConfigurationManager.GetSection("iFinity/dnnUnitTest");
            if (dnnUnitTest == null)
                throw new System.Configuration.ConfigurationErrorsException("The iFinity/dnnUnitTest section was not found in the config file");
            UnitTestHelper.SetHttpContextWithSimulatedRequest(dnnUnitTest.SimulatedServer, dnnUnitTest.AppName, dnnUnitTest.AppPath, dnnUnitTest.SimulatedPage);
            DotNetNuke.Common.Globals.ServerName = dnnUnitTest.SimulatedServer;
            DotNetNuke.Common.Globals.HostMapPath = dnnUnitTest.HostMapPath;
            DotNetNuke.Common.Globals.ApplicationPath = dnnUnitTest.AppPath;
            DotNetNuke.Entities.Portals.PortalAliasInfo objPortalAliasInfo = new DotNetNuke.Entities.Portals.PortalAliasInfo();
            objPortalAliasInfo.PortalID = portalID;
            DotNetNuke.Entities.Portals.PortalSettings ps = new DotNetNuke.Entities.Portals.PortalSettings(-1, objPortalAliasInfo);
            System.Web.HttpContext.Current.Items.Add("PortalSettings", ps);
            _sqlProvider = new SqlDataProvider();
            _portalId = portalID;
        }
    }
    public class DnnUnitTestSection : ConfigurationSection
    {
        [ConfigurationProperty("hostMapPath", DefaultValue = "C:\\DotNetNuke", IsRequired = true)]
        public string HostMapPath
        {
            get { return (string)this["hostMapPath"]; }
            set { this["hostMapPath"] = value; }
        }
        [ConfigurationProperty("appName", DefaultValue = "DotNetNuke", IsRequired = true)]
        public string AppName
        {
            get { return (string)this["appName"]; }
            set { this["appName"] = value; }
        }
        [ConfigurationProperty("appPath", DefaultValue = "C:\\DotNetNuke", IsRequired = true)]
        public string AppPath
        {
            get { return (string)this["appPath"]; }
            set { this["appPath"] = value; }
        }
        [ConfigurationProperty("simulatedServer", DefaultValue = "localhost", IsRequired = true)]
        public string SimulatedServer
        {
            get { return (string)this["simulatedServer"]; }
            set { this["simulatedServer"] = value; }
        }
        [ConfigurationProperty("simulatedPage", DefaultValue = "Default.aspx", IsRequired = true)]
        public string SimulatedPage
        {
            get { return (string)this["simulatedPage"]; }
            set { this["simulatedPage"] = value; }
        }

    }

}

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)

Share

About the Author

Bruce Chapman DNN
Product Manager DNN Corp
Australia Australia
Bruce Chapman is the Product Manager for Cloud Services at DNN. He’s been an active member of the DNN Community since 2006 as a contributor, vendor and now employee of DNN Corp.

You can read his blog at http://dnnsoftware.com/blog or follow him on Twitter @brucerchapman

You may also be interested in...

Pro
Pro
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.170915.1 | Last Updated 19 Jun 2007
Article Copyright 2007 by Bruce Chapman DNN
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid