Re: Unit Testing and ASP.NET Resources

2010-09-10 Thread silky
On Fri, Sep 10, 2010 at 11:45 PM, Wallace Turner  wrote:
> *this is just a though*
>
> Are you testing HttpContext.Current.GetGlobalResource( ) itself or the code
> up until that point?
>
> If the latter then could you replace all your GetGlobalResource( ) calls
> with your own static method? You could then use IoC to plugin in either the
> real GetGlobalResource or your own GetResource( )

Yeah, I had considered this.

The problem is, (well, one could argue how much of a problem it is) is
that not all calls to get resources are done via me directly calling
HttpContext.GetGlobalResource ... (you can use the meta:ResourceKey
approach on asp.net controls themselves to have various properties
set).

Now, it so happens that the particular code I want to test *does*
directly call GetGlobal... so I could replace it in the IoC manner you
describe. But I am kind of not overjoyed by that because it's not the
"One True" way to get the resources.

Ideally, I'd create a new HttpContext and direct it to the location of
the resources. I'm still looking into doing this (it may or may not be
possible). If it's not possible, I'll probably fall back to your
method.

Thanks for the comments.


> Wal

-- 
silky

http://dnoondt.wordpress.com/

"Every morning when I wake up, I experience an exquisite joy — the joy
of being this signature."


RE: Unit Testing and ASP.NET Resources

2010-09-10 Thread Wallace Turner
*this is just a though*

Are you testing HttpContext.Current.GetGlobalResource( ) itself or the code
up until that point?

If the latter then could you replace all your GetGlobalResource( ) calls
with your own static method? You could then use IoC to plugin in either the
real GetGlobalResource or your own GetResource( )

Wal

-Original Message-
From: ozdotnet-boun...@ozdotnet.com [mailto:ozdotnet-boun...@ozdotnet.com]
On Behalf Of silky
Sent: Friday, 10 September 2010 7:11 PM
To: ozDotNet
Subject: Unit Testing and ASP.NET Resources

Has anyone done anything in this area?

The problem is, when tests are run from your unit testing framework
(NUnit in my case), the calls to
HttpContext.Current.GetGlobalResource(...) fail, obviously because
there is no current HttpContext, but also perhaps less obviously
because the resources don't exist in the project that I'm testing.

I actually would like to test that the resources get returned
correctly. (i.e. I want to have tests that run over a bunch of
different languages checking that the results from various calls
result in appropriate-language output). Clearly, one component of the
solution will be a postbuild task to make sure the resources are
copied to the testing project, but the harder problem to solve is how
to make the calls work. Obviously, some IoC scheme is not a legitimate
option.

Anyone have any thoughts? Have I missed an obvious solution? Hope so.

-- 
silky

http://dnoondt.wordpress.com/

"Every morning when I wake up, I experience an exquisite joy - the joy
of being this signature."



Unit Testing and ASP.NET Resources

2010-09-10 Thread silky
Has anyone done anything in this area?

The problem is, when tests are run from your unit testing framework
(NUnit in my case), the calls to
HttpContext.Current.GetGlobalResource(...) fail, obviously because
there is no current HttpContext, but also perhaps less obviously
because the resources don't exist in the project that I'm testing.

I actually would like to test that the resources get returned
correctly. (i.e. I want to have tests that run over a bunch of
different languages checking that the results from various calls
result in appropriate-language output). Clearly, one component of the
solution will be a postbuild task to make sure the resources are
copied to the testing project, but the harder problem to solve is how
to make the calls work. Obviously, some IoC scheme is not a legitimate
option.

Anyone have any thoughts? Have I missed an obvious solution? Hope so.

-- 
silky

http://dnoondt.wordpress.com/

"Every morning when I wake up, I experience an exquisite joy — the joy
of being this signature."