Fleunt NHibernate not working outside of nunit test fixtures
Posted
by thorkia
on Stack Overflow
See other posts from Stack Overflow
or by thorkia
Published on 2010-03-23T02:45:02Z
Indexed on
2010/03/23
2:51 UTC
Read the original article
Hit count: 306
Okay, here is my problem...
I created a Data Layer using the RTM Fluent Nhibernate. My create session code looks like this:
_session = Fluently.Configure().
Database(SQLiteConfiguration.Standard.UsingFile("Data.s3db"))
.Mappings( m =>
{
m.FluentMappings.AddFromAssemblyOf<ProductMap>();
m.FluentMappings.AddFromAssemblyOf<ProductLogMap>();
})
.ExposeConfiguration(BuildSchema)
.BuildSessionFactory();
When I reference the module in a test project, then create a test fixture that looks something like this:
[Test]
public void CanAddProduct()
{
var product = new Product {Code = "9", Name = "Test 9"};
IProductRepository repository = new ProductRepository();
repository.AddProduct(product);
using (ISession session = OrmHelper.OpenSession())
{
var fromDb = session.Get<Product>(product.Id);
Assert.IsNotNull(fromDb);
Assert.AreNotSame(fromDb, product);
Assert.AreEqual(fromDb.Id, product.Id);
}
My tests pass. When I open up the created SQLite DB, the new Product with Code 9 is in it. the tables for Product and ProductLog are there.
Now, when I create a new console application, and reference the same library, do something like this:
Product product = new Product() {Code = "10", Name = "Hello"};
IProductRepository repository = new ProductRepository();
repository.AddProduct(product);
Console.WriteLine(product.Id);
Console.ReadLine();
It doesn't work. I actually get pretty nasty exception chain. To save you lots of head aches, here is the summary:
Top Level exception:
An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.\r\n\r\n
The PotentialReasons collection is empty
The Inner exception:
The IDbCommand and IDbConnection implementation in the assembly System.Data.SQLite could not be found. Ensure that the assembly System.Data.SQLite is located in the application directory or in the Global Assembly Cache. If the assembly is in the GAC, use element in the application configuration file to specify the full name of the assembly.
Both the unit test library and the console application reference the exact same version of System.Data.SQLite. Both projects have the exact same DLLs in the debug folder. I even tried copying SQLite DB the unit test library created into the debug directory of the console app, and removed the build schema lines and it still fails
If anyone can help me figure out why this won't work outside of my unit tests it would be greatly appreciated. This crazy bug has me at a stand still.
© Stack Overflow or respective owner