Umbraco devices do not work

I try to follow the suggestion of Jorge Lusar on Umbraco unit testing . I could not get the GetRoutingContext method to work, because the Umbraco.Web.Routing.UrlProvider constructor gets an exception for the base link (I previously downloaded the umbraco 7.0.4 installation and compiled Umbraco.Tests.dll).

As I selected the options, I decided to download a new copy of Umbraco, compile and run a test that will execute the UrlProvider constructor. To my surprise, I also got an exception for linking to this link, so this error has nothing to do with my solution except Umbraco.

Images speak for themselves. Can anyone help with this? Is this really a mistake or something I can do here?

Null reference exception in UrlProvider constructor

Umbraco configuration settings missing?

+2
source share
2 answers

The solution to the problem was to copy the configuration settings (those from the Unitmbests project of the Umbraco solution) into my test project.

Umbraco is dependent on configuration files. Not perfect for unit tests, but it worked.

It explains how to drown out Umbraco dependencies .

+1
source

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

Another thing you are doing wrong is to use as IUmbracoSettingsSection . Since this means that if the failure fails, you return a null object, not an exception, indicating that the throw was unsuccessful - it fails. Better to do:

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

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

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

This should make the section suitable for you.

0
source

Source: https://habr.com/ru/post/950172/


All Articles