I do something like this stripped version
public class InMemorySpec<TEntity> : SpecBase
{
protected SessionSource SessionSource { get; set; }
protected ISession Session { get; private set; }
public override void MainSetup()
{
...
SetupDb();
}
private void SetupDb()
{
var cfg = Fluently.Configure()
.Database(SQLiteConfiguration.Standard.ProxyFactoryFactory(
"NHibernate.ByteCode.Castle.ProxyFactoryFactory,
NHibernate.ByteCode.Castle").ShowSql().FormatSql().InMemory);
configuration = cfg.BuildConfiguration();
SessionSource = new SessionSource(configuration
.Properties, new TestModel<TEntity>());
Session = SessionSource.CreateSession();
SessionSource.BuildSchema(Session);
}
public override void MainTeardown()
{
TearDownContext();
base.MainTeardown();
}
private void TearDownContext()
{
if (Session.IsOpen)
{
Session.Close();
}
Session.Dispose();
}
}
public class When_getting_product_by_id : InMemorySpec<Product>
{
private Product product;
protected override void Because_of()
{
product = new ProductRepository(Session).GetById(..);
product.ShouldNotBeNull();
}
[Test]
public void Should_eager_load_pictures()
{
NHibernateUtil.IsInitialized(product.Pictures).ShouldBeTrue();
}
}
I inject the session into my repositories but you can easily create your
session manager impl by injecting the session from the memory spec.
public class SessionManager : ISessionManager
{
private readonly ISession session;
public SessionManager(ISession session)
{
this.session = session;
}
public ISession OpenSession()
{
return session;
}
public ISession OpenSession(string alias)
{
return session;
}
public FlushMode DefaultFlushMode { get; set; }
}
//martin
On Tue, Sep 22, 2009 at 4:11 PM, Tiago Soczek <[email protected]> wrote:
> I wanna continues running my tests against data storage.
>
> So, I'll dive into DefaultSessionManager and creates something like a
> TestSessionManager, some tips/considerations to this task?
>
> On Tue, Sep 22, 2009 at 8:04 AM, Germán Schuager <[email protected]>wrote:
>
>> Depending on the content of your repositories I think that you will be
>> better testing them against your actual data storage.
>>
>>
>> On Tue, Sep 22, 2009 at 3:16 AM, Martin Nilsson <[email protected]>wrote:
>>
>>> As you already say you can implement your own ISessionManager
>>>
>>>
>>> On Tue, Sep 22, 2009 at 6:03 AM, Tiago Soczek <[email protected]>wrote:
>>>
>>>> Hi guys,
>>>> Using NHibernate Integration Facility, the container injects
>>>> ISessionManager in my repositories, for tests, i don't want the container
>>>> manages this, I want to create a ISessionManager more manually and then
>>>> runs
>>>> tests without dependency of container, I can do this?
>>>>
>>>> Or, which test strategy you uses for this scenario?
>>>>
>>>> Best regards,
>>>>
>>>> Tiago
>>>>
>>>>
>>>>
>>>
>>>
>>>
>>
>>
>>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Castle Project Users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/castle-project-users?hl=en
-~----------~----~----~----~------~----~------~--~---