Db4ounit Methods

Let's look through the basic API , which will help you to build your own test. This document is not a complete API reference and its intention is to give you a general idea of the methods usage and availability.

AbstractDb4oTestCase

AbstractDb4oTestCase is a base class for creating test cases.

private transient Db4oFixture _fixture; - determines an environment for the test execution and gives an access to the test database. The environment can be local (derived from AbstractSoloDb4oFixture) or client/server (AbstractClientServerDb4oFixture).

You can always access the fixture from your test class using

.NET:

public virtual void Fixture(IDb4oFixture fixture)

Methods for working with a database:

.NET:

public virtual Db4objects.Db4o.Ext.IExtObjectContainer Db()

Returns an instanse of object container for the current environment.


.NET:

protected virtual void Reopen()

This function will close the database and open it again. It also performs an implicit commit on close.


.NET:

protected virtual Db4objects.Db4o.Reflect.IReflector Reflector()

Returns current reflector.


.NET:

protected virtual Db4objects.Db4o.Transaction Trans()

protected virtual Db4objects.Db4o.Transaction SystemTrans()

protected virtual Db4objects.Db4o.Transaction NewTransaction()

Methods to get transaction object for the current environment.

Various methods to work with persistent objects:

.NET:

protected virtual Db4objects.Db4o.Query.IQuery NewQuery()

protected virtual Db4objects.Db4o.Query.IQuery NewQuery(System.Type clazz)

protected virtual Db4objects.Db4o.Query.IQuery NewQuery(Db4objects.Db4o.Transaction transaction, System.Type clazz)

protected virtual Db4objects.Db4o.Query.IQuery NewQuery(Db4objects.Db4o.Transaction transaction)

Create a new query object.


.NET:

protected virtual object RetrieveOnlyInstance(System.Type clazz)

Checks if only one object of a class is stored in the database


.NET:

protected virtual int CountOccurences(System.Type clazz)

Returns the amount of objects of the specified class in the database.


.NET:

protected virtual void Foreach(System.Type clazz, Db4objects.Db4o.Foundation.IVisitor4 visitor)

This method goes through the ObjectSet of the specified class objects in the database calling Visitor4.visit() method. Visitor4 is an interface specifiing a visit method:


.NET:

void Visit(object obj);

.NET:

protected virtual void DeleteAll(System.Type clazz)

Deletes all the instances of the specified class in the database.


Returns a ReflectClass instance for the specified class.


.NET:

protected virtual void IndexField(Db4objects.Db4o.Config.IConfiguration config, System.Type clazz, string fieldName)

Adds field index into specified configuration.


.NET

public void SetUp()

This method:

  • deletes the used database;
  • configures and opens a new one (see Configure method).
  • Calls db4oSetupBeforeStore
  • Calls store()
  • Commits and reopens the database
  • Calls db4oSetupAfterStore

More details about the mentioned above methods:

.NET:

protected virtual void Configure(Db4objects.Db4o.Config.IConfiguration config)

Use this method to create your custom configuration for a test. Config parameter is the current default test configuration, which can be modified.


.NET:

protected virtual void Db4oSetupBeforeStore()

This method is a placeholder for any custom setup actions that need to be taken before filling up the database with objects.

.NET:

protected virtual void Store()

This method is supplied for creating and storing the objects, which you are going to use for your test.


.NET:

protected virtual void Db4oSetupAfterStore()

This method is a placeholder for any custom setup actions that need to be taken after the database is filled up with objects.


Methods for running tests:

.NET:

public virtual int RunSoloAndClientServer()

Will run the test in both modes


.NET:

public virtual int RunSolo()

Only local mode.


.NET:

public virtual int RunClientServer()

Db4ounit.Assert

Db4ounit.Assert class - provides a variety of methods for controlling code execution. Some of the methods are presented below. For more information please refer to the source code.


.NET:

public static void Expect(System.Type exception, Db4oUnit.ICodeBlock block)

This method runs a specified method (block parameter) and throws an exception if the block runs without any exception.


.NET:

public static void IsTrue(bool condition)

public static void IsTrue(bool condition, string msg)

This method checks the condition and throws an exception if the condition is false. Msg parameter can be used to customize exception message.


.NET:

public static void AreEqual(object expected, object actual)

Checks if the supplied parameters are equal and throws an exception otherwise.

Similar methods are provided for null, lesser, greater and other checkings, please refer to Assert class code for full information.


FrameworkTestCase

FrameworkTestCase class provides methods to run your test suite and check if its results.

.NET:

public static void RunTestAndExpect(Db4oUnit.ITest test, int expFailures)

This method will run the test specified and throw an exception if the number of expected failures (expFailures parameter) is not equal to the number of experienced failures.


For more information please refer to the source code of FrameworkTestCase class.