U4-10118 - Umbraco.Core.IO.FileSystemProviderManager is simply not testable and cannot be properly used or setup in tests

Created by Paul Sterling 06 Jul 2017, 04:20:22 Updated by Shannon Deminick 12 Sep 2017, 23:41:37

Tags: Unscheduled Gold partner

Using 7.6.3 and setting up simple tests like:

[TestFixture] public class ReportingTests : BaseWebTest ... [SetUp] public void Setup() { var appCtx = new ApplicationContext( CacheHelper.CreateDisabledCacheHelper(), new ProfilingLogger(Mock.Of<ILogger>(), Mock.Of<IProfiler>()) ); UmbracoContext.EnsureContext( Mock.Of<HttpContextBase>(), appCtx, new WebSecurity(Mock.Of<HttpContextBase>(), appCtx), Mock.Of<IUmbracoSettingsSection>(), Enumerable.Empty<IUrlProvider>(), true ); }

Throws: System.TypeInitializationException : The type initializer for 'Umbraco.Core.IO.FileSystemProviderManager' threw an exception. ----> System.NullReferenceException : Object reference not set to an instance of an object. at Umbraco.Core.IO.FileSystemProviderManager.get_Current() at Umbraco.Tests.TestHelpers.BaseUmbracoApplicationTest.SetupApplicationContext() in C:\projects\umbracobuild\Umbraco-cms\src\Umbraco.Tests\TestHelpers\BaseUmbracoApplicationTest.cs:line 158 at Umbraco.Tests.TestHelpers.BaseUmbracoApplicationTest.Initialize() in C:\projects\umbracobuild\Umbraco-cms\src\Umbraco.Tests\TestHelpers\BaseUmbracoApplicationTest.cs:line 53 at Umbraco.Tests.TestHelpers.BaseDatabaseFactoryTest.Initialize() in C:\projects\umbracobuild\Umbraco-cms\src\Umbraco.Tests\TestHelpers\BaseDatabaseFactoryTest.cs:line 82 at Umbraco.Tests.TestHelpers.BaseWebTest.Initialize() in C:\projects\umbracobuild\Umbraco-cms\src\Umbraco.Tests\TestHelpers\BaseWebTest.cs:line 31 --NullReferenceException at Umbraco.Core.IO.FileSystemProviderManager.GetUnderlyingFileSystemCtor(String alias, Func`1 fallback) at Umbraco.Core.IO.FileSystemProviderManager.GetUnderlyingFileSystemNoCache(String alias, Func`1 fallback) at Umbraco.Core.IO.FileSystemProviderManager.<>c__DisplayClass9`1.<GetFileSystemProvider>b__8(String _) at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory) at Umbraco.Core.IO.FileSystemProviderManager.GetFileSystemProvider[TFileSystem](Func`1 fallback) at Umbraco.Core.IO.FileSystemProviderManager.CreateWellKnownFileSystems() at Umbraco.Core.IO.FileSystemProviderManager..cctor()

We've tried to override the TestHelper Initialize() methods but cannot seem to work past the underlying issue regardless. Thoughts on if was an issue potentially introduced in 7.6+ or something we need to adjust our approach on for 7.6+?


Paul Sterling 06 Jul 2017, 23:03:14

By adding the FileSystemProviders config section to the test project's app.config we can resolve this...which is how Umbraco Core does it as well. So, no issue here.

Shannon Deminick 12 Sep 2017, 03:06:46

There are scenarios where this isn't possible (i.e. my LinqPad provider) and this should really be properly testable

Stephan 12 Sep 2017, 08:06:57

New issue in 7.6 due to the fact that FileSystemProviderManager now has "state" and we want to reset that state for each test. But... this automatically creates an instance, and the creation may fail if some configuration is missing. Looking into making sure we don't create the instance if not needed.

Stephan 12 Sep 2017, 08:53:19

Have created PR from @Shandem branch: https://github.com/umbraco/Umbraco-CMS/pull/2187 Reviewing

Stephan 12 Sep 2017, 09:15:39

Question: the PR will still try to create an instance in every test that inherits from BaseUmbracoApplicationTest due to the call to FileSystemProviderManager.Current.Reset. So... although this allows ppl to mock the config and setup their own provider, is it really fixing the original issue?

Suggesting we replace the internal instance Reset method by a static ResetCurrent method that would reset the current instance ''if it exists'' else do nothing.


Shannon Deminick 12 Sep 2017, 09:43:31

Sure, the thing is it would be no different to what we have right now though right?

Stephan 12 Sep 2017, 09:48:48

I ''think'' what we have right now / in the PR still breaks @paul original issue because we're still going to try and create an instance so we can reset it?

Stephan 12 Sep 2017, 14:06:03


Shannon Deminick 12 Sep 2017, 23:41:37

wonderful :)

Priority: Normal

Type: Bug

State: Fixed


Difficulty: Normal


Backwards Compatible: True

Fix Submitted:

Affected versions: 7.6.3

Due in version: 7.7.0

Sprint: Sprint 67

Story Points: