Click or drag to resize

DatabaseTestBase Class

Undecorated base class for ice.NET database unit tests. This class can be used with any unit testing framework that supports SetUp and TearDown logic.
Inheritance Hierarchy
SystemObject
  PDTec.IceNet.Sdk.TestDatabaseTestBase

Namespace:  PDTec.IceNet.Sdk.Test
Assembly:  PDTec.IceNet.Sdk (in PDTec.IceNet.Sdk.dll) Version: 7.2.0.0 (7.2.7583.15464)
Syntax
C#
public abstract class DatabaseTestBase

The DatabaseTestBase type exposes the following members.

Constructors
  NameDescription
Public methodDatabaseTestBase
Creates a test class instance.
Top
Properties
  NameDescription
Public propertyBOAssemblyNames
Gets the list of BO assemblies to be loaded for the test.
Public propertyBOFactories
Gets the list of BO factories to be loaded for the test.
Public propertyDatabaseName
Gets or sets the SQL Server database name.
Public propertyLicenseFilePath
Gets or sets the license file path.
Public propertyLogin
Gets the login information. If you want to use trusted connection login on the local machine, there is no need to set anything here.
Protected propertyRepository
Gets the repository entry point for the test.
Public propertyServerName
Gets or sets the SQL Server instance name. Default is (local)\SQLEXPRESS.
Protected propertyTestDatabaseSettings
Public propertyUserName
Gets or sets the name of the user that is used to access the ice.NET infrastructure.
Top
Methods
  NameDescription
Protected methodCreateRepository
Creates a new repository entry point for the test.
Protected methodCreateRepositoryFactory
Creates a repository factory.
Protected methodDiscardCurrentRepository
Resets the repository entry point reference. Subsequent access of Repository will create a new instance.
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodImportData
Imports data from a resource XML file.
Protected methodImportModel
Imports a data model fron a resource XML file.
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Protected methodSetUpBase
Undecorated SetUp method. Override this method, call base.SetUpBase() and decorate it with a unit testing attribute.
Protected methodTearDownBase
Undecorated TearDown method. Override this method, call base.TearDownBase() and decorate it with a unit testing attribute.
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Fields
  NameDescription
Protected fieldStatic members_pLog
Top
Remarks
To define unit tests with a specific unit testing framework, override the SetUpBase and TearDownBase methods and decorate them with the specific code attributes.
Remarks
If the login is switched to SQL Server authentication (Login.UseTrustedConnection = false) the login of the current user must be member of the server role "sysadmin". This is required to create and drop the test database.
Examples

This example shows how to create an application-specific unit test base class. The class defines the database name to be used for testing ("test_db01"), sets the path to the license file, ensures that the relevant business objects assemblies ("PDTec.IceNet.Domain", "PDTec.ICR.BusinessLogic") are loaded and that the SetUp and TearDown methods are connected with the unit testing framework by code attributes.

public abstract class DatabaseTestBase : PDTec.IceNet.Sdk.Test.DatabaseTestBase    
{
    public DatabaseTestBase() : base("test_db01")
    {
        LicenseFilePath = @"..\..\..\..\license.xml";

        BOAssemblyNames.Add("PDTec.IceNet.Domain");
        BOAssemblyNames.Add("PDTec.ICR.BusinessLogic");
    }

    [SetUp]
    protected override void SetUpBase()
    {
        base.SetUpBase();
    }

    [TearDown]
    protected override void TearDownBase()
    {
        base.TearDownBase();
    }
}

This example shows how to use the base class defined above to create a test fixture. In the fixture-specific SetUp method the basic model and data is imported. In the test case two business object methods (IVehicle.CreateBooking, IBooking.CreateReceipt) are tested.

[TestFixture]
public class BookingsTest : DatabaseTestBase
{
    [SetUp]
    public void SetUp()
    {
        Repository.ExecuteTransaction(delegate
        {
            ImportModel(Assembly.Load("PDTec.ICR.BusinessLogic"), "PDTec.ICR.BusinessLogic.ModelXml.PDTec.ICR.icemodel");

            ImportData(GetType().Assembly, "PDTec.ICR.Test.MasterData.ICR.Data.icedata");
        });
    }

    [Test]
    public void MakeBooking()
    {
        Repository.ExecuteTransaction(delegate
        {
            ICustomer pCustomer = Repository.GetFolderByKey(Constants.Folder.Customers).Get<ICustomer>(Repository.GetObjTypeByName("PDTec.ICR.Customer"), true, 1)[0];
            IVehicle  pVehicle  = Repository.GetFolderByKey(Constants.Folder.Cars).Get<IVehicle>(Repository.GetObjTypeByName("PDTec.ICR.Vehicle"), true, 1)[0];

            IBooking pBooking = pVehicle.CreateBooking(pCustomer, DateTime.UtcNow, DateTime.UtcNow.AddDays(2.0));

            pBooking.CreateReceipt("System.Database");
        });

        Assert.That(Repository.RootFolder.GetChildFolders().Length, Is.GreaterThan(0));

        Assert.That(ModelUtils.GetObjectsOfType(Repository, Repository.GetObjTypeByName("PDTec.ICR.Booking"), true, FindRange.Global, null, -1).Length, Is.EqualTo(1));

        Assert.That(ModelUtils.GetObjectsOfType(Repository, Repository.GetObjTypeByName("Core.File"), true, FindRange.Global, null, -1).Length, Is.EqualTo(1));
    }
}
See Also