Umbraco unit tests failing

拥有回忆 提交于 2019-12-11 04:09:31

问题


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?


回答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.




回答2:


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.



来源:https://stackoverflow.com/questions/22660255/umbraco-unit-tests-failing

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!