Umbraco unit tests failing
Asked Answered
S

2

2

I am trying to follow Jorge Lusar's suggestion on unit testing Umbraco. I could not get GetRoutingContext method to work because the Umbraco.Web.Routing.UrlProvider constructor is getting a null reference exception (I had downloaded an umbraco 7.0.4 installation previously and compiled the Umbraco.Tests.dll).

As I was getting out of options, I decided to download a fresh copy of Umbraco, compile and run a test that would execute the UrlProvider constructor. To my surprise, I got the null reference exception in there too so apparently, this bug has nothing to do with my solution but Umbraco's instead.

The images speak for themselves. Can anyone plase help with this? Is this really a bug or there's something I can do here?

Null reference exception in UrlProvider constructor

Umbraco configuration settings missing?

Sedan answered 26/3, 2014 at 11:55 Comment(0)
S
1

The solution to the problem was to copy the config settings (the ones in the UnitTests project of the Umbraco solution) to my test project.

Umbraco is dependendant on config files. Not ideal for unit tests but it worked.

Here it is explained how to stub Umbraco dependencies.

Sedan answered 9/7, 2014 at 13:53 Comment(0)
O
0

Checking over a web.config for a current v7 site I've been working on, the umbracoConfiguration/settings section is of type Umbraco.Core.Configuration.UmbracoSettings.UmbracoSettingsSection.

Another thing you're doing wrong is using as IUmbracoSettingsSection. As means if the cast fails you return a null object, rather than an exception telling you the cast failed - it fails silently. It is better to do:

var umbracoSettings = (IUmbracoSettingsSection)ConfigurationManager.GetSection("umbracoConfiguration/settings");

As mentioned, I think your base type is wrong, and you should actually use:

var umbracoSettings = (Umbraco.Core.Configuration.UmbracoSettings.UmbracoSettingsSection)ConfigurationManager.GetSection("umbracoConfiguration/settings");

This should cast the section into the correct type for you.

Offshore answered 9/7, 2014 at 12:43 Comment(2)
You read the question wrongly as I'm not doing right or wrong in the code as it is the Umbraco source.Sedan
I see now - my apologies! I thought you were trying to load your own config settings to test them.Offshore

© 2022 - 2024 — McMap. All rights reserved.