Testing code with HostingEnvironment.MapPath

487 views
Skip to first unread message

Sebastian Caballero

unread,
Mar 12, 2015, 11:05:56 AM3/12/15
to nunit-...@googlegroups.com
I have to test a service using NUnit with this code:

var fileMap = new ExeConfigurationFileMap(); 
fileMap.ExeConfigFilename =   HostingEnvironment.MapPath("~/Modules/Proy.Notification/Web.config");
_configuration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
The problem is that HostingEnvironment.MapPath is returning null. Is there any way to mock my config or make it point to the right folder?

BTW: I can't change the code I'm testing.

Thanks!

Charlie Poole

unread,
Mar 12, 2015, 11:57:36 AM3/12/15
to NUnit-Discuss
I'm not a web developer, so someone else will have to give a definitive answer.

That said, the HostingEnvironment class represents the application
environment under which your ASP.Net application is running. When you
are running NUnit, you are not running under such an environment, so
you will have to find some way to simulate it. Most likely, for this
call, you will need something in the config.

Charlie
> --
> You received this message because you are subscribed to the Google Groups
> "NUnit-Discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to nunit-discus...@googlegroups.com.
> To post to this group, send email to nunit-...@googlegroups.com.
> Visit this group at http://groups.google.com/group/nunit-discuss.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages