Rhino.Commons.NHibernate
Responsible for creating the that a test requires
and ensuring this context is current for the execution of that test
Initialize the persistence framework, build a session factory, and
initialize the container. If
is or string.Empty a RhinoContainer will not be initialized.
The persistence framework
The configuration file to
initialize a
RhinoContainer or .
Name of the database or .
The database engine that tests should be performed against
Information used to map classes to database tables and queries.
If is or
a database with a name
derived from the other parameters supplied will be created. See
and
See
See
See
Throw away all objects within
and referenced by . WARNING: Subsequent calls to
and all its overloads will now take considerably longer as the persistent framework will
be initialised a fresh.
This method should be used vary sparingly. It is highly unlikely that you will need to
call this method between every test.
Calling this method will dispose of objects within
. Each context maintains a reference to a
. If this container object is
referenced by . then any subsequent calls to . and any of the overloads will throw.
Data holder for NHibernate mapping information
Tell NHibernate about the types that are referenced in HQL queries.
This method makes a simple assumption: the name of a type referenced in HQL is the same as the
unqalified name of the actual class/struct. If alias names are used, then
register these using
Initialize NHibernate, build a session factory, and initialize the container.
If is or string.Empty
a RhinoContainer will not be initialized.
The configuration file to initialize a RhinoContainer
or .
The assemblies to load for NHibernate mapping files.
Initialize NHibernate and builds a session factory
Note, this is a costly call so it will be executed only one.
Creates the in memory db schema using the session.
Starts a and creates the in memory db schema.
Using , , and in your tests.
using NUnit.Framework;
using Rhino.Commons;
using Rhino.Commons.ForTesting;
[TestFixture]
public class FooTest : NHibernateEmbeddedDBTestFixtureBase
{
[TestFixtureSetup]
public void TestFixtureSetup()
{
FixtureInitialize("RhinoContainer.boo", typeof(Foo).Assembly);
}
[Setup]
public void TestSetup()
{
/// Creates a top level UnitOfWork, remember to clean me up
CreateUnitOfWork();
}
[TearDown]
public void TestTearDown()
{
/// Cleanup the top level UnitOfWork
UnitOfWork.Current.Dispose();
}
[Test]
public void CanSaveFoo()
{
Foo f = new Foo();
Foo res = null;
f.Name = "Bar";
Assert.AreEqual(Guid.Empty, f.Id);
With.Transaction(delegate
{
IoC.Resolve<IRepository<Foo>>.Save(f);
});
Assert.AreNotEqual(Guid.Empty, f.Id);
using(UnitOfWork.Start())
res = IoC.Resolve<IRepository<Foo>>.Load(f.Id);
Assert.IsNotNull(res);
Assert.AreEqual("Bar", res.Name);
}
}
Opens an NHibernate session and creates the db schema.
The open NHibernate session.
Initialize NHibernate, build a session factory, and initialize the container.
If is or string.Empty
a RhinoContainer will not be initialized.
The configuration file to initialize a RhinoContainer
or .
The assemblies to load for NHibernate mapping files.
Initialize NHibernate and builds a session factory
Note, this is a costly call so it will be executed only one.
Creates the in memory db schema using the session.
An open NHibernate session.
Starts a and creates the in memory db schema.
Using , , and in your tests.
using NUnit.Framework;
using Rhino.Commons;
using Rhino.Commons.ForTesting;
[TestFixture]
public class FooTest : NHibernateInMemoryTest
{
[TestFixtureSetup]
public void TestFixtureSetup()
{
OneTimeInitialize("RhinoContainer.boo", typeof(Foo).Assembly);
}
[Setup]
public void TestSetup()
{
/// Creates a top level UnitOfWork, remember to clean me up
CreateUnitOfWork();
}
[TearDown]
public void TestTearDown()
{
/// Cleanup the top level UnitOfWork
UnitOfWork.Current.Dispose();
}
[Test]
public void CanSaveFoo()
{
Foo f = new Foo();
Foo res = null;
f.Name = "Bar";
Assert.AreEqual(Guid.Empty, f.Id);
With.Transaction(delegate
{
IoC.Resolve<IRepository<Foo>>.Save(f);
});
Assert.AreNotEqual(Guid.Empty, f.Id);
using(UnitOfWork.Start())
res = IoC.Resolve<IRepository<Foo>>.Load(f.Id);
Assert.IsNotNull(res);
Assert.AreEqual("Bar", res.Name);
}
}
Opens an NHibernate session and creates the in memory db schema.
The open NHibernate session.
Encapsulates the construction, initialization and disposal of the
database and UnitOfWork context required for testing. Allows different
implementations of this context to be substituted at runtime
Starts a and creates the db schema.
Using , , and in your tests.
using MbUnit.Framework;
using Rhino.Commons;
using Rhino.Commons.ForTesting;
[TestFixture]
public class FooTest : DatabaseTestFixtureBase
{
[TestFixtureSetup]
public void TestFixtureSetup()
{
IntializeNHibernateAndIoC(PersistenceFramework.NHibernate, "RhinoContainer.boo", typeof(Foo).Assembly);
}
[Setup]
public void TestSetup()
{
/// Creates a top level UnitOfWork, remember to clean me up
CurrentContext.CreateUnitOfWork();
}
[TearDown]
public void TestTearDown()
{
/// Cleanup the top level UnitOfWork
CurrentContext.DisposeUnitOfWork();
}
[Test]
public void CanSaveFoo()
{
Foo f = new Foo();
Foo res = null;
f.Name = "Bar";
Assert.AreEqual(Guid.Empty, f.Id);
With.Transaction(delegate
{
IoC.Resolve<IRepository<Foo>>().Save(f);
});
Assert.AreNotEqual(Guid.Empty, f.Id);
using(UnitOfWork.Start())
res = IoC.Resolve<IRepository<Foo>>().Load(f.Id);
Assert.IsNotNull(res);
Assert.AreEqual("Bar", res.Name);
}
}
Opens an NHibernate session and creates the db schema.
The open NHibernate session.
Creates the in db schema using the session.
An open NHibernate session.
A strategy class that parameterizes a with database specific implementations
This class is a companion to . Its
purpose is to encapsulate behind a common interface the database
specific implementations of behaviour required to construct and manage
the test context
Creates the physical database named .
Use this method to create the physical database file.
For MsSqlCe this will create a database file in the file system
named .sdf
For MsSql2005 this will create a database named in the (local) instance of Sql Server 2005 on
this machine
This verifies that the current request has performed less than the configurable
number of queries (MaxNumberOfQueriesPerRequest).
Can be temporarily ignored using ?hack=true
Gets the query count.
The query count.
Base class for the future of a query, when you try to access the real
result of the query than all the future queries in the current context
(current thread / current request) are executed as a single batch and all
their results are loaded in a single round trip.
Execute all the queries in the batch.
Clears the batcher.
Gets a value indicating whether this instance was loaded.
true if this query was loaded; otherwise, false.
Gets the batcher.
The batcher.
Hold the future of a query, when you try to iterate over
a instance of or access the Results
or TotalCount properties, all the future queries in the current context
(current thread / current request) are executed as a single batch and all
their results are loaded in a single round trip.
Base class for the future of a query, when you try to access the real
result of the query than all the future queries in the current context
(current thread / current request) are executed as a single batch and all
their results are loaded in a single round trip.
Initializes a new instance of the class.
The id.
The options.
Gets the value, initializing the current batch if needed
The value.
Creates the specified property.
The property.
The values.
The maximum number of paramters allowed before the XmlIn creates an xml string.
This class takes the responsability of inspecting NHibernate's entities
and extracting the relevant domain interfaces as separate
services.
Registers the interfaces of the entities defined in the session factory in the container.
The windsor container.
The session factory.
The repository type to map to .
The is candidate for repository.
The reason that we have the is to avoid registering services
for interfaces that are not related to the domain (INotifyPropertyChanged, as a good example).
Registers the interfaces of the entities defined in the session factory in the kernel.
The kernel.
The session factory.
The repository type to map to .
The is candidate for repository.
The reason that we have the is to avoid registering services
for interfaces that are not related to the domain (INotifyPropertyChanged, as a good example).
I hate open generic types in the CLR
Get the entity from the persistance store, or return null
if it doesn't exist.
The entity's id
Either the entity that matches the id, or a null
Get a future entity from the persistance store, or return null
if it doesn't exist.
Note that the null will be there when you resolve the FutureValue.Value property
The entity's id
A future for the value
A future of the entity loaded from the persistance store
Will throw an exception if there isn't an entity that matches
the id.
The entity's id
The entity that matches the id
Load the entity from the persistance store
Will throw an exception if there isn't an entity that matches
the id.
The entity's id
The entity that matches the id
Register the entity for deletion when the unit of work
is completed.
The entity to delete
Registers all entities for deletion when the unit of work
is completed.
Registers all entities for deletion that match the supplied
criteria condition when the unit of work is completed.
criteria condition to select the rows to be deleted
Register te entity for save in the database when the unit of work
is completed. (INSERT)
the entity to save
The saved entity
Saves or update the entity, based on its usaved-value
The saved or updated entity
Saves or update the copy of entity, based on its usaved-value
The saved entity
Register the entity for update in the database when the unit of work
is completed. (UPDATE)
Loads all the entities that match the criteria
by order
the criteria to look for
All the entities that match the criteria
Loads all the entities that match the criteria
by order
the criteria to look for
the order to load the entities
All the entities that match the criteria
Loads all the entities that match the criteria
by order
the criteria to look for
the order to load the entities
the first result to load
the number of result to load
All the entities that match the criteria
Loads all the entities that match the criteria
by order
the criteria to look for
All the entities that match the criteria
Loads all the entities that match the criteria
the criteria to look for
All the entities that match the criteria
Loads all the entities that match the criteria, and allow paging.
The first result to load
Total number of results to load
the cirteria to look for
number of Results of entities that match the criteria
Loads all the entities that match the criteria, with paging
and orderring by a single field.
The first result to load
Total number of results to load
the cirteria to look for
number of Results of entities that match the criteria
The field the repository should order by
number of Results of entities that match the criteria
Loads all the entities that match the criteria, with paging
and orderring by a multiply fields.
The first result to load
Total number of results to load
the cirteria to look for
number of Results of entities that match the criteria
The fields the repository should order by
Execute the named query and return all the results
The named query to execute
Parameters for the query
The results of the query
Execute the named query and return paged results
Parameters for the query
the query to execute
The first result to return
number of records to return
Paged results of the query
Find a single entity based on a criteria.
Thorws is there is more than one result.
The criteria to look for
The entity or null
Find a single entity based on a criteria.
Thorws is there is more than one result.
The criteria to look for
The entity or null
Find a single entity based on a named query.
Thorws is there is more than one result.
parameters for the query
the query to executre
The entity or null
Find the entity based on a criteria.
The criteria to look for
Optional orderring
The entity or null
Find the first entity of type
Optional orderring
The entity or null
Execute the specified stored procedure with the given parameters
and return the result.
Note: only scalar values are supported using this approach.
The name of the stored procedure
parameters for the stored procedure
return value
Execute the specified stored procedure with the given parameters and then converts
the results using the supplied delegate.
The collection type to return.
The delegate which converts the raw results.
The name of the stored procedure.
Parameters for the stored procedure.
Check if any instance matches the criteria.
true if an instance is found; otherwise false.
Check if any instance of the type exists
true if an instance is found; otherwise false.
Counts the number of instances matching the criteria.
Counts the overall number of instances.
Create the project of type (ie a
DataTransferObject) that satisfies the criteria supplied. Throws a
NHibernate.NonUniqueResultException if there is more than one
result.
The criteria to look for
Maps the properties from the object
graph satisfiying to the DTO
The DTO or null
The intent is for to be based (rooted)
on . This is not enforced but is a
convention that should be followed
Create the projects of type (ie
DataTransferObject(s)) that satisfies the criteria supplied.
The criteria to look for
Maps the properties from the object
graph satisfiying to the DTO
The fields the repository should order by
The projection result (DTO's) built from the object graph
satisfying
The intent is for to be based (rooted)
on . This is not enforced but is a
convention that should be followed
Execute the named query and return all the resulting DTO's
(projection)
the type returned
the query to execute in the *.hbm
mapping files
parameters for the query
Creates a compatible with this Repository
The
Creates an aliases compatible with this Repository
the alias
The
Create an instance of , mapping it to the concrete class
if needed
Get a future entity from the persistance store, or return null
if it doesn't exist.
Note that the null will be there when you resolve the FutureValue.Value property
The entity's id
A future for the value
A future of the entity loaded from the persistance store
Will throw an exception if there isn't an entity that matches
the id.
The entity's id
The entity that matches the id
Creates a compatible with this Repository
The
Creates an aliases compatible with this Repository
the alias
The
Loads all the entities that match the criteria
the criteria to look for
All the entities that match the criteria
Loads all the entities that match the criteria
by order
the order in which to bring the data
the criteria to look for
All the entities that match the criteria
Loads all the entities that match the criteria
by order
the order in which to bring the data
the criteria to look for
All the entities that match the criteria
Loads all the entities that match the criteria
by order
the criteria to look for
the order to load the entities
All the entities that match the criteria
Loads all the entities that match the criteria
by order
the criteria to look for
the order to load the entities
the first result to load
the number of result to load
All the entities that match the criteria
Loads all the entities that match the criteria, and allow paging.
The first result to load
Total number of results to load
the cirteria to look for
number of Results of entities that match the criteria
Loads all the entities that match the criteria, with paging
and orderring by a single field.
The first result to load
Total number of results to load
the cirteria to look for
number of Results of entities that match the criteria
The field the repository should order by
number of Results of entities that match the criteria
Loads all the entities that match the criteria, with paging
and orderring by a multiply fields.
The first result to load
Total number of results to load
the cirteria to look for
number of Results of entities that match the criteria
The fields the repository should order by
Execute the named query and return all the results
The named query to execute
Parameters for the query
The results of the query
Execute the named query and return paged results
Parameters for the query
the query to execute
The first result to return
number of records to return
Paged results of the query
Find a single entity based on a criteria.
Thorws is there is more than one result.
The criteria to look for
The entity or null
Find a single entity based on a criteria.
Thorws is there is more than one result.
The criteria to look for
The entity or null
Find a single entity based on a named query.
Thorws is there is more than one result.
parameters for the query
the query to executre
The entity or null
Find the first entity of type
Optional ordering
The entity or null
Find the entity based on a criteria.
The criteria to look for
Optional orderring
The entity or null
Counts the number of instances matching the criteria.
Counts the overall number of instances.
Check if any instance matches the criteria.
true if an instance is found; otherwise false.
Check if any instance of the type exists
true if an instance is found; otherwise false.
Execute the specified stored procedure with the given parameters and then converts
the results using the supplied delegate.
The collection type to return.
The delegate which converts the raw results.
The name of the stored procedure.
Parameters for the stored procedure.
Create an instance of , mapping it to the concrete class
if needed
Gets or sets the concrete type of this repository
The type of the concrete.
This is used to convert the resulting tuples into strongly typed objects.
Get the entity from the persistance store, or return null
if it doesn't exist.
The entity's id
Either the entity that matches the id, or a null
Get a future entity from the persistance store, or return null
if it doesn't exist.
Note that the null will be there when you resolve the FutureValue.Value property
The entity's id
A future for the value
Get the entity from the persistance store, or return null
if it doesn't exist.
The entity's id
Either the entity that matches the id, or a null
Load the entity from the persistance store
Will throw an exception if there isn't an entity that matches
the id.
The entity's id
The entity that matches the id
Register the entity for deletion when the unit of work
is completed.
The entity to delete
Registers all entities for deletion when the unit of work
is completed.
Registers all entities for deletion that match the supplied
criteria condition when the unit of work is completed.
criteria condition to select the rows to be deleted
Register te entity for save in the database when the unit of work
is completed. (INSERT)
the entity to save
The saved entity
Saves or update the entity, based on its usaved-value
The saved or updated entity
Saves or update the copy of entity, based on its usaved-value
Register the entity for update in the database when the unit of work
is completed. (UPDATE)
Loads all the entities that match the criteria
by order
the criteria to look for
All the entities that match the criteria
Loads all the entities that match the criteria
by order
the criteria to look for
the order to load the entities
All the entities that match the criteria
Loads all the entities that match the criteria
by order
the criteria to look for
the order to load the entities
the first result to load
the number of result to load
All the entities that match the criteria
Loads all the entities that match the criteria
by order
the criteria to look for
All the entities that match the criteria
Loads all the entities that match the criteria
the criteria to look for
All the entities that match the criteria
Loads all the entities that match the criteria, and allow paging.
The first result to load
Total number of results to load
the cirteria to look for
number of Results of entities that match the criteria
Loads all the entities that match the criteria, with paging
and orderring by a single field.
The first result to load
Total number of results to load
the cirteria to look for
number of Results of entities that match the criteria
The field the repository should order by
number of Results of entities that match the criteria
Loads all the entities that match the criteria, with paging
and orderring by a multiply fields.
The first result to load
Total number of results to load
the cirteria to look for
number of Results of entities that match the criteria
The fields the repository should order by
Execute the named query and return all the results
The named query to execute
Parameters for the query
The results of the query
Execute the named query and return paged results
Parameters for the query
the query to execute
The first result to return
number of records to return
Paged results of the query
Find a single entity based on a criteria.
Thorws is there is more than one result.
The criteria to look for
The entity or null
Find a single entity based on a criteria.
Thorws is there is more than one result.
The criteria to look for
The entity or null
Find a single entity based on a named query.
Thorws is there is more than one result.
parameters for the query
the query to executre
The entity or null
Find the entity based on a criteria.
The criteria to look for
Optional orderring
The entity or null
Find the first entity of type
Optional orderring
The entity or null
Execute the specified stored procedure with the given parameters
and return the result.
Note: only scalar values are supported using this approach.
The name of the stored procedure
parameters for the stored procedure
return value
Execute the specified stored procedure with the given parameters and then converts
the results using the supplied delegate.
The collection type to return.
The delegate which converts the raw results.
The name of the stored procedure.
Parameters for the stored procedure.
Check if any instance matches the criteria.
true if an instance is found; otherwise false.
Check if any instance of the type exists
true if an instance is found; otherwise false.
Counts the number of instances matching the criteria.
Counts the overall number of instances.
See
See
See
See
See
See
See
See
See
See
See
Create an instance of , mapping it to the concrete class
if needed
Used to handle extra initialization for configuration and session factory
Initialize the factory, note that this may be called more than once
Create a new unit of work implementation.
Possible connection that the user supplied
Previous unit of work, if existed
A usable unit of work
When using LongConversation UnitOfWorkApplication uses this method to restore the
conversation between requests
the IUnitOfWork that had been restored
the Long Conversation Id
When using LongConversation UnitOfWorkApplication uses this method to store the
conversation between requests
Add another usage to this.
Will increase the dispose count
NOT THREAD SAFE
Replace the default implementation of the Session Factory (read from configuration)
with a user supplied one.
NOTE: This should be done at application start.
No attempt is made to make this thread safe!
The session factory for the application.
Note: Prefer to avoid using the member.
It is provided to support complex scenarios only, and it is possible
to configure its behavior externally via configuration.
The current NHibernate session.
Note that the flush mode is CommitOnly!
Note: Prefer to avoid using this member.
It is provided to support complex scenarios only.
Signals the start of an application/user transaction that spans multiple page requests
Used in conjunction with , will ensure that the current UoW
(see ) is kept intact across multiple page requests.
Note: This method does not start a physical database transaction.
Signals the end of the current application/user transaction
Actual disposal of the current UoW is deferred until the end the current page request
NOT thread safe! Mostly intended to support mocking of the unit of work.
You must pass a null argument when finished to ensure atomic units of work UnitOfWorkRegisterGlobalUnitOfWork(null);
You can also call Dispose() on the result of this method, or put it in a using statement (preferred)
Start a Unit of Work
is called
An IUnitOfwork object that can be used to work with the current UoW.
Called internally to clear the current UoW and move to the previous one.
The current unit of work.
Gets the current session.
The current session.