diff --git a/src/Umbraco.Core/Scoping/Scope.cs b/src/Umbraco.Core/Scoping/Scope.cs index 14d7fdd8d9..4979aa6ae1 100644 --- a/src/Umbraco.Core/Scoping/Scope.cs +++ b/src/Umbraco.Core/Scoping/Scope.cs @@ -90,6 +90,7 @@ namespace Umbraco.Core.Scoping var database = ParentScope.Database; if (_isolationLevel > IsolationLevel.Unspecified && database.CurrentTransactionIsolationLevel < _isolationLevel) throw new Exception("Scope requires isolation level " + _isolationLevel + ", but got " + database.CurrentTransactionIsolationLevel + " from parent."); + _database = database; } if (_database != null) diff --git a/src/Umbraco.Core/UmbracoApplicationBase.cs b/src/Umbraco.Core/UmbracoApplicationBase.cs index 02f50710a9..662cbb12bb 100644 --- a/src/Umbraco.Core/UmbracoApplicationBase.cs +++ b/src/Umbraco.Core/UmbracoApplicationBase.cs @@ -64,7 +64,9 @@ namespace Umbraco.Core // after Umbraco has started there is a scope in "context" and that context is // going to stay there and never get destroyed nor reused, so we have to ensure that // the scope is disposed (along with database etc) - reset it all entirely - ((ScopeProvider) ApplicationContext.Current.ScopeProvider).Reset(); + var scopeProvider = ApplicationContext.Current.ScopeProvider as ScopeProvider; + if (scopeProvider != null) // can be mocked... + scopeProvider.Reset(); } /// diff --git a/src/Umbraco.Tests/Scoping/ScopeTests.cs b/src/Umbraco.Tests/Scoping/ScopeTests.cs index 249ecd2081..f6a9ab71df 100644 --- a/src/Umbraco.Tests/Scoping/ScopeTests.cs +++ b/src/Umbraco.Tests/Scoping/ScopeTests.cs @@ -295,7 +295,7 @@ namespace Umbraco.Tests.Scoping using (var nested = scopeProvider.CreateScope()) { nested.Database.Execute("INSERT INTO tmp (id, name) VALUES (2, 'b')"); - var nn = scope.Database.ExecuteScalar("SELECT name FROM tmp WHERE id=2"); + var nn = nested.Database.ExecuteScalar("SELECT name FROM tmp WHERE id=2"); Assert.AreEqual("b", nn); } @@ -331,7 +331,7 @@ namespace Umbraco.Tests.Scoping using (var nested = scopeProvider.CreateScope()) { nested.Database.Execute("INSERT INTO tmp (id, name) VALUES (2, 'b')"); - var nn = scope.Database.ExecuteScalar("SELECT name FROM tmp WHERE id=2"); + var nn = nested.Database.ExecuteScalar("SELECT name FROM tmp WHERE id=2"); Assert.AreEqual("b", nn); nested.Complete(); } @@ -366,7 +366,7 @@ namespace Umbraco.Tests.Scoping using (var nested = scopeProvider.CreateScope()) { nested.Database.Execute("INSERT INTO tmp (id, name) VALUES (2, 'b')"); - var nn = scope.Database.ExecuteScalar("SELECT name FROM tmp WHERE id=2"); + var nn = nested.Database.ExecuteScalar("SELECT name FROM tmp WHERE id=2"); Assert.AreEqual("b", nn); nested.Complete(); }