-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Problem of NUnit+Asp.Net+NHibernate
PostPosted: Tue Aug 14, 2007 4:17 am 
Newbie

Joined: Tue Aug 14, 2007 3:57 am
Posts: 2
I want to make the ut for some business module. I create a class library to write ut cases. THen run NUnit.GUI and load the dll file, but the result is wrong:

becase in this file, the httpcontext is null...


public static ISession GetCurrentSession()
{
HttpContext context = HttpContext.Current;
ISession currentSession = context.Items[CurrentSessionKey] as ISession;
if (currentSession == null)
{
currentSession = sessionFactory.OpenSession();
context.Items[CurrentSessionKey] = currentSession;
}
//ISession currentSession = null;
return currentSession;
}

========================================
But when I run the NUnit, it's only a windows application and no httpcontext...

How to solve this problem?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 14, 2007 11:12 am 
Expert
Expert

Joined: Fri May 13, 2005 11:13 am
Posts: 292
Location: Rochester, NY
This isn't really an NHibernate related question, but my $0.02

You have one of two choices: either remove the dependency on HttpContext from your .dll (highly recommended!) or if you cannot do that because of other constraints, then "wrap off" the areas that do depend on it so that they fall back to the CallContext.Items when HttpContext.Items is not available. Or course, the latter solution presumes that you haven't referenced other ASP.NET specific structures that have no analogue outside it.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 14, 2007 1:33 pm 
Senior
Senior

Joined: Sat Sep 10, 2005 3:46 pm
Posts: 178
I'm not sure where you got that code but I don't believe that it is NHibernate code. Its not a problem with NHibernate at all, its a problem with your architecture. I'm sure that you can see it wont work in NUnit because there is no HttpContext.

Sounds like you need a session manger that is smart enough to determine the appropriate context. Check out the NHibernate facility over at the castle project.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 14, 2007 8:35 pm 
Newbie

Joined: Tue Aug 14, 2007 3:57 am
Posts: 2
I got the codes from Hibernate manual (.pdf).

So When use NHibernate in Windows application, how to create the interface to NHiberante? No HttpContext?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 14, 2007 11:01 pm 
Expert
Expert

Joined: Fri May 13, 2005 11:13 am
Posts: 292
Location: Rochester, NY
That code was never intended for inclusion in a .dll. It is included as merely a suggestion for session mgmt in ASP.NET. You'd use completely different patterns for a Winforms app.

I tend to agree with jnapier, your architecture is way off. Your .dll shouldn't be doing Session management of that nature, and it should certainly not be bound to ASP.NET like that. That is something that should be done to some extent in the consuming application, mainly because the function of said application will usually dictate the optimal pattern, not the underlying domain.

It's nice that you have a separation of concerns, but you need to separate the right concerns.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.