diff --git a/src/Umbraco.Infrastructure/Scoping/IScope.cs b/src/Umbraco.Core/Scoping/IScope.cs similarity index 88% rename from src/Umbraco.Infrastructure/Scoping/IScope.cs rename to src/Umbraco.Core/Scoping/IScope.cs index 8027e10606..312be1a35f 100644 --- a/src/Umbraco.Infrastructure/Scoping/IScope.cs +++ b/src/Umbraco.Core/Scoping/IScope.cs @@ -1,7 +1,6 @@ using System; using Umbraco.Cms.Core.Cache; using Umbraco.Cms.Core.Events; -using Umbraco.Cms.Infrastructure.Persistence; namespace Umbraco.Cms.Core.Scoping { @@ -10,16 +9,6 @@ namespace Umbraco.Cms.Core.Scoping /// public interface IScope : IDisposable, IInstanceIdentifiable { - /// - /// Gets the scope database. - /// - IUmbracoDatabase Database { get; } - - /// - /// Gets the Sql context. - /// - ISqlContext SqlContext { get; } - /// /// Gets the scope notification publisher /// diff --git a/src/Umbraco.Infrastructure/Scoping/IScopeProvider.cs b/src/Umbraco.Core/Scoping/IScopeProvider.cs similarity index 97% rename from src/Umbraco.Infrastructure/Scoping/IScopeProvider.cs rename to src/Umbraco.Core/Scoping/IScopeProvider.cs index 51b7ba874a..c12680763f 100644 --- a/src/Umbraco.Infrastructure/Scoping/IScopeProvider.cs +++ b/src/Umbraco.Core/Scoping/IScopeProvider.cs @@ -1,7 +1,6 @@ using System.Data; using Umbraco.Cms.Core.Events; using Umbraco.Cms.Core.Persistence.Querying; -using Umbraco.Cms.Infrastructure.Persistence; #if DEBUG_SCOPES using System.Collections.Generic; @@ -84,10 +83,8 @@ namespace Umbraco.Cms.Core.Scoping IScopeContext Context { get; } /// - /// Gets the sql context. + /// Creates an instance of /// - ISqlContext SqlContext { get; } - IQuery CreateQuery(); #if DEBUG_SCOPES diff --git a/src/Umbraco.Infrastructure/Cache/DefaultRepositoryCachePolicy.cs b/src/Umbraco.Infrastructure/Cache/DefaultRepositoryCachePolicy.cs index ef7255a0d6..b8fc8d68a5 100644 --- a/src/Umbraco.Infrastructure/Cache/DefaultRepositoryCachePolicy.cs +++ b/src/Umbraco.Infrastructure/Cache/DefaultRepositoryCachePolicy.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Linq; using Umbraco.Cms.Core.Models.Entities; using Umbraco.Cms.Core.Scoping; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Extensions; namespace Umbraco.Cms.Core.Cache diff --git a/src/Umbraco.Infrastructure/Cache/FullDataSetRepositoryCachePolicy.cs b/src/Umbraco.Infrastructure/Cache/FullDataSetRepositoryCachePolicy.cs index a04cd69900..6b2be94d45 100644 --- a/src/Umbraco.Infrastructure/Cache/FullDataSetRepositoryCachePolicy.cs +++ b/src/Umbraco.Infrastructure/Cache/FullDataSetRepositoryCachePolicy.cs @@ -1,4 +1,4 @@ -// Copyright (c) Umbraco. +// Copyright (c) Umbraco. // See LICENSE for more details. using System; @@ -7,6 +7,7 @@ using System.Linq; using Umbraco.Cms.Core.Collections; using Umbraco.Cms.Core.Models.Entities; using Umbraco.Cms.Core.Scoping; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Extensions; namespace Umbraco.Cms.Core.Cache diff --git a/src/Umbraco.Infrastructure/Cache/RepositoryCachePolicyBase.cs b/src/Umbraco.Infrastructure/Cache/RepositoryCachePolicyBase.cs index 8913de956b..6124d9fb7a 100644 --- a/src/Umbraco.Infrastructure/Cache/RepositoryCachePolicyBase.cs +++ b/src/Umbraco.Infrastructure/Cache/RepositoryCachePolicyBase.cs @@ -1,10 +1,11 @@ -// Copyright (c) Umbraco. +// Copyright (c) Umbraco. // See LICENSE for more details. using System; using System.Collections.Generic; using Umbraco.Cms.Core.Models.Entities; using Umbraco.Cms.Core.Scoping; +using Umbraco.Cms.Infrastructure.Scoping; namespace Umbraco.Cms.Core.Cache { diff --git a/src/Umbraco.Infrastructure/Cache/SingleItemsOnlyRepositoryCachePolicy.cs b/src/Umbraco.Infrastructure/Cache/SingleItemsOnlyRepositoryCachePolicy.cs index 5b1420be65..f74d602bb8 100644 --- a/src/Umbraco.Infrastructure/Cache/SingleItemsOnlyRepositoryCachePolicy.cs +++ b/src/Umbraco.Infrastructure/Cache/SingleItemsOnlyRepositoryCachePolicy.cs @@ -1,8 +1,9 @@ -// Copyright (c) Umbraco. +// Copyright (c) Umbraco. // See LICENSE for more details. using Umbraco.Cms.Core.Models.Entities; using Umbraco.Cms.Core.Scoping; +using Umbraco.Cms.Infrastructure.Scoping; namespace Umbraco.Cms.Core.Cache { diff --git a/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.CoreServices.cs b/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.CoreServices.cs index b979ce239d..5a4faa6c43 100644 --- a/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.CoreServices.cs +++ b/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.CoreServices.cs @@ -50,6 +50,7 @@ using Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0.DataTypes; using Umbraco.Cms.Infrastructure.Persistence; using Umbraco.Cms.Infrastructure.Persistence.Mappers; using Umbraco.Cms.Infrastructure.Runtime; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Cms.Infrastructure.Search; using Umbraco.Cms.Infrastructure.Serialization; using Umbraco.Extensions; @@ -92,9 +93,11 @@ namespace Umbraco.Cms.Infrastructure.DependencyInjection builder.Mappers().AddCoreMappers(); // register the scope provider - builder.Services.AddSingleton(); // implements both IScopeProvider and IScopeAccessor + builder.Services.AddSingleton(); // implements IScopeProvider, IScopeAccessor builder.Services.AddSingleton(f => f.GetRequiredService()); builder.Services.AddSingleton(f => f.GetRequiredService()); + + builder.Services.AddScoped(); builder.Services.AddSingleton(); diff --git a/src/Umbraco.Infrastructure/Migrations/Install/DatabaseBuilder.cs b/src/Umbraco.Infrastructure/Migrations/Install/DatabaseBuilder.cs index 78dbdddc84..0aa2cdda57 100644 --- a/src/Umbraco.Infrastructure/Migrations/Install/DatabaseBuilder.cs +++ b/src/Umbraco.Infrastructure/Migrations/Install/DatabaseBuilder.cs @@ -10,6 +10,7 @@ using Umbraco.Cms.Core.Services; using Umbraco.Cms.Infrastructure.Migrations.Upgrade; using Umbraco.Cms.Infrastructure.Persistence; using Umbraco.Cms.Infrastructure.Persistence.Dtos; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Extensions; namespace Umbraco.Cms.Infrastructure.Migrations.Install @@ -21,6 +22,7 @@ namespace Umbraco.Cms.Infrastructure.Migrations.Install { private readonly IUmbracoDatabaseFactory _databaseFactory; private readonly IScopeProvider _scopeProvider; + private readonly IScopeAccessor _scopeAccessor; private readonly IRuntimeState _runtimeState; private readonly IKeyValueService _keyValueService; private readonly ILogger _logger; @@ -38,6 +40,7 @@ namespace Umbraco.Cms.Infrastructure.Migrations.Install /// public DatabaseBuilder( IScopeProvider scopeProvider, + IScopeAccessor scopeAccessor, IUmbracoDatabaseFactory databaseFactory, IRuntimeState runtimeState, ILoggerFactory loggerFactory, @@ -50,6 +53,7 @@ namespace Umbraco.Cms.Infrastructure.Migrations.Install DatabaseSchemaCreatorFactory databaseSchemaCreatorFactory) { _scopeProvider = scopeProvider; + _scopeAccessor = scopeAccessor; _databaseFactory = databaseFactory; _runtimeState = runtimeState; _logger = loggerFactory.CreateLogger(); @@ -113,17 +117,17 @@ namespace Umbraco.Cms.Infrastructure.Migrations.Install using (var scope = _scopeProvider.CreateScope()) { // look for the super user with default password - var sql = scope.Database.SqlContext.Sql() + var sql = _scopeAccessor.AmbientScope.Database.SqlContext.Sql() .SelectCount() .From() .Where(x => x.Id == Constants.Security.SuperUserId && x.Password == "default"); - var result = scope.Database.ExecuteScalar(sql); + var result = _scopeAccessor.AmbientScope.Database.ExecuteScalar(sql); var has = result != 1; if (has == false) { // found only 1 user == the default user with default password // however this always exists on uCloud, also need to check if there are other users too - result = scope.Database.ExecuteScalar("SELECT COUNT(*) FROM umbracoUser"); + result = _scopeAccessor.AmbientScope.Database.ExecuteScalar("SELECT COUNT(*) FROM umbracoUser"); has = result != 1; } scope.Complete(); @@ -135,7 +139,7 @@ namespace Umbraco.Cms.Infrastructure.Migrations.Install { using (var scope = _scopeProvider.CreateScope(autoComplete: true)) { - return scope.Database.IsUmbracoInstalled(); + return _scopeAccessor.AmbientScope.Database.IsUmbracoInstalled(); } } @@ -336,7 +340,7 @@ namespace Umbraco.Cms.Infrastructure.Migrations.Install if (_databaseSchemaValidationResult != null) return _databaseSchemaValidationResult; - _databaseSchemaValidationResult = scope.Database.ValidateSchema(); + _databaseSchemaValidationResult = _scopeAccessor.AmbientScope.Database.ValidateSchema(); scope.Complete(); @@ -372,7 +376,7 @@ namespace Umbraco.Cms.Infrastructure.Migrations.Install _logger.LogInformation("Database configuration status: Started"); - var database = scope.Database; + var database = _scopeAccessor.AmbientScope.Database; var message = string.Empty; diff --git a/src/Umbraco.Infrastructure/Migrations/MigrationPlanExecutor.cs b/src/Umbraco.Infrastructure/Migrations/MigrationPlanExecutor.cs index 09cddbc20b..358d7d0281 100644 --- a/src/Umbraco.Infrastructure/Migrations/MigrationPlanExecutor.cs +++ b/src/Umbraco.Infrastructure/Migrations/MigrationPlanExecutor.cs @@ -4,6 +4,7 @@ using System.Linq; using Microsoft.Extensions.Logging; using Umbraco.Cms.Core.Migrations; using Umbraco.Cms.Core.Scoping; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Extensions; using Type = System.Type; @@ -12,16 +13,19 @@ namespace Umbraco.Cms.Infrastructure.Migrations public class MigrationPlanExecutor : IMigrationPlanExecutor { private readonly IScopeProvider _scopeProvider; + private readonly IScopeAccessor _scopeAccessor; private readonly ILoggerFactory _loggerFactory; private readonly IMigrationBuilder _migrationBuilder; private readonly ILogger _logger; public MigrationPlanExecutor( IScopeProvider scopeProvider, + IScopeAccessor scopeAccessor, ILoggerFactory loggerFactory, IMigrationBuilder migrationBuilder) { _scopeProvider = scopeProvider; + _scopeAccessor = scopeAccessor; _loggerFactory = loggerFactory; _migrationBuilder = migrationBuilder; _logger = _loggerFactory.CreateLogger(); @@ -61,7 +65,7 @@ namespace Umbraco.Cms.Infrastructure.Migrations // that packages notification handlers may explode because that package isn't fully installed yet. using (scope.Notifications.Suppress()) { - var context = new MigrationContext(plan, scope.Database, _loggerFactory.CreateLogger()); + var context = new MigrationContext(plan, _scopeAccessor.AmbientScope.Database, _loggerFactory.CreateLogger()); while (transition != null) { diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/AuditEntryRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/AuditEntryRepository.cs index e3685dd32c..9cadc82e49 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/AuditEntryRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/AuditEntryRepository.cs @@ -12,6 +12,7 @@ using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Infrastructure.Persistence.Dtos; using Umbraco.Cms.Infrastructure.Persistence.Factories; using Umbraco.Cms.Infrastructure.Persistence.Querying; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Extensions; namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/AuditRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/AuditRepository.cs index d528f69dce..644dc4bc26 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/AuditRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/AuditRepository.cs @@ -8,9 +8,9 @@ using Umbraco.Cms.Core.Cache; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Persistence.Querying; using Umbraco.Cms.Core.Persistence.Repositories; -using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Infrastructure.Persistence.Dtos; using Umbraco.Cms.Infrastructure.Persistence.Querying; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Extensions; namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/CacheInstructionRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/CacheInstructionRepository.cs index d0e025e06e..3ce9aad530 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/CacheInstructionRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/CacheInstructionRepository.cs @@ -4,9 +4,9 @@ using System.Linq; using NPoco; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Persistence.Repositories; -using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Infrastructure.Persistence.Dtos; using Umbraco.Cms.Infrastructure.Persistence.Factories; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Extensions; namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement @@ -21,7 +21,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement public CacheInstructionRepository(IScopeAccessor scopeAccessor) => _scopeAccessor = scopeAccessor; /// - private IScope AmbientScope => _scopeAccessor.AmbientScope; + private IDatabaseScope AmbientScope => _scopeAccessor.AmbientScope; /// public int CountAll() diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ConsentRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ConsentRepository.cs index 87a112fe08..194369285b 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ConsentRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ConsentRepository.cs @@ -6,10 +6,10 @@ using Umbraco.Cms.Core.Cache; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Persistence.Querying; using Umbraco.Cms.Core.Persistence.Repositories; -using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Infrastructure.Persistence.Dtos; using Umbraco.Cms.Infrastructure.Persistence.Factories; using Umbraco.Cms.Infrastructure.Persistence.Querying; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Extensions; namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentRepositoryBase.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentRepositoryBase.cs index fd4d1c33b9..0b4af6bdee 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentRepositoryBase.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentRepositoryBase.cs @@ -15,12 +15,12 @@ using Umbraco.Cms.Core.Persistence; using Umbraco.Cms.Core.Persistence.Querying; using Umbraco.Cms.Core.Persistence.Repositories; using Umbraco.Cms.Core.PropertyEditors; -using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Core.Serialization; using Umbraco.Cms.Core.Services; using Umbraco.Cms.Infrastructure.Persistence.Dtos; using Umbraco.Cms.Infrastructure.Persistence.Factories; using Umbraco.Cms.Infrastructure.Persistence.Querying; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Extensions; using static Umbraco.Cms.Core.Persistence.SqlExtensionsStatics; diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentTypeCommonRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentTypeCommonRepository.cs index 04ca55b499..66ab87b743 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentTypeCommonRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentTypeCommonRepository.cs @@ -12,6 +12,7 @@ using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Core.Strings; using Umbraco.Cms.Infrastructure.Persistence.Dtos; using Umbraco.Cms.Infrastructure.Persistence.Factories; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Extensions; using Enumerable = System.Linq.Enumerable; @@ -42,7 +43,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement _shortStringHelper = shortStringHelper; } - private IScope AmbientScope => _scopeAccessor.AmbientScope; + private IDatabaseScope AmbientScope => _scopeAccessor.AmbientScope; private IUmbracoDatabase Database => AmbientScope.Database; private ISqlContext SqlContext => AmbientScope.SqlContext; diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentTypeRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentTypeRepository.cs index 9b0fe45c79..56fd356011 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentTypeRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentTypeRepository.cs @@ -8,11 +8,11 @@ using Umbraco.Cms.Core.Cache; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Persistence.Querying; using Umbraco.Cms.Core.Persistence.Repositories; -using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Core.Strings; using Umbraco.Cms.Infrastructure.Persistence.Dtos; using Umbraco.Cms.Infrastructure.Persistence.Querying; using Umbraco.Cms.Infrastructure.Persistence.SqlSyntax; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Extensions; namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentTypeRepositoryBase.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentTypeRepositoryBase.cs index 38e8a99d08..5ffdf4bf10 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentTypeRepositoryBase.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentTypeRepositoryBase.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Data; using System.Globalization; @@ -12,12 +12,12 @@ using Umbraco.Cms.Core.Exceptions; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Persistence; using Umbraco.Cms.Core.Persistence.Repositories; -using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Core.Services; using Umbraco.Cms.Core.Strings; using Umbraco.Cms.Infrastructure.Persistence.Dtos; using Umbraco.Cms.Infrastructure.Persistence.Factories; using Umbraco.Cms.Infrastructure.Persistence.Querying; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Extensions; namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DataTypeContainerRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DataTypeContainerRepository.cs index 6128b2e9b2..f8fc9e14be 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DataTypeContainerRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DataTypeContainerRepository.cs @@ -1,7 +1,7 @@ -using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging; using Umbraco.Cms.Core.Cache; using Umbraco.Cms.Core.Persistence.Repositories; -using Umbraco.Cms.Core.Scoping; +using Umbraco.Cms.Infrastructure.Scoping; namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement { diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DataTypeRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DataTypeRepository.cs index f70048c4f9..954d3e0d0f 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DataTypeRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DataTypeRepository.cs @@ -13,12 +13,12 @@ using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Persistence.Querying; using Umbraco.Cms.Core.Persistence.Repositories; using Umbraco.Cms.Core.PropertyEditors; -using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Core.Serialization; using Umbraco.Cms.Core.Services; using Umbraco.Cms.Infrastructure.Persistence.Dtos; using Umbraco.Cms.Infrastructure.Persistence.Factories; using Umbraco.Cms.Infrastructure.Persistence.Querying; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Extensions; using static Umbraco.Cms.Core.Persistence.SqlExtensionsStatics; diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DictionaryRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DictionaryRepository.cs index bc9892b1ee..98b1820204 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DictionaryRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DictionaryRepository.cs @@ -9,10 +9,10 @@ using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Models.Entities; using Umbraco.Cms.Core.Persistence.Querying; using Umbraco.Cms.Core.Persistence.Repositories; -using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Infrastructure.Persistence.Dtos; using Umbraco.Cms.Infrastructure.Persistence.Factories; using Umbraco.Cms.Infrastructure.Persistence.Querying; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Extensions; namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DocumentBlueprintRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DocumentBlueprintRepository.cs index 79663c292e..f97aec0917 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DocumentBlueprintRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DocumentBlueprintRepository.cs @@ -4,9 +4,9 @@ using Umbraco.Cms.Core.Cache; using Umbraco.Cms.Core.Events; using Umbraco.Cms.Core.Persistence.Repositories; using Umbraco.Cms.Core.PropertyEditors; -using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Core.Serialization; using Umbraco.Cms.Core.Services; +using Umbraco.Cms.Infrastructure.Scoping; namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement { diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DocumentRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DocumentRepository.cs index 41645dba27..0d77f3d53b 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DocumentRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DocumentRepository.cs @@ -21,6 +21,7 @@ using Umbraco.Cms.Infrastructure.Persistence.Dtos; using Umbraco.Cms.Infrastructure.Persistence.Factories; using Umbraco.Cms.Infrastructure.Persistence.Querying; using Umbraco.Cms.Infrastructure.Persistence.SqlSyntax; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Extensions; namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DocumentTypeContainerRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DocumentTypeContainerRepository.cs index c6c0df848c..f37886fee2 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DocumentTypeContainerRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DocumentTypeContainerRepository.cs @@ -1,7 +1,7 @@ -using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging; using Umbraco.Cms.Core.Cache; using Umbraco.Cms.Core.Persistence.Repositories; -using Umbraco.Cms.Core.Scoping; +using Umbraco.Cms.Infrastructure.Scoping; namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement { diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DocumentVersionRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DocumentVersionRepository.cs index 21bd883c68..52b73bed26 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DocumentVersionRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DocumentVersionRepository.cs @@ -7,6 +7,7 @@ using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Persistence.Repositories; using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Infrastructure.Persistence.Dtos; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Extensions; namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DomainRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DomainRepository.cs index d7fd2e9c7c..7633264ed6 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DomainRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DomainRepository.cs @@ -11,6 +11,7 @@ using Umbraco.Cms.Core.Persistence.Querying; using Umbraco.Cms.Core.Persistence.Repositories; using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Infrastructure.Persistence.Dtos; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Extensions; namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/EntityContainerRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/EntityContainerRepository.cs index b30c5ae1a4..37cbf979e2 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/EntityContainerRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/EntityContainerRepository.cs @@ -8,8 +8,8 @@ using Umbraco.Cms.Core.Cache; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Persistence.Querying; using Umbraco.Cms.Core.Persistence.Repositories; -using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Infrastructure.Persistence.Dtos; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Extensions; namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/EntityRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/EntityRepository.cs index 83cb31774d..82cc897e45 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/EntityRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/EntityRepository.cs @@ -8,11 +8,11 @@ using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Models.Entities; using Umbraco.Cms.Core.Persistence.Querying; using Umbraco.Cms.Core.Persistence.Repositories; -using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Core.Services; using Umbraco.Cms.Infrastructure.Persistence.Dtos; using Umbraco.Cms.Infrastructure.Persistence.Querying; using Umbraco.Cms.Infrastructure.Persistence.SqlSyntax; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Extensions; using static Umbraco.Cms.Core.Persistence.SqlExtensionsStatics; diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/EntityRepositoryBase.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/EntityRepositoryBase.cs index 79e6f732a2..3518803490 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/EntityRepositoryBase.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/EntityRepositoryBase.cs @@ -10,6 +10,7 @@ using Umbraco.Cms.Core.Persistence; using Umbraco.Cms.Core.Persistence.Querying; using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Infrastructure.Persistence.Querying; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Extensions; namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ExternalLoginRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ExternalLoginRepository.cs index 814bfefc88..60fa5e02e7 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ExternalLoginRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ExternalLoginRepository.cs @@ -9,11 +9,11 @@ using Umbraco.Cms.Core.Models.Entities; using Umbraco.Cms.Core.Persistence; using Umbraco.Cms.Core.Persistence.Querying; using Umbraco.Cms.Core.Persistence.Repositories; -using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Core.Security; using Umbraco.Cms.Infrastructure.Persistence.Dtos; using Umbraco.Cms.Infrastructure.Persistence.Factories; using Umbraco.Cms.Infrastructure.Persistence.Querying; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Extensions; namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/KeyValueRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/KeyValueRepository.cs index 288f480ed1..653e916be6 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/KeyValueRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/KeyValueRepository.cs @@ -7,9 +7,9 @@ using Umbraco.Cms.Core.Cache; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Persistence.Querying; using Umbraco.Cms.Core.Persistence.Repositories; -using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Infrastructure.Persistence.Dtos; using Umbraco.Cms.Infrastructure.Persistence.Querying; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Extensions; namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/LanguageRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/LanguageRepository.cs index d0aee52406..fc40343692 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/LanguageRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/LanguageRepository.cs @@ -10,10 +10,10 @@ using Umbraco.Cms.Core.Configuration.Models; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Persistence.Querying; using Umbraco.Cms.Core.Persistence.Repositories; -using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Infrastructure.Persistence.Dtos; using Umbraco.Cms.Infrastructure.Persistence.Factories; using Umbraco.Cms.Infrastructure.Persistence.Querying; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Extensions; namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/LogViewerQueryRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/LogViewerQueryRepository.cs index 556aba8e22..3482da377d 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/LogViewerQueryRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/LogViewerQueryRepository.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Data; using System.Linq; @@ -8,8 +8,8 @@ using Umbraco.Cms.Core.Cache; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Persistence.Querying; using Umbraco.Cms.Core.Persistence.Repositories; -using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Infrastructure.Persistence.Dtos; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Extensions; namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/MacroRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/MacroRepository.cs index 535895e8ed..c0ba8f3ac4 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/MacroRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/MacroRepository.cs @@ -9,11 +9,11 @@ using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Models.Entities; using Umbraco.Cms.Core.Persistence.Querying; using Umbraco.Cms.Core.Persistence.Repositories; -using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Core.Strings; using Umbraco.Cms.Infrastructure.Persistence.Dtos; using Umbraco.Cms.Infrastructure.Persistence.Factories; using Umbraco.Cms.Infrastructure.Persistence.Querying; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Extensions; namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/MediaRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/MediaRepository.cs index 29960a4044..a431fb6896 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/MediaRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/MediaRepository.cs @@ -12,12 +12,12 @@ using Umbraco.Cms.Core.Persistence; using Umbraco.Cms.Core.Persistence.Querying; using Umbraco.Cms.Core.Persistence.Repositories; using Umbraco.Cms.Core.PropertyEditors; -using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Core.Serialization; using Umbraco.Cms.Core.Services; using Umbraco.Cms.Infrastructure.Persistence.Dtos; using Umbraco.Cms.Infrastructure.Persistence.Factories; using Umbraco.Cms.Infrastructure.Persistence.Querying; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Extensions; using static Umbraco.Cms.Core.Persistence.SqlExtensionsStatics; diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/MediaTypeContainerRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/MediaTypeContainerRepository.cs index 7710f3efb1..069b49de2f 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/MediaTypeContainerRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/MediaTypeContainerRepository.cs @@ -1,7 +1,7 @@ -using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging; using Umbraco.Cms.Core.Cache; using Umbraco.Cms.Core.Persistence.Repositories; -using Umbraco.Cms.Core.Scoping; +using Umbraco.Cms.Infrastructure.Scoping; namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement { diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/MediaTypeRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/MediaTypeRepository.cs index 26d24cbac0..0a07fb2260 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/MediaTypeRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/MediaTypeRepository.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using Microsoft.Extensions.Logging; @@ -8,10 +8,10 @@ using Umbraco.Cms.Core.Cache; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Persistence.Querying; using Umbraco.Cms.Core.Persistence.Repositories; -using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Core.Strings; using Umbraco.Cms.Infrastructure.Persistence.Dtos; using Umbraco.Cms.Infrastructure.Persistence.Querying; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Extensions; namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/MemberGroupRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/MemberGroupRepository.cs index 970e498b26..89858951d7 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/MemberGroupRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/MemberGroupRepository.cs @@ -9,10 +9,10 @@ using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Notifications; using Umbraco.Cms.Core.Persistence.Querying; using Umbraco.Cms.Core.Persistence.Repositories; -using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Infrastructure.Persistence.Dtos; using Umbraco.Cms.Infrastructure.Persistence.Factories; using Umbraco.Cms.Infrastructure.Persistence.Querying; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Extensions; namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/MemberRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/MemberRepository.cs index a1b15f407d..db45c40007 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/MemberRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/MemberRepository.cs @@ -21,6 +21,7 @@ using Umbraco.Cms.Core.Services; using Umbraco.Cms.Infrastructure.Persistence.Dtos; using Umbraco.Cms.Infrastructure.Persistence.Factories; using Umbraco.Cms.Infrastructure.Persistence.Querying; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Extensions; using static Umbraco.Cms.Core.Persistence.SqlExtensionsStatics; diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/MemberTypeRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/MemberTypeRepository.cs index ca3edea81c..27e51551e2 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/MemberTypeRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/MemberTypeRepository.cs @@ -8,11 +8,11 @@ using Umbraco.Cms.Core.Cache; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Persistence.Querying; using Umbraco.Cms.Core.Persistence.Repositories; -using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Core.Strings; using Umbraco.Cms.Infrastructure.Persistence.Dtos; using Umbraco.Cms.Infrastructure.Persistence.Factories; using Umbraco.Cms.Infrastructure.Persistence.Querying; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Extensions; namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/NotificationsRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/NotificationsRepository.cs index 2d68c95fe2..c35052b9d1 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/NotificationsRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/NotificationsRepository.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using Umbraco.Cms.Core.Models; @@ -7,6 +7,7 @@ using Umbraco.Cms.Core.Models.Membership; using Umbraco.Cms.Core.Persistence.Repositories; using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Infrastructure.Persistence.Dtos; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Extensions; namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement @@ -20,7 +21,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement _scopeAccessor = scopeAccessor; } - private IScope AmbientScope => _scopeAccessor.AmbientScope; + private IDatabaseScope AmbientScope => _scopeAccessor.AmbientScope; public IEnumerable GetUsersNotifications(IEnumerable userIds, string action, IEnumerable nodeIds, Guid objectType) { diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/PermissionRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/PermissionRepository.cs index 2b38d55212..afcefdee2c 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/PermissionRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/PermissionRepository.cs @@ -9,8 +9,8 @@ using Umbraco.Cms.Core.Cache; using Umbraco.Cms.Core.Models.Entities; using Umbraco.Cms.Core.Models.Membership; using Umbraco.Cms.Core.Persistence.Querying; -using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Infrastructure.Persistence.Dtos; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Extensions; namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/PublicAccessRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/PublicAccessRepository.cs index 1c4dcdb675..dbddb56b68 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/PublicAccessRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/PublicAccessRepository.cs @@ -8,10 +8,10 @@ using Umbraco.Cms.Core.Cache; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Persistence.Querying; using Umbraco.Cms.Core.Persistence.Repositories; -using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Infrastructure.Persistence.Dtos; using Umbraco.Cms.Infrastructure.Persistence.Factories; using Umbraco.Cms.Infrastructure.Persistence.Querying; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Extensions; namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/RedirectUrlRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/RedirectUrlRepository.cs index 6ab29aa47e..5a15cc5b3d 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/RedirectUrlRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/RedirectUrlRepository.cs @@ -9,8 +9,8 @@ using Umbraco.Cms.Core.Cache; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Persistence.Querying; using Umbraco.Cms.Core.Persistence.Repositories; -using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Infrastructure.Persistence.Dtos; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Extensions; namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/RelationRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/RelationRepository.cs index 749fc9d77b..63d49f06af 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/RelationRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/RelationRepository.cs @@ -9,12 +9,12 @@ using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Models.Entities; using Umbraco.Cms.Core.Persistence.Querying; using Umbraco.Cms.Core.Persistence.Repositories; -using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Core.Services; using Umbraco.Cms.Infrastructure.Persistence.Dtos; using Umbraco.Cms.Infrastructure.Persistence.Factories; using Umbraco.Cms.Infrastructure.Persistence.Querying; using Umbraco.Cms.Infrastructure.Persistence.SqlSyntax; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Extensions; using static Umbraco.Cms.Core.Persistence.SqlExtensionsStatics; diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/RelationTypeRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/RelationTypeRepository.cs index 151d08a2ff..f50e307cfa 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/RelationTypeRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/RelationTypeRepository.cs @@ -9,10 +9,10 @@ using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Models.Entities; using Umbraco.Cms.Core.Persistence.Querying; using Umbraco.Cms.Core.Persistence.Repositories; -using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Infrastructure.Persistence.Dtos; using Umbraco.Cms.Infrastructure.Persistence.Factories; using Umbraco.Cms.Infrastructure.Persistence.Querying; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Extensions; namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/RepositoryBase.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/RepositoryBase.cs index 6e550f9362..4f82603710 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/RepositoryBase.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/RepositoryBase.cs @@ -3,8 +3,8 @@ using NPoco; using Umbraco.Cms.Core.Cache; using Umbraco.Cms.Core.Persistence; using Umbraco.Cms.Core.Persistence.Querying; -using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Infrastructure.Persistence.SqlSyntax; +using Umbraco.Cms.Infrastructure.Scoping; namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement { @@ -35,11 +35,11 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement /// /// Gets the AmbientScope /// - protected IScope AmbientScope + protected IDatabaseScope AmbientScope { get { - IScope scope = ScopeAccessor.AmbientScope; + IDatabaseScope scope = ScopeAccessor.AmbientScope; if (scope == null) { throw new InvalidOperationException("Cannot run a repository without an ambient scope."); diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ServerRegistrationRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ServerRegistrationRepository.cs index 98aef6fa6d..4d1ef3fa88 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ServerRegistrationRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ServerRegistrationRepository.cs @@ -10,6 +10,7 @@ using Umbraco.Cms.Core.Persistence.Repositories; using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Infrastructure.Persistence.Dtos; using Umbraco.Cms.Infrastructure.Persistence.Factories; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Extensions; namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/SimpleGetRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/SimpleGetRepository.cs index 6053d35085..2b7257ff8e 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/SimpleGetRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/SimpleGetRepository.cs @@ -6,8 +6,8 @@ using NPoco; using Umbraco.Cms.Core.Cache; using Umbraco.Cms.Core.Models.Entities; using Umbraco.Cms.Core.Persistence.Querying; -using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Infrastructure.Persistence.Querying; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Extensions; namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/TagRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/TagRepository.cs index 919bbeea31..81e6a82f89 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/TagRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/TagRepository.cs @@ -9,10 +9,10 @@ using Umbraco.Cms.Core.Cache; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Persistence.Querying; using Umbraco.Cms.Core.Persistence.Repositories; -using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Infrastructure.Persistence.Dtos; using Umbraco.Cms.Infrastructure.Persistence.Factories; using Umbraco.Cms.Infrastructure.Persistence.Querying; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Extensions; using static Umbraco.Cms.Core.Persistence.SqlExtensionsStatics; diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/TemplateRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/TemplateRepository.cs index 6d2c02484a..f318d4d31e 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/TemplateRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/TemplateRepository.cs @@ -12,11 +12,11 @@ using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Models.Entities; using Umbraco.Cms.Core.Persistence.Querying; using Umbraco.Cms.Core.Persistence.Repositories; -using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Core.Strings; using Umbraco.Cms.Infrastructure.Persistence.Dtos; using Umbraco.Cms.Infrastructure.Persistence.Factories; using Umbraco.Cms.Infrastructure.Persistence.Querying; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Extensions; namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/UserGroupRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/UserGroupRepository.cs index d6be3cf730..b27f42858a 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/UserGroupRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/UserGroupRepository.cs @@ -10,11 +10,11 @@ using Umbraco.Cms.Core.Models.Entities; using Umbraco.Cms.Core.Models.Membership; using Umbraco.Cms.Core.Persistence.Querying; using Umbraco.Cms.Core.Persistence.Repositories; -using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Core.Strings; using Umbraco.Cms.Infrastructure.Persistence.Dtos; using Umbraco.Cms.Infrastructure.Persistence.Factories; using Umbraco.Cms.Infrastructure.Persistence.Querying; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Extensions; namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/UserRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/UserRepository.cs index b94daf5d83..26d37ed80a 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/UserRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/UserRepository.cs @@ -13,13 +13,13 @@ using Umbraco.Cms.Core.Models.Entities; using Umbraco.Cms.Core.Models.Membership; using Umbraco.Cms.Core.Persistence.Querying; using Umbraco.Cms.Core.Persistence.Repositories; -using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Core.Serialization; using Umbraco.Cms.Core.Services; using Umbraco.Cms.Infrastructure.Persistence.Dtos; using Umbraco.Cms.Infrastructure.Persistence.Factories; using Umbraco.Cms.Infrastructure.Persistence.Mappers; using Umbraco.Cms.Infrastructure.Persistence.Querying; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Extensions; namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement diff --git a/src/Umbraco.Infrastructure/Scoping/IDatabaseScope.cs b/src/Umbraco.Infrastructure/Scoping/IDatabaseScope.cs new file mode 100644 index 0000000000..aac5f48b4b --- /dev/null +++ b/src/Umbraco.Infrastructure/Scoping/IDatabaseScope.cs @@ -0,0 +1,18 @@ +using Umbraco.Cms.Core.Scoping; +using Umbraco.Cms.Infrastructure.Persistence; + +namespace Umbraco.Cms.Infrastructure.Scoping +{ + public interface IDatabaseScope : IScope + { + /// + /// Gets the scope database. + /// + IUmbracoDatabase Database { get; } + + /// + /// Gets the Sql context. + /// + ISqlContext SqlContext { get; } + } +} diff --git a/src/Umbraco.Infrastructure/Scoping/IScopeAccessor.cs b/src/Umbraco.Infrastructure/Scoping/IScopeAccessor.cs index a699a8bc3e..234ee0232b 100644 --- a/src/Umbraco.Infrastructure/Scoping/IScopeAccessor.cs +++ b/src/Umbraco.Infrastructure/Scoping/IScopeAccessor.cs @@ -1,17 +1,11 @@ -// Copyright (c) Umbraco. -// See LICENSE for more details. - -namespace Umbraco.Cms.Core.Scoping +namespace Umbraco.Cms.Infrastructure.Scoping { - /// - /// Provides access to the ambient scope. - /// public interface IScopeAccessor { /// /// Gets the ambient scope. /// /// Returns null if there is no ambient scope. - IScope AmbientScope { get; } + IDatabaseScope AmbientScope { get; } } } diff --git a/src/Umbraco.Infrastructure/Scoping/Scope.cs b/src/Umbraco.Infrastructure/Scoping/Scope.cs index e0f947b4aa..1c1bd636b9 100644 --- a/src/Umbraco.Infrastructure/Scoping/Scope.cs +++ b/src/Umbraco.Infrastructure/Scoping/Scope.cs @@ -10,6 +10,7 @@ using Umbraco.Cms.Core.Configuration.Models; using Umbraco.Cms.Core.Events; using Umbraco.Cms.Core.IO; using Umbraco.Cms.Infrastructure.Persistence; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Core.Collections; using Umbraco.Extensions; @@ -19,7 +20,7 @@ namespace Umbraco.Cms.Core.Scoping /// Implements . /// /// Not thread-safe obviously. - internal class Scope : IScope + internal class Scope : IDatabaseScope { private readonly bool _autoComplete; private readonly CoreDebugSettings _coreDebugSettings; diff --git a/src/Umbraco.Infrastructure/Scoping/ScopeProvider.cs b/src/Umbraco.Infrastructure/Scoping/ScopeProvider.cs index 944c547236..0f5fba4d4a 100644 --- a/src/Umbraco.Infrastructure/Scoping/ScopeProvider.cs +++ b/src/Umbraco.Infrastructure/Scoping/ScopeProvider.cs @@ -12,6 +12,7 @@ using System.Collections.Generic; using System.Collections.Concurrent; using System.Threading; using Umbraco.Cms.Core.Persistence.Querying; +using Umbraco.Cms.Infrastructure.Scoping; #if DEBUG_SCOPES using System.Linq; @@ -286,10 +287,10 @@ namespace Umbraco.Cms.Core.Scoping #region Ambient Scope - IScope IScopeAccessor.AmbientScope => AmbientScope; + IDatabaseScope IScopeAccessor.AmbientScope => AmbientScope; /// - /// Get or set the Ambient (Current) for the current execution context. + /// Gets or set the Ambient (Current) for the current execution context. /// /// /// The current execution context may be request based (HttpContext) or on a background thread (AsyncLocal) diff --git a/src/Umbraco.Infrastructure/Services/IdKeyMap.cs b/src/Umbraco.Infrastructure/Services/IdKeyMap.cs index 49747534c6..cc461cead7 100644 --- a/src/Umbraco.Infrastructure/Services/IdKeyMap.cs +++ b/src/Umbraco.Infrastructure/Services/IdKeyMap.cs @@ -1,23 +1,26 @@ -using System; +using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Threading; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Scoping; +using Umbraco.Cms.Infrastructure.Scoping; namespace Umbraco.Cms.Core.Services { public class IdKeyMap : IIdKeyMap,IDisposable { private readonly IScopeProvider _scopeProvider; + private readonly IScopeAccessor _scopeAccessor; private readonly ReaderWriterLockSlim _locker = new ReaderWriterLockSlim(); private readonly Dictionary> _id2Key = new Dictionary>(); private readonly Dictionary> _key2Id = new Dictionary>(); - public IdKeyMap(IScopeProvider scopeProvider) + public IdKeyMap(IScopeProvider scopeProvider, IScopeAccessor scopeAccessor) { _scopeProvider = scopeProvider; + _scopeAccessor = scopeAccessor; } // note - for pure read-only we might want to *not* enforce a transaction? @@ -170,11 +173,11 @@ namespace Umbraco.Cms.Core.Services //if it's unknown don't include the nodeObjectType in the query if (umbracoObjectType == UmbracoObjectTypes.Unknown) { - val = scope.Database.ExecuteScalar("SELECT id FROM umbracoNode WHERE uniqueId=@id", new { id = key}); + val = _scopeAccessor.AmbientScope.Database.ExecuteScalar("SELECT id FROM umbracoNode WHERE uniqueId=@id", new { id = key}); } else { - val = scope.Database.ExecuteScalar("SELECT id FROM umbracoNode WHERE uniqueId=@id AND (nodeObjectType=@type OR nodeObjectType=@reservation)", + val = _scopeAccessor.AmbientScope.Database.ExecuteScalar("SELECT id FROM umbracoNode WHERE uniqueId=@id AND (nodeObjectType=@type OR nodeObjectType=@reservation)", new { id = key, type = GetNodeObjectTypeGuid(umbracoObjectType), reservation = Cms.Core.Constants.ObjectTypes.IdReservation }); } scope.Complete(); @@ -258,11 +261,11 @@ namespace Umbraco.Cms.Core.Services //if it's unknown don't include the nodeObjectType in the query if (umbracoObjectType == UmbracoObjectTypes.Unknown) { - val = scope.Database.ExecuteScalar("SELECT uniqueId FROM umbracoNode WHERE id=@id", new { id }); + val = _scopeAccessor.AmbientScope.Database.ExecuteScalar("SELECT uniqueId FROM umbracoNode WHERE id=@id", new { id }); } else { - val = scope.Database.ExecuteScalar("SELECT uniqueId FROM umbracoNode WHERE id=@id AND (nodeObjectType=@type OR nodeObjectType=@reservation)", + val = _scopeAccessor.AmbientScope.Database.ExecuteScalar("SELECT uniqueId FROM umbracoNode WHERE id=@id AND (nodeObjectType=@type OR nodeObjectType=@reservation)", new { id, type = GetNodeObjectTypeGuid(umbracoObjectType), reservation = Cms.Core.Constants.ObjectTypes.IdReservation }); } scope.Complete(); diff --git a/src/Umbraco.PublishedCache.NuCache/DependencyInjection/UmbracoBuilderExtensions.cs b/src/Umbraco.PublishedCache.NuCache/DependencyInjection/UmbracoBuilderExtensions.cs index c52c1271ad..60face6428 100644 --- a/src/Umbraco.PublishedCache.NuCache/DependencyInjection/UmbracoBuilderExtensions.cs +++ b/src/Umbraco.PublishedCache.NuCache/DependencyInjection/UmbracoBuilderExtensions.cs @@ -13,6 +13,7 @@ using Umbraco.Cms.Core.Services; using Umbraco.Cms.Infrastructure.PublishedCache; using Umbraco.Cms.Infrastructure.PublishedCache.DataSource; using Umbraco.Cms.Infrastructure.PublishedCache.Persistence; +using Umbraco.Cms.Infrastructure.Scoping; namespace Umbraco.Extensions { @@ -42,7 +43,7 @@ namespace Umbraco.Extensions // TODO: Gotta wonder how much this does actually improve perf? It's a lot of weird code to make this happen so hope it's worth it builder.Services.AddUnique(factory => { - var idkSvc = new IdKeyMap(factory.GetRequiredService()); + var idkSvc = new IdKeyMap(factory.GetRequiredService(), factory.GetRequiredService()); if (factory.GetRequiredService() is PublishedSnapshotService publishedSnapshotService) { idkSvc.SetMapper(UmbracoObjectTypes.Document, id => publishedSnapshotService.GetDocumentUid(id), uid => publishedSnapshotService.GetDocumentId(uid)); diff --git a/src/Umbraco.PublishedCache.NuCache/Persistence/NuCacheContentRepository.cs b/src/Umbraco.PublishedCache.NuCache/Persistence/NuCacheContentRepository.cs index 649bc0eebb..8aa35c1608 100644 --- a/src/Umbraco.PublishedCache.NuCache/Persistence/NuCacheContentRepository.cs +++ b/src/Umbraco.PublishedCache.NuCache/Persistence/NuCacheContentRepository.cs @@ -18,6 +18,7 @@ using Umbraco.Cms.Infrastructure.Persistence; using Umbraco.Cms.Infrastructure.Persistence.Dtos; using Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement; using Umbraco.Cms.Infrastructure.PublishedCache.DataSource; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Extensions; using static Umbraco.Cms.Core.Persistence.SqlExtensionsStatics; using Constants = Umbraco.Cms.Core.Constants; @@ -694,7 +695,7 @@ AND cmsContentNu.nodeId IS NULL } } - public ContentNodeKit GetMediaSource(IScope scope, int id) + public ContentNodeKit GetMediaSource(IDatabaseScope scope, int id) { var sql = SqlMediaSourcesSelect() .Append(SqlObjectTypeNotTrashed(SqlContext, Constants.ObjectTypes.Media)) diff --git a/tests/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs b/tests/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs index 314a614b49..25f6194fde 100644 --- a/tests/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs +++ b/tests/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs @@ -31,6 +31,7 @@ using Umbraco.Cms.Core.Web; using Umbraco.Cms.Infrastructure.DependencyInjection; using Umbraco.Cms.Infrastructure.Persistence; using Umbraco.Cms.Infrastructure.Persistence.Mappers; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Cms.Tests.Common.Builders; using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.DependencyInjection; diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Migrations/AdvancedMigrationTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Migrations/AdvancedMigrationTests.cs index 40dbad176e..19d4080524 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Migrations/AdvancedMigrationTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Migrations/AdvancedMigrationTests.cs @@ -56,7 +56,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Migrations upgrader.Execute(MigrationPlanExecutor, ScopeProvider, Mock.Of()); - var helper = new DatabaseSchemaCreator(scope.Database, LoggerFactory.CreateLogger(), LoggerFactory, UmbracoVersion, EventAggregator); + var helper = new DatabaseSchemaCreator(ScopeAccessor.AmbientScope.Database, LoggerFactory.CreateLogger(), LoggerFactory, UmbracoVersion, EventAggregator); bool exists = helper.TableExists("umbracoUser"); Assert.IsTrue(exists); diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Packaging/PackageDataInstallationTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Packaging/PackageDataInstallationTests.cs index ef6585bef6..3feac1ce38 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Packaging/PackageDataInstallationTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Packaging/PackageDataInstallationTests.cs @@ -150,7 +150,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Packaging using IScope scope = ScopeProvider.CreateScope(); foreach (IPropertyType propertyType in mRBasePage.PropertyTypes) { - PropertyTypeDto propertyTypeDto = scope.Database.First("WHERE id = @id", new { id = propertyType.Id }); + PropertyTypeDto propertyTypeDto = ScopeAccessor.AmbientScope.Database.First("WHERE id = @id", new { id = propertyType.Id }); Assert.AreEqual(propertyTypeDto.UniqueId, propertyType.Key); } } @@ -424,7 +424,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Packaging string configuration; using (IScope scope = ScopeProvider.CreateScope()) { - List dtos = scope.Database.Fetch("WHERE nodeId = @Id", new { dataTypeDefinitions.First().Id }); + List dtos = ScopeAccessor.AmbientScope.Database.Fetch("WHERE nodeId = @Id", new { dataTypeDefinitions.First().Id }); configuration = dtos.Single().Configuration; } diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/LocksTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/LocksTests.cs index 96ded92f41..fa539ef1e8 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/LocksTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/LocksTests.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Data.SqlClient; using System.Linq; @@ -27,7 +27,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence // create a few lock objects using (var scope = ScopeProvider.CreateScope()) { - var database = scope.Database; + var database = ScopeAccessor.AmbientScope.Database; database.Insert("umbracoLock", "id", false, new LockDto { Id = 1, Name = "Lock.1" }); database.Insert("umbracoLock", "id", false, new LockDto { Id = 2, Name = "Lock.2" }); database.Insert("umbracoLock", "id", false, new LockDto { Id = 3, Name = "Lock.3" }); @@ -121,7 +121,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence using (var scope = ScopeProvider.CreateScope()) { - var db = scope.Database; + var db = ScopeAccessor.AmbientScope.Database; try { db.EnableSqlCount = true; @@ -297,7 +297,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence Console.WriteLine($"[{id1}] WAIT {id1}"); scope.EagerWriteLock(id1); Console.WriteLine($"[{id1}] GRANT {id1}"); - WriteLocks(scope.Database); + WriteLocks(ScopeAccessor.AmbientScope.Database); myEv.Set(); if (id1 == 1) @@ -312,7 +312,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence Console.WriteLine($"[{id1}] WAIT {id2}"); scope.EagerWriteLock(id2); Console.WriteLine($"[{id1}] GRANT {id2}"); - WriteLocks(scope.Database); + WriteLocks(ScopeAccessor.AmbientScope.Database); } catch (Exception e) { @@ -483,7 +483,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence { using (var scope = ScopeProvider.CreateScope()) { - var realDb = (Database)scope.Database; + var realDb = (Database)ScopeAccessor.AmbientScope.Database; realDb.CommandTimeout = 1000; Console.WriteLine("Write lock A"); @@ -505,7 +505,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence Console.WriteLine($"[{id}] WAIT {id}"); scope.EagerWriteLock(id); Console.WriteLine($"[{id}] GRANT {id}"); - WriteLocks(scope.Database); + WriteLocks(ScopeAccessor.AmbientScope.Database); myEv.Set(); otherEv.WaitOne(); } diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/NPocoTests/NPocoBulkInsertTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/NPocoTests/NPocoBulkInsertTests.cs index 7fd90c97b3..10b0a06032 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/NPocoTests/NPocoBulkInsertTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/NPocoTests/NPocoBulkInsertTests.cs @@ -39,7 +39,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.NPoco using (IScope scope = ScopeProvider.CreateScope()) { // Still no what we want, but look above. - IUmbracoDatabase dbSqlServer = scope.Database; + IUmbracoDatabase dbSqlServer = ScopeAccessor.AmbientScope.Database; // drop the table dbSqlServer.Execute("DROP TABLE [umbracoServer]"); @@ -103,7 +103,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.NPoco { using (IScope scope = ScopeProvider.CreateScope()) { - scope.Database.BulkInsertRecords(servers); + ScopeAccessor.AmbientScope.Database.BulkInsertRecords(servers); scope.Complete(); } } @@ -111,7 +111,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.NPoco // Assert using (IScope scope = ScopeProvider.CreateScope()) { - Assert.That(scope.Database.ExecuteScalar("SELECT COUNT(*) FROM umbracoServer"), Is.EqualTo(1000)); + Assert.That(ScopeAccessor.AmbientScope.Database.ExecuteScalar("SELECT COUNT(*) FROM umbracoServer"), Is.EqualTo(1000)); } } @@ -136,7 +136,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.NPoco { using (IScope scope = ScopeProvider.CreateScope()) { - scope.Database.BulkInsertRecords(servers); + ScopeAccessor.AmbientScope.Database.BulkInsertRecords(servers); // Don't call complete here - the transaction will be rolled back. } @@ -145,7 +145,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.NPoco // Assert using (IScope scope = ScopeProvider.CreateScope()) { - Assert.That(scope.Database.ExecuteScalar("SELECT COUNT(*) FROM umbracoServer"), Is.EqualTo(0)); + Assert.That(ScopeAccessor.AmbientScope.Database.ExecuteScalar("SELECT COUNT(*) FROM umbracoServer"), Is.EqualTo(0)); } } @@ -168,7 +168,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.NPoco IDbCommand[] commands; using (IScope scope = ScopeProvider.CreateScope()) { - commands = scope.Database.GenerateBulkInsertCommands(servers.ToArray()); + commands = ScopeAccessor.AmbientScope.Database.GenerateBulkInsertCommands(servers.ToArray()); scope.Complete(); } @@ -198,7 +198,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.NPoco IDbCommand[] commands; using (IScope scope = ScopeProvider.CreateScope()) { - commands = scope.Database.GenerateBulkInsertCommands(servers.ToArray()); + commands = ScopeAccessor.AmbientScope.Database.GenerateBulkInsertCommands(servers.ToArray()); scope.Complete(); } diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/NPocoTests/NPocoFetchTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/NPocoTests/NPocoFetchTests.cs index bea5a8fb8c..19976da976 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/NPocoTests/NPocoFetchTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/NPocoTests/NPocoFetchTests.cs @@ -23,7 +23,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.NPoco { using (IScope scope = ScopeProvider.CreateScope()) { - InsertData(scope.Database); + InsertData(ScopeAccessor.AmbientScope.Database); scope.Complete(); } } @@ -166,11 +166,11 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.NPoco // var sql = @" // SELECT zbThing1.id, zbThing1.name // FROM zbThing1"; - Sql sql = scope.SqlContext.Sql() + Sql sql = ScopeAccessor.AmbientScope.SqlContext.Sql() .Select() .From(); - List dtos = scope.Database.Fetch(sql); + List dtos = ScopeAccessor.AmbientScope.Database.Fetch(sql); Assert.AreEqual(2, dtos.Count); Assert.AreEqual("one", dtos.First(x => x.Id == 1).Name); } @@ -189,12 +189,12 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.NPoco // zbThing1.id Thing__id, zbThing1.name Thing__name // FROM zbThing2 // JOIN zbThing1 ON zbThing2.thingId=zbThing1.id"; - Sql sql = scope.SqlContext.Sql() + Sql sql = ScopeAccessor.AmbientScope.SqlContext.Sql() .Select(r => r.Select(x => x.Thing)) .From() .InnerJoin().On((t2, t1) => t2.ThingId == t1.Id); - List dtos = scope.Database.Fetch(sql); + List dtos = ScopeAccessor.AmbientScope.Database.Fetch(sql); Assert.AreEqual(3, dtos.Count); Assert.AreEqual("uno", dtos.First(x => x.Id == 1).Name); Assert.IsNotNull(dtos.First(x => x.Id == 1).Thing); @@ -218,14 +218,14 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.NPoco // FROM zbThing1 // JOIN zbThing2 ON zbThing1.id=zbThing2.thingId // WHERE zbThing1.id=1"); - Sql sql = scope.SqlContext.Sql() + Sql sql = ScopeAccessor.AmbientScope.SqlContext.Sql() .Select(r => r.Select(x => x.Things)) .From() .InnerJoin().On(left => left.Id, right => right.ThingId) .Where(x => x.Id == 1); // var dtos = scope.Database.FetchOneToMany(x => x.Things, x => x.Id, sql); - List dtos = scope.Database.FetchOneToMany(x => x.Things, sql); + List dtos = ScopeAccessor.AmbientScope.Database.FetchOneToMany(x => x.Things, sql); Assert.AreEqual(1, dtos.Count); Thing3Dto dto1 = dtos.FirstOrDefault(x => x.Id == 1); @@ -258,13 +258,13 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.NPoco // FROM zbThing1 // JOIN zbThing2 ON zbThing1.id=zbThing2.thingId // ORDER BY zbThing1.id"; - Sql sql = scope.SqlContext.Sql() + Sql sql = ScopeAccessor.AmbientScope.SqlContext.Sql() .Select(r => r.Select(x => x.Things)) // select Thing3Dto, and Thing2Dto for Things .From() .InnerJoin().On(left => left.Id, right => right.ThingId) .OrderBy(x => x.Id); - List dtos = scope.Database.FetchOneToMany(x => x.Things, /*x => x.Id,*/ sql); + List dtos = ScopeAccessor.AmbientScope.Database.FetchOneToMany(x => x.Things, /*x => x.Id,*/ sql); Assert.AreEqual(2, dtos.Count); Thing3Dto dto1 = dtos.FirstOrDefault(x => x.Id == 1); @@ -283,18 +283,18 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.NPoco { using (IScope scope = ScopeProvider.CreateScope()) { - scope.SqlContext.Templates.Clear(); + ScopeAccessor.AmbientScope.SqlContext.Templates.Clear(); - Sql sql = scope.SqlContext.Templates.Get("xxx", s => s + Sql sql = ScopeAccessor.AmbientScope.SqlContext.Templates.Get("xxx", s => s .Select(r => r.Select(x => x.Things)) // select Thing3Dto, and Thing2Dto for Things .From() .InnerJoin().On(left => left.Id, right => right.ThingId) .OrderBy(x => x.Id)).Sql(); // cached - sql = scope.SqlContext.Templates.Get("xxx", s => throw new InvalidOperationException()).Sql(); + sql = ScopeAccessor.AmbientScope.SqlContext.Templates.Get("xxx", s => throw new InvalidOperationException()).Sql(); - List dtos = scope.Database.FetchOneToMany(x => x.Things, /*x => x.Id,*/ sql); + List dtos = ScopeAccessor.AmbientScope.Database.FetchOneToMany(x => x.Things, /*x => x.Id,*/ sql); Assert.AreEqual(2, dtos.Count); Thing3Dto dto1 = dtos.FirstOrDefault(x => x.Id == 1); @@ -326,14 +326,14 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.NPoco // JOIN zbThing2Group ON zbThing1.id=zbThing2Group.thingId // JOIN zbThingGroup ON zbThing2Group.groupId=zbThingGroup.id // ORDER BY zbThing1.id"; - Sql sql = scope.SqlContext.Sql() + Sql sql = ScopeAccessor.AmbientScope.SqlContext.Sql() .Select(r => r.Select(x => x.Groups)) .From() .InnerJoin().On((t, t2g) => t.Id == t2g.ThingId) .InnerJoin().On((t2g, tg) => t2g.GroupId == tg.Id) .OrderBy(x => x.Id); - List dtos = scope.Database.FetchOneToMany(x => x.Groups, /*x => x.Id,*/ sql); + List dtos = ScopeAccessor.AmbientScope.Database.FetchOneToMany(x => x.Groups, /*x => x.Id,*/ sql); Assert.AreEqual(2, dtos.Count); Thing4Dto dto1 = dtos.FirstOrDefault(x => x.Id == 1); @@ -360,14 +360,14 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.NPoco // FROM zbThing1 // JOIN zbThing2Group ON zbThing1.id=zbThing2Group.thingId // GROUP BY zbThing1.id, zbThing1.name"; - Sql sql = scope.SqlContext.Sql() + Sql sql = ScopeAccessor.AmbientScope.SqlContext.Sql() .Select() .Append(", COUNT(zbThing2Group.groupId) AS groupCount") // FIXME: .From() .InnerJoin().On((t, t2g) => t.Id == t2g.ThingId) .GroupBy(x => x.Id, x => x.Name); - List dtos = scope.Database.Fetch(sql); + List dtos = ScopeAccessor.AmbientScope.Database.Fetch(sql); Assert.AreEqual(2, dtos.Count); Thing5Dto dto1 = dtos.FirstOrDefault(x => x.Id == 1); @@ -390,12 +390,12 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.NPoco { using (IScope scope = ScopeProvider.CreateScope()) { - Sql sql = scope.SqlContext.Sql() + Sql sql = ScopeAccessor.AmbientScope.SqlContext.Sql() .SelectAll() .From() .Where(x => x.Id == 1); - Thing1Dto dto = scope.Database.Fetch(sql).FirstOrDefault(); + Thing1Dto dto = ScopeAccessor.AmbientScope.Database.Fetch(sql).FirstOrDefault(); Assert.IsNotNull(dto); Assert.AreEqual("one", dto.Name); @@ -406,7 +406,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.NPoco //// Assert.AreEqual("one", dto.Name); var sql3 = new Sql(sql.SQL, 1); - dto = scope.Database.Fetch(sql3).FirstOrDefault(); + dto = ScopeAccessor.AmbientScope.Database.Fetch(sql3).FirstOrDefault(); Assert.IsNotNull(dto); Assert.AreEqual("one", dto.Name); } @@ -418,28 +418,28 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.NPoco using (IScope scope = ScopeProvider.CreateScope()) { var tA1A = new ThingA1Dto { Id = 1, Name = "a1_a" }; - scope.Database.Insert(tA1A); + ScopeAccessor.AmbientScope.Database.Insert(tA1A); var tA1B = new ThingA1Dto { Id = 2, Name = "a1_b" }; - scope.Database.Insert(tA1B); + ScopeAccessor.AmbientScope.Database.Insert(tA1B); var tA1C = new ThingA1Dto { Id = 3, Name = "a1_c" }; - scope.Database.Insert(tA1C); + ScopeAccessor.AmbientScope.Database.Insert(tA1C); var tA2A = new ThingA2Dto { Id = 1, Name = "a2_a" }; - scope.Database.Insert(tA2A); + ScopeAccessor.AmbientScope.Database.Insert(tA2A); var tA2B = new ThingA2Dto { Id = 2, Name = "a2_b" }; - scope.Database.Insert(tA2B); + ScopeAccessor.AmbientScope.Database.Insert(tA2B); var tA2C = new ThingA2Dto { Id = 3, Name = "a2_c" }; - scope.Database.Insert(tA2C); + ScopeAccessor.AmbientScope.Database.Insert(tA2C); var tA3A = new ThingA3Dto { Id = 1, Name = "a3_a" }; - scope.Database.Insert(tA3A); + ScopeAccessor.AmbientScope.Database.Insert(tA3A); var tA3B = new ThingA3Dto { Id = 2, Name = "a3_b" }; - scope.Database.Insert(tA3B); + ScopeAccessor.AmbientScope.Database.Insert(tA3B); var k1 = new ThingA12Dto { Name = "a", Thing1Id = tA1A.Id, Thing2Id = tA2A.Id }; - scope.Database.Insert(k1); + ScopeAccessor.AmbientScope.Database.Insert(k1); var k2 = new ThingA12Dto { Name = "B", Thing1Id = tA1A.Id, Thing2Id = tA2B.Id }; - scope.Database.Insert(k2); + ScopeAccessor.AmbientScope.Database.Insert(k2); string sql = @"SELECT a1.id, a1.name, a2.id AS T2A__Id, a2.name AS T2A__Name, a3.id AS T2A__T3__Id, a3.name AS T2A__T3__Name, @@ -453,7 +453,7 @@ JOIN zbThingA2 a2x ON a12x.thing2id=a2x.id JOIN zbThingA3 a3x ON a2x.id=a3x.id "; - List ts = scope.Database.Fetch(sql); + List ts = ScopeAccessor.AmbientScope.Database.Fetch(sql); Assert.AreEqual(1, ts.Count); ThingA1Dto t = ts.First(); diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/AuditRepositoryTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/AuditRepositoryTest.cs index c586d496b7..4951146147 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/AuditRepositoryTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/AuditRepositoryTest.cs @@ -12,6 +12,7 @@ using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Infrastructure.Persistence; using Umbraco.Cms.Infrastructure.Persistence.Dtos; using Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; @@ -35,7 +36,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos var repo = new AuditRepository((IScopeAccessor)sp, _logger); repo.Save(new AuditItem(-1, AuditType.System, -1, UmbracoObjectTypes.Document.GetName(), "This is a System audit trail")); - List dtos = scope.Database.Fetch("WHERE id > -1"); + List dtos = ScopeAccessor.AmbientScope.Database.Fetch("WHERE id > -1"); Assert.That(dtos.Any(), Is.True); Assert.That(dtos.First().Comment, Is.EqualTo("This is a System audit trail")); @@ -63,7 +64,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos { var repo = new AuditRepository((IScopeAccessor)sp, _logger); - IEnumerable page = repo.GetPagedResultsByQuery(sp.SqlContext.Query(), 0, 10, out long total, Direction.Descending, null, null); + IEnumerable page = repo.GetPagedResultsByQuery(sp.CreateQuery(), 0, 10, out long total, Direction.Descending, null, null); Assert.AreEqual(10, page.Count()); Assert.AreEqual(200, total); @@ -91,12 +92,12 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos { var repo = new AuditRepository((IScopeAccessor)sp, _logger); - IQuery query = sp.SqlContext.Query().Where(x => x.UserId == -1); + IQuery query = sp.CreateQuery().Where(x => x.UserId == -1); try { - scope.Database.AsUmbracoDatabase().EnableSqlTrace = true; - scope.Database.AsUmbracoDatabase().EnableSqlCount = true; + ScopeAccessor.AmbientScope.Database.AsUmbracoDatabase().EnableSqlTrace = true; + ScopeAccessor.AmbientScope.Database.AsUmbracoDatabase().EnableSqlCount = true; IEnumerable page = repo.GetPagedResultsByQuery( query, @@ -105,7 +106,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos out long total, Direction.Descending, new[] { AuditType.Publish }, - sp.SqlContext.Query() + sp.CreateQuery() .Where(x => x.UserId > -2)); Assert.AreEqual(10, page.Count()); @@ -113,8 +114,8 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos } finally { - scope.Database.AsUmbracoDatabase().EnableSqlTrace = false; - scope.Database.AsUmbracoDatabase().EnableSqlCount = false; + ScopeAccessor.AmbientScope.Database.AsUmbracoDatabase().EnableSqlTrace = false; + ScopeAccessor.AmbientScope.Database.AsUmbracoDatabase().EnableSqlCount = false; } } } @@ -141,7 +142,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos var repo = new AuditRepository((IScopeAccessor)sp, _logger); IAuditItem[] page = repo.GetPagedResultsByQuery( - sp.SqlContext.Query(), + sp.CreateQuery(), 0, 9, out long total, @@ -178,13 +179,13 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos var repo = new AuditRepository((IScopeAccessor)sp, _logger); IAuditItem[] page = repo.GetPagedResultsByQuery( - sp.SqlContext.Query(), + sp.CreateQuery(), 0, 8, out long total, Direction.Descending, null, - sp.SqlContext.Query() + sp.CreateQuery() .Where(item => item.Comment == "Content created")) .ToArray(); diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/CacheInstructionRepositoryTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/CacheInstructionRepositoryTest.cs index faa5fd9d6e..f39b4311b2 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/CacheInstructionRepositoryTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/CacheInstructionRepositoryTest.cs @@ -13,6 +13,7 @@ using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Infrastructure.Persistence; using Umbraco.Cms.Infrastructure.Persistence.Dtos; using Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; @@ -98,7 +99,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos var repo = new CacheInstructionRepository((IScopeAccessor)sp); repo.Add(new CacheInstruction(0, date, Instructions, OriginIdentiy, InstructionCount)); - List dtos = scope.Database.Fetch("WHERE id > -1"); + List dtos = ScopeAccessor.AmbientScope.Database.Fetch("WHERE id > -1"); Assert.That(dtos.Any(), Is.True); diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/ContentTypeRepositoryTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/ContentTypeRepositoryTest.cs index 9f79414b55..38882c1638 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/ContentTypeRepositoryTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/ContentTypeRepositoryTest.cs @@ -17,6 +17,7 @@ using Umbraco.Cms.Core.Persistence.Repositories; using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Core.Services; using Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Cms.Tests.Common.Builders; using Umbraco.Cms.Tests.Common.Extensions; using Umbraco.Cms.Tests.Common.Testing; @@ -552,7 +553,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos ContentTypeRepository repository = ContentTypeRepository; // Act - IEnumerable contentTypes = repository.Get(scope.SqlContext.Query().Where(x => x.ParentId == contentType.Id)); + IEnumerable contentTypes = repository.Get(provider.CreateQuery().Where(x => x.ParentId == contentType.Id)); // Assert Assert.That(contentTypes.Count(), Is.EqualTo(3)); @@ -630,7 +631,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos // Act IEnumerable contentTypes = repository.GetMany(); int count = - scope.Database.ExecuteScalar( + ScopeAccessor.AmbientScope.Database.ExecuteScalar( "SELECT COUNT(*) FROM umbracoNode WHERE nodeObjectType = @NodeObjectType", new { NodeObjectType = Constants.ObjectTypes.DocumentType }); @@ -653,7 +654,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos // Act IEnumerable contentTypes = ((IReadRepository)repository).GetMany(allGuidIds); int count = - scope.Database.ExecuteScalar( + ScopeAccessor.AmbientScope.Database.ExecuteScalar( "SELECT COUNT(*) FROM umbracoNode WHERE nodeObjectType = @NodeObjectType", new { NodeObjectType = Constants.ObjectTypes.DocumentType }); diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/DataTypeDefinitionRepositoryTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/DataTypeDefinitionRepositoryTest.cs index baa94c6e9e..8cb7686982 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/DataTypeDefinitionRepositoryTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/DataTypeDefinitionRepositoryTest.cs @@ -279,7 +279,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos using (IScope scope = ScopeProvider.CreateScope()) { // Act - IQuery query = scope.SqlContext.Query().Where(x => x.EditorAlias == Constants.PropertyEditors.Aliases.RadioButtonList); + IQuery query = ScopeProvider.CreateQuery().Where(x => x.EditorAlias == Constants.PropertyEditors.Aliases.RadioButtonList); IDataType[] result = DataTypeRepository.Get(query).ToArray(); // Assert @@ -295,7 +295,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos using (IScope scope = ScopeProvider.CreateScope()) { // Act - IQuery query = scope.SqlContext.Query().Where(x => x.Name.StartsWith("D")); + IQuery query = ScopeProvider.CreateQuery().Where(x => x.Name.StartsWith("D")); int count = DataTypeRepository.Count(query); // Assert diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/DictionaryRepositoryTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/DictionaryRepositoryTest.cs index 87f33b8589..fc3caa6acf 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/DictionaryRepositoryTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/DictionaryRepositoryTest.cs @@ -191,7 +191,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos IDictionaryRepository repository = CreateRepository(); // Act - IQuery query = provider.SqlContext.Query().Where(x => x.ItemKey == "Article"); + IQuery query = provider.CreateQuery().Where(x => x.ItemKey == "Article"); IEnumerable result = repository.Get(query); // Assert @@ -211,7 +211,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos IDictionaryRepository repository = CreateRepository(); // Act - IQuery query = provider.SqlContext.Query().Where(x => x.ItemKey.StartsWith("Read")); + IQuery query = provider.CreateQuery().Where(x => x.ItemKey.StartsWith("Read")); int result = repository.Count(query); // Assert diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/DocumentRepositoryTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/DocumentRepositoryTest.cs index 7207718071..2059564cd8 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/DocumentRepositoryTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/DocumentRepositoryTest.cs @@ -24,6 +24,7 @@ using Umbraco.Cms.Core.Services; using Umbraco.Cms.Infrastructure.Persistence; using Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement; using Umbraco.Cms.Infrastructure.Persistence.SqlSyntax; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Cms.Tests.Common.Builders; using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; @@ -152,11 +153,13 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos new IsolatedCaches(t => new ObjectCacheAppCache())); IScopeProvider provider = ScopeProvider; + IScopeAccessor scopeAccessor = ScopeAccessor; + using (IScope scope = provider.CreateScope()) { DocumentRepository repository = CreateRepository((IScopeAccessor)provider, out ContentTypeRepository contentTypeRepository, appCaches: realCache); - IUmbracoDatabase udb = scope.Database; + IUmbracoDatabase udb = scopeAccessor.AmbientScope.Database; udb.EnableSqlCount = false; @@ -230,7 +233,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos Assert.AreEqual(versions[^1], repository.Get(content1.Id).VersionId); // misc checks - Assert.AreEqual(true, scope.Database.ExecuteScalar($"SELECT published FROM {Constants.DatabaseSchema.Tables.Document} WHERE nodeId=@id", new { id = content1.Id })); + Assert.AreEqual(true, ScopeAccessor.AmbientScope.Database.ExecuteScalar($"SELECT published FROM {Constants.DatabaseSchema.Tables.Document} WHERE nodeId=@id", new { id = content1.Id })); // change something // save = update the current (draft) version @@ -246,7 +249,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos Assert.AreEqual(versions[^1], repository.Get(content1.Id).VersionId); // misc checks - Assert.AreEqual(true, scope.Database.ExecuteScalar($"SELECT published FROM {Constants.DatabaseSchema.Tables.Document} WHERE nodeId=@id", new { id = content1.Id })); + Assert.AreEqual(true, ScopeAccessor.AmbientScope.Database.ExecuteScalar($"SELECT published FROM {Constants.DatabaseSchema.Tables.Document} WHERE nodeId=@id", new { id = content1.Id })); // unpublish = no impact on versions ((Content)content1).PublishedState = PublishedState.Unpublishing; @@ -261,7 +264,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos Assert.AreEqual(versions[^1], repository.Get(content1.Id).VersionId); // misc checks - Assert.AreEqual(false, scope.Database.ExecuteScalar($"SELECT published FROM {Constants.DatabaseSchema.Tables.Document} WHERE nodeId=@id", new { id = content1.Id })); + Assert.AreEqual(false, ScopeAccessor.AmbientScope.Database.ExecuteScalar($"SELECT published FROM {Constants.DatabaseSchema.Tables.Document} WHERE nodeId=@id", new { id = content1.Id })); // change something // save = update the current (draft) version @@ -276,7 +279,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos Assert.AreEqual(versions[^1], repository.Get(content1.Id).VersionId); // misc checks - Assert.AreEqual(false, scope.Database.ExecuteScalar($"SELECT published FROM {Constants.DatabaseSchema.Tables.Document} WHERE nodeId=@id", new { id = content1.Id })); + Assert.AreEqual(false, ScopeAccessor.AmbientScope.Database.ExecuteScalar($"SELECT published FROM {Constants.DatabaseSchema.Tables.Document} WHERE nodeId=@id", new { id = content1.Id })); // publish = version content1.PublishCulture(CultureImpact.Invariant); @@ -292,7 +295,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos Assert.AreEqual(versions[^1], repository.Get(content1.Id).VersionId); // misc checks - Assert.AreEqual(true, scope.Database.ExecuteScalar($"SELECT published FROM {Constants.DatabaseSchema.Tables.Document} WHERE nodeId=@id", new { id = content1.Id })); + Assert.AreEqual(true, ScopeAccessor.AmbientScope.Database.ExecuteScalar($"SELECT published FROM {Constants.DatabaseSchema.Tables.Document} WHERE nodeId=@id", new { id = content1.Id })); // change something // save = update the current (draft) version @@ -310,7 +313,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos Assert.AreEqual(versions[^1], repository.Get(content1.Id).VersionId); // misc checks - Assert.AreEqual(true, scope.Database.ExecuteScalar($"SELECT published FROM {Constants.DatabaseSchema.Tables.Document} WHERE nodeId=@id", new { id = content1.Id })); + Assert.AreEqual(true, ScopeAccessor.AmbientScope.Database.ExecuteScalar($"SELECT published FROM {Constants.DatabaseSchema.Tables.Document} WHERE nodeId=@id", new { id = content1.Id })); // publish = new version content1.Name = "name-4"; @@ -328,7 +331,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos Assert.AreEqual(versions[^1], repository.Get(content1.Id).VersionId); // misc checks - Assert.AreEqual(true, scope.Database.ExecuteScalar($"SELECT published FROM {Constants.DatabaseSchema.Tables.Document} WHERE nodeId=@id", new { id = content1.Id })); + Assert.AreEqual(true, ScopeAccessor.AmbientScope.Database.ExecuteScalar($"SELECT published FROM {Constants.DatabaseSchema.Tables.Document} WHERE nodeId=@id", new { id = content1.Id })); // all versions IContent[] allVersions = repository.GetAllVersions(content1.Id).ToArray(); @@ -700,7 +703,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos { DocumentRepository repository = CreateRepository((IScopeAccessor)provider, out _); - IQuery query = scope.SqlContext.Query().Where(x => x.Level == 2); + IQuery query = ScopeProvider.CreateQuery().Where(x => x.Level == 2); IEnumerable result = repository.Get(query); Assert.GreaterOrEqual(2, result.Count()); @@ -838,10 +841,10 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos try { - scope.Database.AsUmbracoDatabase().EnableSqlTrace = true; - scope.Database.AsUmbracoDatabase().EnableSqlCount = true; + ScopeAccessor.AmbientScope.Database.AsUmbracoDatabase().EnableSqlTrace = true; + ScopeAccessor.AmbientScope.Database.AsUmbracoDatabase().EnableSqlCount = true; - IQuery query = scope.SqlContext.Query().Where(x => x.ParentId == root.Id); + IQuery query = ScopeProvider.CreateQuery().Where(x => x.ParentId == root.Id); IEnumerable result = repository.GetPage(query, 0, 20, out long totalRecords, null, Ordering.By("UpdateDate")); Assert.AreEqual(25, totalRecords); @@ -864,8 +867,8 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos } finally { - scope.Database.AsUmbracoDatabase().EnableSqlTrace = false; - scope.Database.AsUmbracoDatabase().EnableSqlCount = false; + ScopeAccessor.AmbientScope.Database.AsUmbracoDatabase().EnableSqlTrace = false; + ScopeAccessor.AmbientScope.Database.AsUmbracoDatabase().EnableSqlCount = false; } } } @@ -878,12 +881,12 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos { DocumentRepository repository = CreateRepository((IScopeAccessor)provider, out _); - IQuery query = scope.SqlContext.Query().Where(x => x.Name.Contains("Text")); + IQuery query = ScopeProvider.CreateQuery().Where(x => x.Name.Contains("Text")); try { - scope.Database.AsUmbracoDatabase().EnableSqlTrace = true; - scope.Database.AsUmbracoDatabase().EnableSqlCount = true; + ScopeAccessor.AmbientScope.Database.AsUmbracoDatabase().EnableSqlTrace = true; + ScopeAccessor.AmbientScope.Database.AsUmbracoDatabase().EnableSqlCount = true; IEnumerable result = repository.GetPage(query, 0, 2, out long totalRecords, null, Ordering.By("title", isCustomField: true)); @@ -896,8 +899,8 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos } finally { - scope.Database.AsUmbracoDatabase().EnableSqlTrace = false; - scope.Database.AsUmbracoDatabase().EnableSqlCount = false; + ScopeAccessor.AmbientScope.Database.AsUmbracoDatabase().EnableSqlTrace = false; + ScopeAccessor.AmbientScope.Database.AsUmbracoDatabase().EnableSqlCount = false; } } } @@ -910,12 +913,12 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos { DocumentRepository repository = CreateRepository((IScopeAccessor)provider, out _); - IQuery query = scope.SqlContext.Query().Where(x => x.Level == 2); + IQuery query = ScopeProvider.CreateQuery().Where(x => x.Level == 2); try { - scope.Database.AsUmbracoDatabase().EnableSqlTrace = true; - scope.Database.AsUmbracoDatabase().EnableSqlCount = true; + ScopeAccessor.AmbientScope.Database.AsUmbracoDatabase().EnableSqlTrace = true; + ScopeAccessor.AmbientScope.Database.AsUmbracoDatabase().EnableSqlCount = true; IEnumerable result = repository.GetPage(query, 0, 1, out long totalRecords, null, Ordering.By("Name")); @@ -925,8 +928,8 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos } finally { - scope.Database.AsUmbracoDatabase().EnableSqlTrace = false; - scope.Database.AsUmbracoDatabase().EnableSqlCount = false; + ScopeAccessor.AmbientScope.Database.AsUmbracoDatabase().EnableSqlTrace = false; + ScopeAccessor.AmbientScope.Database.AsUmbracoDatabase().EnableSqlCount = false; } } } @@ -939,7 +942,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos { DocumentRepository repository = CreateRepository((IScopeAccessor)provider, out _); - IQuery query = scope.SqlContext.Query().Where(x => x.Level == 2); + IQuery query = ScopeProvider.CreateQuery().Where(x => x.Level == 2); IEnumerable result = repository.GetPage(query, 1, 1, out long totalRecords, null, Ordering.By("Name")); Assert.That(totalRecords, Is.GreaterThanOrEqualTo(2)); @@ -956,7 +959,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos { DocumentRepository repository = CreateRepository((IScopeAccessor)provider, out _); - IQuery query = scope.SqlContext.Query().Where(x => x.Level == 2); + IQuery query = ScopeProvider.CreateQuery().Where(x => x.Level == 2); IEnumerable result = repository.GetPage(query, 0, 2, out long totalRecords, null, Ordering.By("Name")); Assert.That(totalRecords, Is.GreaterThanOrEqualTo(2)); @@ -973,7 +976,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos { DocumentRepository repository = CreateRepository((IScopeAccessor)provider, out _); - IQuery query = scope.SqlContext.Query().Where(x => x.Level == 2); + IQuery query = ScopeProvider.CreateQuery().Where(x => x.Level == 2); IEnumerable result = repository.GetPage(query, 0, 1, out long totalRecords, null, Ordering.By("Name", Direction.Descending)); Assert.That(totalRecords, Is.GreaterThanOrEqualTo(2)); @@ -990,9 +993,9 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos { DocumentRepository repository = CreateRepository((IScopeAccessor)provider, out _); - IQuery query = scope.SqlContext.Query().Where(x => x.Level == 2); + IQuery query = ScopeProvider.CreateQuery().Where(x => x.Level == 2); - IQuery filterQuery = scope.SqlContext.Query().Where(x => x.Name.Contains("Page 2")); + IQuery filterQuery = ScopeProvider.CreateQuery().Where(x => x.Name.Contains("Page 2")); IEnumerable result = repository.GetPage(query, 0, 1, out long totalRecords, filterQuery, Ordering.By("Name")); Assert.That(totalRecords, Is.EqualTo(1)); @@ -1009,9 +1012,9 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos { DocumentRepository repository = CreateRepository((IScopeAccessor)provider, out _); - IQuery query = scope.SqlContext.Query().Where(x => x.Level == 2); + IQuery query = ScopeProvider.CreateQuery().Where(x => x.Level == 2); - IQuery filterQuery = scope.SqlContext.Query().Where(x => x.Name.Contains("text")); + IQuery filterQuery = ScopeProvider.CreateQuery().Where(x => x.Name.Contains("text")); IEnumerable result = repository.GetPage(query, 0, 1, out long totalRecords, filterQuery, Ordering.By("Name")); Assert.That(totalRecords, Is.EqualTo(2)); @@ -1084,7 +1087,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos { DocumentRepository repository = CreateRepository((IScopeAccessor)provider, out _); - IQuery query = scope.SqlContext.Query().Where(x => x.Level == 2); + IQuery query = ScopeProvider.CreateQuery().Where(x => x.Level == 2); int result = repository.Count(query); Assert.That(result, Is.GreaterThanOrEqualTo(2)); @@ -1099,7 +1102,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos { DocumentRepository repository = CreateRepository((IScopeAccessor)provider, out _); - IQuery query = scope.SqlContext.Query().Where(x => x.Key == new Guid("B58B3AD4-62C2-4E27-B1BE-837BD7C533E0")); + IQuery query = ScopeProvider.CreateQuery().Where(x => x.Key == new Guid("B58B3AD4-62C2-4E27-B1BE-837BD7C533E0")); IContent content = repository.Get(query).SingleOrDefault(); Assert.IsNotNull(content); diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/DocumentVersionRepositoryTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/DocumentVersionRepositoryTest.cs index ba5c176ee2..c25bd69653 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/DocumentVersionRepositoryTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/DocumentVersionRepositoryTest.cs @@ -6,6 +6,7 @@ using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Core.Services; using Umbraco.Cms.Infrastructure.Persistence.Dtos; using Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Cms.Tests.Common.Builders; using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; @@ -78,7 +79,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos using (var scope = ScopeProvider.CreateScope()) { - scope.Database.Update("set preventCleanup = 1 where id in (1,3)"); + ScopeAccessor.AmbientScope.Database.Update("set preventCleanup = 1 where id in (1,3)"); var sut = new DocumentVersionRepository(ScopeAccessor); var results = sut.GetDocumentVersionsEligibleForCleanup(); @@ -113,7 +114,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos ContentService.SaveAndPublish(content); using (var scope = ScopeProvider.CreateScope()) { - var query = scope.SqlContext.Sql(); + var query = ScopeAccessor.AmbientScope.SqlContext.Sql(); query.Select() .From(); @@ -121,7 +122,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos var sut = new DocumentVersionRepository(ScopeAccessor); sut.DeleteVersions(new []{1,2,3}); - var after = scope.Database.Fetch(query); + var after = ScopeAccessor.AmbientScope.Database.Fetch(query); Assert.Multiple(() => { diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/DomainRepositoryTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/DomainRepositoryTest.cs index c53099cee9..4928354d97 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/DomainRepositoryTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/DomainRepositoryTest.cs @@ -12,6 +12,7 @@ using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Persistence.Repositories; using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Cms.Tests.Common.Builders; using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/EntityRepositoryTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/EntityRepositoryTest.cs index 9da3f6ef59..a70355c887 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/EntityRepositoryTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/EntityRepositoryTest.cs @@ -11,6 +11,7 @@ using Umbraco.Cms.Core.Persistence.Querying; using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Core.Services; using Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Cms.Tests.Common.Builders; using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; @@ -68,7 +69,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos System.Guid[] objectTypes = new[] { Constants.ObjectTypes.Document, Constants.ObjectTypes.Media, Constants.ObjectTypes.Member }; - IQuery query = provider.SqlContext.Query() + IQuery query = provider.CreateQuery() .WhereIn(e => e.Id, ids); var entities = repo.GetPagedResultsByQuery(query, objectTypes, 0, 20, out long totalRecords, null, null).ToList(); diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/KeyValueRepositoryTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/KeyValueRepositoryTests.cs index 3f3a709ce9..4f6934a481 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/KeyValueRepositoryTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/KeyValueRepositoryTests.cs @@ -8,6 +8,7 @@ using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Persistence.Repositories; using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/LanguageRepositoryTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/LanguageRepositoryTest.cs index 242533c651..3c157d9c5a 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/LanguageRepositoryTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/LanguageRepositoryTest.cs @@ -15,6 +15,7 @@ using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Core.Services; using Umbraco.Cms.Infrastructure.Persistence; using Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; @@ -40,7 +41,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos IScopeProvider provider = ScopeProvider; using (IScope scope = provider.CreateScope()) { - scope.Database.AsUmbracoDatabase().EnableSqlTrace = true; + ScopeAccessor.AmbientScope.Database.AsUmbracoDatabase().EnableSqlTrace = true; LanguageRepository repository = CreateRepository(provider); // Act @@ -150,7 +151,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos LanguageRepository repository = CreateRepository(provider); // Act - IQuery query = scope.SqlContext.Query().Where(x => x.IsoCode == "da-DK"); + IQuery query = provider.CreateQuery().Where(x => x.IsoCode == "da-DK"); IEnumerable result = repository.Get(query); // Assert @@ -170,7 +171,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos LanguageRepository repository = CreateRepository(provider); // Act - IQuery query = scope.SqlContext.Query().Where(x => x.IsoCode.StartsWith("D")); + IQuery query = provider.CreateQuery().Where(x => x.IsoCode.StartsWith("D")); int count = repository.Count(query); // Assert diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/MacroRepositoryTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/MacroRepositoryTest.cs index 2766e66426..bfba8b32e0 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/MacroRepositoryTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/MacroRepositoryTest.cs @@ -11,6 +11,7 @@ using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Persistence.Querying; using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; @@ -127,7 +128,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos var repository = new MacroRepository((IScopeAccessor)provider, AppCaches.Disabled, _logger, ShortStringHelper); // Act - IQuery query = scope.SqlContext.Query().Where(x => x.Alias.ToUpper() == "TEST1"); + IQuery query = ScopeAccessor.AmbientScope.SqlContext.Query().Where(x => x.Alias.ToUpper() == "TEST1"); IEnumerable result = repository.Get((IQuery)query); // Assert @@ -145,7 +146,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos var repository = new MacroRepository((IScopeAccessor)provider, AppCaches.Disabled, _logger, ShortStringHelper); // Act - IQuery query = scope.SqlContext.Query().Where(x => x.Name.StartsWith("Test")); + IQuery query = ScopeAccessor.AmbientScope.SqlContext.Query().Where(x => x.Name.StartsWith("Test")); int count = repository.Count(query); // Assert diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/MediaRepositoryTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/MediaRepositoryTest.cs index fc98b8ef10..1acba24035 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/MediaRepositoryTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/MediaRepositoryTest.cs @@ -24,6 +24,7 @@ using Umbraco.Cms.Core.Services; using Umbraco.Cms.Infrastructure.Persistence; using Umbraco.Cms.Infrastructure.Persistence.Dtos; using Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Cms.Tests.Common.Builders; using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; @@ -84,7 +85,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos { MediaRepository repository = CreateRepository(provider, out MediaTypeRepository mediaTypeRepository, appCaches: realCache); - IUmbracoDatabase udb = scope.Database; + IUmbracoDatabase udb = ScopeAccessor.AmbientScope.Database; udb.EnableSqlCount = false; @@ -271,7 +272,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos MediaRepository repository = CreateRepository(provider, out MediaTypeRepository mediaTypeRepository); // Act - IQuery query = scope.SqlContext.Query().Where(x => x.Level == 2); + IQuery query = provider.CreateQuery().Where(x => x.Level == 2); IEnumerable result = repository.Get(query); // Assert @@ -297,7 +298,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos } int[] types = new[] { 1031 }; - IQuery query = scope.SqlContext.Query().Where(x => types.Contains(x.ContentTypeId)); + IQuery query = provider.CreateQuery().Where(x => types.Contains(x.ContentTypeId)); IEnumerable result = repository.Get(query); // Assert @@ -327,7 +328,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos } string[] types = new[] { "Folder" }; - IQuery query = scope.SqlContext.Query().Where(x => types.Contains(x.ContentType.Alias)); + IQuery query = provider.CreateQuery().Where(x => types.Contains(x.ContentType.Alias)); IEnumerable result = repository.Get(query); // Assert @@ -345,7 +346,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos MediaRepository repository = CreateRepository(provider, out MediaTypeRepository mediaTypeRepository); // Act - IQuery query = scope.SqlContext.Query().Where(x => x.Level == 2); + IQuery query = provider.CreateQuery().Where(x => x.Level == 2); IEnumerable result = repository.GetPage(query, 0, 1, out long totalRecords, null, Ordering.By("SortOrder")); // Assert @@ -365,7 +366,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos MediaRepository repository = CreateRepository(provider, out MediaTypeRepository mediaTypeRepository); // Act - IQuery query = scope.SqlContext.Query().Where(x => x.Level == 2); + IQuery query = provider.CreateQuery().Where(x => x.Level == 2); IEnumerable result = repository.GetPage(query, 1, 1, out long totalRecords, null, Ordering.By("SortOrder")); // Assert @@ -385,7 +386,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos MediaRepository repository = CreateRepository(provider, out MediaTypeRepository mediaTypeRepository); // Act - IQuery query = scope.SqlContext.Query().Where(x => x.Level == 2); + IQuery query = provider.CreateQuery().Where(x => x.Level == 2); IEnumerable result = repository.GetPage(query, 0, 2, out long totalRecords, null, Ordering.By("SortOrder")); // Assert @@ -405,7 +406,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos MediaRepository repository = CreateRepository(provider, out MediaTypeRepository mediaTypeRepository); // Act - IQuery query = scope.SqlContext.Query().Where(x => x.Level == 2); + IQuery query = provider.CreateQuery().Where(x => x.Level == 2); IEnumerable result = repository.GetPage(query, 0, 1, out long totalRecords, null, Ordering.By("SortOrder", Direction.Descending)); // Assert @@ -425,7 +426,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos MediaRepository repository = CreateRepository(provider, out MediaTypeRepository mediaTypeRepository); // Act - IQuery query = scope.SqlContext.Query().Where(x => x.Level == 2); + IQuery query = provider.CreateQuery().Where(x => x.Level == 2); IEnumerable result = repository.GetPage(query, 0, 1, out long totalRecords, null, Ordering.By("Name")); // Assert @@ -445,9 +446,9 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos MediaRepository repository = CreateRepository(provider, out MediaTypeRepository mediaTypeRepository); // Act - IQuery query = scope.SqlContext.Query().Where(x => x.Level == 2); + IQuery query = provider.CreateQuery().Where(x => x.Level == 2); - IQuery filter = scope.SqlContext.Query().Where(x => x.Name.Contains("File")); + IQuery filter = provider.CreateQuery().Where(x => x.Name.Contains("File")); IEnumerable result = repository.GetPage(query, 0, 1, out long totalRecords, filter, Ordering.By("SortOrder")); // Assert @@ -467,9 +468,9 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos MediaRepository repository = CreateRepository(provider, out _); // Act - IQuery query = scope.SqlContext.Query().Where(x => x.Level == 2); + IQuery query = provider.CreateQuery().Where(x => x.Level == 2); - IQuery filter = scope.SqlContext.Query().Where(x => x.Name.Contains("Test")); + IQuery filter = provider.CreateQuery().Where(x => x.Name.Contains("Test")); IEnumerable result = repository.GetPage(query, 0, 1, out long totalRecords, filter, Ordering.By("SortOrder")); // Assert @@ -559,7 +560,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos // Act int level = 2; - IQuery query = scope.SqlContext.Query().Where(x => x.Level == level); + IQuery query = provider.CreateQuery().Where(x => x.Level == level); int result = repository.Count(query); // Assert diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/MediaTypeRepositoryTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/MediaTypeRepositoryTest.cs index 46cdca4194..51a71c30e1 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/MediaTypeRepositoryTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/MediaTypeRepositoryTest.cs @@ -13,6 +13,7 @@ using Umbraco.Cms.Core.Persistence; using Umbraco.Cms.Core.Persistence.Repositories; using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Cms.Tests.Common.Builders; using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; @@ -294,7 +295,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos // Act IEnumerable mediaTypes = repository.GetMany(); int count = - scope.Database.ExecuteScalar( + ScopeAccessor.AmbientScope.Database.ExecuteScalar( "SELECT COUNT(*) FROM umbracoNode WHERE nodeObjectType = @NodeObjectType", new { NodeObjectType = Constants.ObjectTypes.MediaType }); @@ -319,7 +320,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos IEnumerable mediaTypes = ((IReadRepository)repository).GetMany(allGuidIds); int count = - scope.Database.ExecuteScalar( + ScopeAccessor.AmbientScope.Database.ExecuteScalar( "SELECT COUNT(*) FROM umbracoNode WHERE nodeObjectType = @NodeObjectType", new { NodeObjectType = Constants.ObjectTypes.MediaType }); diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/MemberRepositoryTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/MemberRepositoryTest.cs index d8bf4be14a..d5fb7d3edc 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/MemberRepositoryTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/MemberRepositoryTest.cs @@ -28,6 +28,7 @@ using Umbraco.Cms.Infrastructure.Persistence; using Umbraco.Cms.Infrastructure.Persistence.Dtos; using Umbraco.Cms.Infrastructure.Persistence.Querying; using Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Cms.Tests.Common.Builders; using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; @@ -151,7 +152,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos IMember member = CreateTestMember(key: key); // Act - IQuery query = scope.SqlContext.Query().Where(x => x.Key == key); + IQuery query = provider.CreateQuery().Where(x => x.Key == key); IEnumerable result = repository.Get(query); // Assert @@ -271,20 +272,23 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos { IScopeProvider provider = ScopeProvider; - IQuery query = provider.SqlContext.Query().Where(x => - ((Member)x).LongStringPropertyValue.Contains("1095") && - ((Member)x).PropertyTypeAlias == "headshot"); + using (provider.CreateScope()) + { + IQuery query = provider.CreateQuery().Where(x => + ((Member)x).LongStringPropertyValue.Contains("1095") && + ((Member)x).PropertyTypeAlias == "headshot"); - Sql sqlSubquery = GetSubquery(); - var translator = new SqlTranslator(sqlSubquery, query); - Sql subquery = translator.Translate(); - Sql sql = GetBaseQuery(false) - .Append("WHERE umbracoNode.id IN (" + subquery.SQL + ")", subquery.Arguments) - .OrderByDescending(x => x.VersionDate) - .OrderBy(x => x.SortOrder); + Sql sqlSubquery = GetSubquery(); + var translator = new SqlTranslator(sqlSubquery, query); + Sql subquery = translator.Translate(); + Sql sql = GetBaseQuery(false) + .Append("WHERE umbracoNode.id IN (" + subquery.SQL + ")", subquery.Arguments) + .OrderByDescending(x => x.VersionDate) + .OrderBy(x => x.SortOrder); - Debug.Print(sql.SQL); - Assert.That(sql.SQL, Is.Not.Empty); + Debug.Print(sql.SQL); + Assert.That(sql.SQL, Is.Not.Empty); + } } private IMember CreateTestMember(IMemberType memberType = null, string name = null, string email = null, string password = null, string username = null, Guid? key = null) @@ -327,7 +331,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos IScopeProvider provider = ScopeProvider; if (isCount) { - Sql sqlCount = provider.SqlContext.Sql() + Sql sqlCount = ScopeAccessor.AmbientScope.SqlContext.Sql() .SelectCount() .From() .InnerJoin().On(left => left.NodeId, right => right.NodeId) @@ -338,7 +342,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos return sqlCount; } - Sql sql = provider.SqlContext.Sql(); + Sql sql = ScopeAccessor.AmbientScope.SqlContext.Sql(); sql.Select( "umbracoNode.*", $"{Constants.DatabaseSchema.Tables.Content}.contentTypeId", @@ -381,7 +385,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos private Sql GetSubquery() { IScopeProvider provider = ScopeProvider; - Sql sql = provider.SqlContext.Sql(); + Sql sql = ScopeAccessor.AmbientScope.SqlContext.Sql(); sql.Select("umbracoNode.id") .From() .InnerJoin().On(left => left.NodeId, right => right.NodeId) diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/MemberTypeRepositoryTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/MemberTypeRepositoryTest.cs index c963375e3f..33209abc6a 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/MemberTypeRepositoryTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/MemberTypeRepositoryTest.cs @@ -14,6 +14,7 @@ using Umbraco.Cms.Core.Persistence; using Umbraco.Cms.Core.Persistence.Repositories; using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Cms.Tests.Common.Builders; using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/NotificationsRepositoryTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/NotificationsRepositoryTest.cs index be625e4afd..f7bfbb989e 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/NotificationsRepositoryTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/NotificationsRepositoryTest.cs @@ -13,6 +13,7 @@ using Umbraco.Cms.Core.Models.Membership; using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Infrastructure.Persistence.Dtos; using Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; using Constants = Umbraco.Cms.Core.Constants; @@ -44,7 +45,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos UniqueId = Guid.NewGuid(), UserId = Constants.Security.SuperUserId }; - object result = scope.Database.Insert(node); + object result = ScopeAccessor.AmbientScope.Database.Insert(node); IEntity entity = Mock.Of(e => e.Id == node.NodeId); IUser user = Mock.Of(e => e.Id == node.UserId); @@ -66,7 +67,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos var repo = new NotificationsRepository((IScopeAccessor)provider); var userDto = new UserDto { Email = "test", Login = "test", Password = "test", UserName = "test", UserLanguage = "en", CreateDate = DateTime.Now, UpdateDate = DateTime.Now }; - scope.Database.Insert(userDto); + ScopeAccessor.AmbientScope.Database.Insert(userDto); IUser userNew = Mock.Of(e => e.Id == userDto.Id); IUser userAdmin = Mock.Of(e => e.Id == Constants.Security.SuperUserId); @@ -74,7 +75,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos for (int i = 0; i < 10; i++) { var node = new NodeDto { CreateDate = DateTime.Now, Level = 1, NodeObjectType = Constants.ObjectTypes.ContentItem, ParentId = -1, Path = "-1," + i, SortOrder = 1, Text = "hello" + i, Trashed = false, UniqueId = Guid.NewGuid(), UserId = -1 }; - object result = scope.Database.Insert(node); + object result = ScopeAccessor.AmbientScope.Database.Insert(node); IEntity entity = Mock.Of(e => e.Id == node.NodeId); Notification notification = repo.CreateNotification((i % 2 == 0) ? userAdmin : userNew, entity, i.ToString(CultureInfo.InvariantCulture)); } @@ -94,16 +95,16 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos var repo = new NotificationsRepository((IScopeAccessor)provider); var node1 = new NodeDto { CreateDate = DateTime.Now, Level = 1, NodeObjectType = Constants.ObjectTypes.ContentItem, ParentId = -1, Path = "-1,1", SortOrder = 1, Text = "hello1", Trashed = false, UniqueId = Guid.NewGuid(), UserId = -1 }; - scope.Database.Insert(node1); + ScopeAccessor.AmbientScope.Database.Insert(node1); IEntity entity1 = Mock.Of(e => e.Id == node1.NodeId); var node2 = new NodeDto { CreateDate = DateTime.Now, Level = 1, NodeObjectType = Constants.ObjectTypes.ContentItem, ParentId = -1, Path = "-1,2", SortOrder = 1, Text = "hello2", Trashed = false, UniqueId = Guid.NewGuid(), UserId = -1 }; - scope.Database.Insert(node2); + ScopeAccessor.AmbientScope.Database.Insert(node2); IEntity entity2 = Mock.Of(e => e.Id == node2.NodeId); for (int i = 0; i < 10; i++) { var userDto = new UserDto { Email = "test" + i, Login = "test" + i, Password = "test", UserName = "test" + i, UserLanguage = "en", CreateDate = DateTime.Now, UpdateDate = DateTime.Now }; - scope.Database.Insert(userDto); + ScopeAccessor.AmbientScope.Database.Insert(userDto); IUser userNew = Mock.Of(e => e.Id == userDto.Id); Notification notification = repo.CreateNotification(userNew, (i % 2 == 0) ? entity1 : entity2, i.ToString(CultureInfo.InvariantCulture)); } @@ -123,16 +124,16 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos var repo = new NotificationsRepository((IScopeAccessor)provider); var node1 = new NodeDto { CreateDate = DateTime.Now, Level = 1, NodeObjectType = Constants.ObjectTypes.ContentItem, ParentId = -1, Path = "-1,1", SortOrder = 1, Text = "hello1", Trashed = false, UniqueId = Guid.NewGuid(), UserId = -1 }; - scope.Database.Insert(node1); + ScopeAccessor.AmbientScope.Database.Insert(node1); IEntity entity1 = Mock.Of(e => e.Id == node1.NodeId); var node2 = new NodeDto { CreateDate = DateTime.Now, Level = 1, NodeObjectType = Constants.ObjectTypes.ContentItem, ParentId = -1, Path = "-1,2", SortOrder = 1, Text = "hello2", Trashed = false, UniqueId = Guid.NewGuid(), UserId = -1 }; - scope.Database.Insert(node2); + ScopeAccessor.AmbientScope.Database.Insert(node2); IEntity entity2 = Mock.Of(e => e.Id == node2.NodeId); for (int i = 0; i < 10; i++) { var userDto = new UserDto { Email = "test" + i, Login = "test" + i, Password = "test", UserName = "test" + i, UserLanguage = "en", CreateDate = DateTime.Now, UpdateDate = DateTime.Now }; - scope.Database.Insert(userDto); + ScopeAccessor.AmbientScope.Database.Insert(userDto); IUser userNew = Mock.Of(e => e.Id == userDto.Id); Notification notification = repo.CreateNotification(userNew, (i % 2 == 0) ? entity1 : entity2, i.ToString(CultureInfo.InvariantCulture)); } @@ -152,7 +153,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos var repo = new NotificationsRepository((IScopeAccessor)provider); var userDto = new UserDto { Email = "test", Login = "test", Password = "test", UserName = "test", UserLanguage = "en", CreateDate = DateTime.Now, UpdateDate = DateTime.Now }; - scope.Database.Insert(userDto); + ScopeAccessor.AmbientScope.Database.Insert(userDto); IUser userNew = Mock.Of(e => e.Id == userDto.Id); IUser userAdmin = Mock.Of(e => e.Id == Constants.Security.SuperUserId); @@ -160,7 +161,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos for (int i = 0; i < 10; i++) { var node = new NodeDto { CreateDate = DateTime.Now, Level = 1, NodeObjectType = Constants.ObjectTypes.ContentItem, ParentId = -1, Path = "-1," + i, SortOrder = 1, Text = "hello" + i, Trashed = false, UniqueId = Guid.NewGuid(), UserId = -1 }; - object result = scope.Database.Insert(node); + object result = ScopeAccessor.AmbientScope.Database.Insert(node); IEntity entity = Mock.Of(e => e.Id == node.NodeId); Notification notification = repo.CreateNotification((i % 2 == 0) ? userAdmin : userNew, entity, i.ToString(CultureInfo.InvariantCulture)); } diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/PublicAccessRepositoryTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/PublicAccessRepositoryTest.cs index 3926c4975c..283c8e57aa 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/PublicAccessRepositoryTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/PublicAccessRepositoryTest.cs @@ -11,6 +11,7 @@ using Umbraco.Cms.Core.Persistence.Repositories; using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Infrastructure.Persistence; using Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Cms.Tests.Common.Builders; using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; @@ -62,7 +63,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos IScopeProvider provider = ScopeProvider; using (IScope scope = provider.CreateScope()) { - scope.Database.AsUmbracoDatabase().EnableSqlTrace = true; + ScopeAccessor.AmbientScope.Database.AsUmbracoDatabase().EnableSqlTrace = true; var repo = new PublicAccessRepository((IScopeAccessor)provider, AppCaches, LoggerFactory.CreateLogger()); PublicAccessRule[] rules = new[] @@ -102,7 +103,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos IScopeProvider provider = ScopeProvider; using (IScope scope = provider.CreateScope()) { - scope.Database.AsUmbracoDatabase().EnableSqlTrace = true; + ScopeAccessor.AmbientScope.Database.AsUmbracoDatabase().EnableSqlTrace = true; var repo = new PublicAccessRepository((IScopeAccessor)provider, AppCaches, LoggerFactory.CreateLogger()); PublicAccessRule[] rules = new[] diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/RedirectUrlRepositoryTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/RedirectUrlRepositoryTests.cs index 04a0fd3ebb..af75016d9a 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/RedirectUrlRepositoryTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/RedirectUrlRepositoryTests.cs @@ -11,6 +11,7 @@ using Umbraco.Cms.Core.Persistence.Repositories; using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Core.Services; using Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Cms.Tests.Common.Builders; using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/RelationRepositoryTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/RelationRepositoryTest.cs index ee01816f09..a20706c597 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/RelationRepositoryTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/RelationRepositoryTest.cs @@ -15,6 +15,7 @@ using Umbraco.Cms.Core.Persistence.Repositories; using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Core.Services; using Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Cms.Tests.Common.Builders; using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; @@ -361,7 +362,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos RelationRepository repository = CreateRepository(ScopeProvider, out RelationTypeRepository repositoryType); // Act - IQuery query = scope.SqlContext.Query().Where(x => x.ParentId == _textpage.Id); + IQuery query = ScopeProvider.CreateQuery().Where(x => x.ParentId == _textpage.Id); int count = repository.Count(query); // Assert @@ -378,7 +379,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos RelationRepository repository = CreateRepository(ScopeProvider, out RelationTypeRepository repositoryType); // Act - IQuery query = scope.SqlContext.Query().Where(x => x.RelationTypeId == _relateContent.Id); + IQuery query = ScopeProvider.CreateQuery().Where(x => x.RelationTypeId == _relateContent.Id); IEnumerable relations = repository.Get(query); // Assert diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/RelationTypeRepositoryTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/RelationTypeRepositoryTest.cs index 4b0a23464f..d99de65721 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/RelationTypeRepositoryTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/RelationTypeRepositoryTest.cs @@ -10,6 +10,7 @@ using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Persistence.Querying; using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; using Constants = Umbraco.Cms.Core.Constants; @@ -183,7 +184,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos RelationTypeRepository repository = CreateRepository(provider); // Act - IQuery query = scope.SqlContext.Query().Where(x => x.Alias.StartsWith("relate")); + IQuery query = provider.CreateQuery().Where(x => x.Alias.StartsWith("relate")); int count = repository.Count(query); // Assert @@ -202,7 +203,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos // Act System.Guid childObjType = Constants.ObjectTypes.DocumentType; - IQuery query = scope.SqlContext.Query().Where(x => x.ChildObjectType == childObjType); + IQuery query = provider.CreateQuery().Where(x => x.ChildObjectType == childObjType); IEnumerable result = repository.Get(query); // Assert diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/ServerRegistrationRepositoryTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/ServerRegistrationRepositoryTest.cs index f85796f622..10461dd577 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/ServerRegistrationRepositoryTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/ServerRegistrationRepositoryTest.cs @@ -11,6 +11,7 @@ using Umbraco.Cms.Core.Cache; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/TagRepositoryTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/TagRepositoryTest.cs index e2972ad504..8dc0a2ed81 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/TagRepositoryTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/TagRepositoryTest.cs @@ -11,6 +11,7 @@ using Umbraco.Cms.Core.Persistence.Repositories; using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Core.Services; using Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Cms.Tests.Common.Builders; using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; @@ -864,7 +865,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos DocumentRepository.Delete(content1); - Assert.AreEqual(0, scope.Database.ExecuteScalar( + Assert.AreEqual(0, ScopeAccessor.AmbientScope.Database.ExecuteScalar( "SELECT COUNT(*) FROM cmsTagRelationship WHERE nodeId=@nodeId AND propertyTypeId=@propTypeId", new { nodeId = content1.Id, propTypeId = contentType.PropertyTypes.First().Id })); } diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/TemplateRepositoryTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/TemplateRepositoryTest.cs index 80eb61d21f..7b0b8b9e21 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/TemplateRepositoryTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/TemplateRepositoryTest.cs @@ -22,6 +22,7 @@ using Umbraco.Cms.Core.PropertyEditors; using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Core.Services; using Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Cms.Infrastructure.Serialization; using Umbraco.Cms.Tests.Common.Builders; using Umbraco.Cms.Tests.Common.Testing; diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/UserGroupRepositoryTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/UserGroupRepositoryTest.cs index b38814b928..367d4f770e 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/UserGroupRepositoryTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/UserGroupRepositoryTest.cs @@ -10,6 +10,7 @@ using Umbraco.Cms.Core.Persistence.Querying; using Umbraco.Cms.Core.Persistence.Repositories; using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Cms.Tests.Common.Builders; using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; @@ -180,7 +181,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos CreateAndCommitMultipleUserGroups(repository); // Act - IQuery query = scope.SqlContext.Query().Where(x => x.Alias == "testGroup1"); + IQuery query = provider.CreateQuery().Where(x => x.Alias == "testGroup1"); IEnumerable result = repository.Get(query); // Assert @@ -261,7 +262,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos IUserGroup[] userGroups = CreateAndCommitMultipleUserGroups(repository); // Act - IQuery query = scope.SqlContext.Query().Where(x => x.Alias == "testGroup1" || x.Alias == "testGroup2"); + IQuery query = provider.CreateQuery().Where(x => x.Alias == "testGroup1" || x.Alias == "testGroup2"); int result = repository.Count(query); // Assert diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/UserRepositoryTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/UserRepositoryTest.cs index a613a42c36..52af0ac615 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/UserRepositoryTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/UserRepositoryTest.cs @@ -21,6 +21,7 @@ using Umbraco.Cms.Infrastructure.Persistence; using Umbraco.Cms.Infrastructure.Persistence.Dtos; using Umbraco.Cms.Infrastructure.Persistence.Mappers; using Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Cms.Infrastructure.Serialization; using Umbraco.Cms.Tests.Common.Builders; using Umbraco.Cms.Tests.Common.Builders.Extensions; @@ -192,7 +193,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos CreateAndCommitMultipleUsers(repository); // Act - IQuery query = scope.SqlContext.Query().Where(x => x.Username == "TestUser1"); + IQuery query = ScopeProvider.CreateQuery().Where(x => x.Username == "TestUser1"); IEnumerable result = repository.Get(query); // Assert @@ -273,7 +274,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos IUser[] users = CreateAndCommitMultipleUsers(repository); // Act - IQuery query = scope.SqlContext.Query().Where(x => x.Username == "TestUser1" || x.Username == "TestUser2"); + IQuery query = ScopeProvider.CreateQuery().Where(x => x.Username == "TestUser1" || x.Username == "TestUser2"); int result = repository.Count(query); // Assert @@ -290,12 +291,12 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos UserRepository repository = CreateRepository(provider); IUser[] users = CreateAndCommitMultipleUsers(repository); - IQuery query = provider.SqlContext.Query().Where(x => x.Username == "TestUser1" || x.Username == "TestUser2"); + IQuery query = provider.CreateQuery().Where(x => x.Username == "TestUser1" || x.Username == "TestUser2"); try { - scope.Database.AsUmbracoDatabase().EnableSqlTrace = true; - scope.Database.AsUmbracoDatabase().EnableSqlCount = true; + ScopeAccessor.AmbientScope.Database.AsUmbracoDatabase().EnableSqlTrace = true; + ScopeAccessor.AmbientScope.Database.AsUmbracoDatabase().EnableSqlCount = true; // Act IEnumerable result = repository.GetPagedResultsByQuery( @@ -306,15 +307,15 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos user => user.Id, Direction.Ascending, excludeUserGroups: new[] { Constants.Security.TranslatorGroupAlias }, - filter: provider.SqlContext.Query().Where(x => x.Id > -1)); + filter: provider.CreateQuery().Where(x => x.Id > -1)); // Assert Assert.AreEqual(2, totalRecs); } finally { - scope.Database.AsUmbracoDatabase().EnableSqlTrace = false; - scope.Database.AsUmbracoDatabase().EnableSqlCount = false; + ScopeAccessor.AmbientScope.Database.AsUmbracoDatabase().EnableSqlTrace = false; + ScopeAccessor.AmbientScope.Database.AsUmbracoDatabase().EnableSqlCount = false; } } } @@ -331,8 +332,8 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos try { - scope.Database.AsUmbracoDatabase().EnableSqlTrace = true; - scope.Database.AsUmbracoDatabase().EnableSqlCount = true; + ScopeAccessor.AmbientScope.Database.AsUmbracoDatabase().EnableSqlTrace = true; + ScopeAccessor.AmbientScope.Database.AsUmbracoDatabase().EnableSqlCount = true; // Act IEnumerable result = repository.GetPagedResultsByQuery( @@ -344,15 +345,15 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos Direction.Ascending, includeUserGroups: new[] { Constants.Security.AdminGroupAlias, Constants.Security.SensitiveDataGroupAlias }, excludeUserGroups: new[] { Constants.Security.TranslatorGroupAlias }, - filter: provider.SqlContext.Query().Where(x => x.Id == -1)); + filter: provider.CreateQuery().Where(x => x.Id == -1)); // Assert Assert.AreEqual(1, totalRecs); } finally { - scope.Database.AsUmbracoDatabase().EnableSqlTrace = false; - scope.Database.AsUmbracoDatabase().EnableSqlCount = false; + ScopeAccessor.AmbientScope.Database.AsUmbracoDatabase().EnableSqlTrace = false; + ScopeAccessor.AmbientScope.Database.AsUmbracoDatabase().EnableSqlCount = false; } } } @@ -404,7 +405,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos Guid sessionId = repository.CreateLoginSession(user.Id, "1.2.3.4"); // manually update this record to be in the past - scope.Database.Execute(scope.SqlContext.Sql() + ScopeAccessor.AmbientScope.Database.Execute(ScopeAccessor.AmbientScope.SqlContext.Sql() .Update(u => u.Set(x => x.LoggedOutUtc, DateTime.UtcNow.AddDays(-100))) .Where(x => x.SessionId == sessionId)); diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/SchemaValidationTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/SchemaValidationTest.cs index 13f543c130..90f6fab9e1 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/SchemaValidationTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/SchemaValidationTest.cs @@ -1,4 +1,4 @@ -using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging; using NUnit.Framework; using Umbraco.Cms.Core.Configuration; using Umbraco.Cms.Core.Events; @@ -22,7 +22,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence using (var scope = ScopeProvider.CreateScope()) { - var schema = new DatabaseSchemaCreator(scope.Database, LoggerFactory.CreateLogger(), LoggerFactory, UmbracoVersion, EventAggregator); + var schema = new DatabaseSchemaCreator(ScopeAccessor.AmbientScope.Database, LoggerFactory.CreateLogger(), LoggerFactory, UmbracoVersion, EventAggregator); result = schema.ValidateSchema(DatabaseSchemaCreator.OrderedTables); } diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/SqlServerTableByTableTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/SqlServerTableByTableTest.cs index 4b3d159ff5..8c34202fe4 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/SqlServerTableByTableTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/SqlServerTableByTableTest.cs @@ -1,4 +1,4 @@ -using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using NUnit.Framework; using Umbraco.Cms.Core.Configuration; @@ -23,7 +23,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence { using (var scope = ScopeProvider.CreateScope()) { - var helper = new DatabaseSchemaCreator(scope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); + var helper = new DatabaseSchemaCreator(ScopeAccessor.AmbientScope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); helper.CreateTable(); @@ -36,7 +36,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence { using (var scope = ScopeProvider.CreateScope()) { - var helper = new DatabaseSchemaCreator(scope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); + var helper = new DatabaseSchemaCreator(ScopeAccessor.AmbientScope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); helper.CreateTable(); helper.CreateTable(); @@ -50,7 +50,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence { using (var scope = ScopeProvider.CreateScope()) { - var helper = new DatabaseSchemaCreator(scope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); + var helper = new DatabaseSchemaCreator(ScopeAccessor.AmbientScope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); helper.CreateTable(); helper.CreateTable(); @@ -65,7 +65,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence { using (var scope = ScopeProvider.CreateScope()) { - var helper = new DatabaseSchemaCreator(scope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); + var helper = new DatabaseSchemaCreator(ScopeAccessor.AmbientScope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); helper.CreateTable(); helper.CreateTable(); @@ -79,7 +79,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence { using (var scope = ScopeProvider.CreateScope()) { - var helper = new DatabaseSchemaCreator(scope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); + var helper = new DatabaseSchemaCreator(ScopeAccessor.AmbientScope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); helper.CreateTable(); helper.CreateTable(); @@ -94,7 +94,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence { using (var scope = ScopeProvider.CreateScope()) { - var helper = new DatabaseSchemaCreator(scope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); + var helper = new DatabaseSchemaCreator(ScopeAccessor.AmbientScope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); helper.CreateTable(); helper.CreateTable(); @@ -108,7 +108,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence { using (var scope = ScopeProvider.CreateScope()) { - var helper = new DatabaseSchemaCreator(scope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); + var helper = new DatabaseSchemaCreator(ScopeAccessor.AmbientScope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); helper.CreateTable(); helper.CreateTable(); @@ -124,7 +124,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence { using (var scope = ScopeProvider.CreateScope()) { - var helper = new DatabaseSchemaCreator(scope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); + var helper = new DatabaseSchemaCreator(ScopeAccessor.AmbientScope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); helper.CreateTable(); helper.CreateTable(); @@ -138,7 +138,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence { using (var scope = ScopeProvider.CreateScope()) { - var helper = new DatabaseSchemaCreator(scope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); + var helper = new DatabaseSchemaCreator(ScopeAccessor.AmbientScope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); helper.CreateTable(); @@ -151,7 +151,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence { using (var scope = ScopeProvider.CreateScope()) { - var helper = new DatabaseSchemaCreator(scope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); + var helper = new DatabaseSchemaCreator(ScopeAccessor.AmbientScope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); helper.CreateTable(); helper.CreateTable(); @@ -166,7 +166,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence { using (var scope = ScopeProvider.CreateScope()) { - var helper = new DatabaseSchemaCreator(scope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); + var helper = new DatabaseSchemaCreator(ScopeAccessor.AmbientScope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); helper.CreateTable(); helper.CreateTable(); @@ -180,7 +180,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence { using (var scope = ScopeProvider.CreateScope()) { - var helper = new DatabaseSchemaCreator(scope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); + var helper = new DatabaseSchemaCreator(ScopeAccessor.AmbientScope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); helper.CreateTable(); helper.CreateTable(); @@ -197,7 +197,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence { using (var scope = ScopeProvider.CreateScope()) { - var helper = new DatabaseSchemaCreator(scope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); + var helper = new DatabaseSchemaCreator(ScopeAccessor.AmbientScope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); helper.CreateTable(); helper.CreateTable(); @@ -213,7 +213,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence { using (var scope = ScopeProvider.CreateScope()) { - var helper = new DatabaseSchemaCreator(scope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); + var helper = new DatabaseSchemaCreator(ScopeAccessor.AmbientScope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); helper.CreateTable(); helper.CreateTable(); @@ -227,7 +227,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence { using (var scope = ScopeProvider.CreateScope()) { - var helper = new DatabaseSchemaCreator(scope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); + var helper = new DatabaseSchemaCreator(ScopeAccessor.AmbientScope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); helper.CreateTable(); @@ -240,7 +240,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence { using (var scope = ScopeProvider.CreateScope()) { - var helper = new DatabaseSchemaCreator(scope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); + var helper = new DatabaseSchemaCreator(ScopeAccessor.AmbientScope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); helper.CreateTable(); @@ -253,7 +253,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence { using (var scope = ScopeProvider.CreateScope()) { - var helper = new DatabaseSchemaCreator(scope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); + var helper = new DatabaseSchemaCreator(ScopeAccessor.AmbientScope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); helper.CreateTable(); @@ -266,7 +266,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence { using (var scope = ScopeProvider.CreateScope()) { - var helper = new DatabaseSchemaCreator(scope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); + var helper = new DatabaseSchemaCreator(ScopeAccessor.AmbientScope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); helper.CreateTable(); @@ -279,7 +279,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence { using (var scope = ScopeProvider.CreateScope()) { - var helper = new DatabaseSchemaCreator(scope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); + var helper = new DatabaseSchemaCreator(ScopeAccessor.AmbientScope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); helper.CreateTable(); helper.CreateTable(); @@ -295,7 +295,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence { using (var scope = ScopeProvider.CreateScope()) { - var helper = new DatabaseSchemaCreator(scope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); + var helper = new DatabaseSchemaCreator(ScopeAccessor.AmbientScope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); helper.CreateTable(); helper.CreateTable(); @@ -312,7 +312,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence { using (var scope = ScopeProvider.CreateScope()) { - var helper = new DatabaseSchemaCreator(scope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); + var helper = new DatabaseSchemaCreator(ScopeAccessor.AmbientScope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); helper.CreateTable(); helper.CreateTable(); @@ -327,7 +327,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence { using (var scope = ScopeProvider.CreateScope()) { - var helper = new DatabaseSchemaCreator(scope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); + var helper = new DatabaseSchemaCreator(ScopeAccessor.AmbientScope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); helper.CreateTable(); helper.CreateTable(); @@ -345,7 +345,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence { using (var scope = ScopeProvider.CreateScope()) { - var helper = new DatabaseSchemaCreator(scope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); + var helper = new DatabaseSchemaCreator(ScopeAccessor.AmbientScope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); helper.CreateTable(); helper.CreateTable(); @@ -362,7 +362,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence { using (var scope = ScopeProvider.CreateScope()) { - var helper = new DatabaseSchemaCreator(scope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); + var helper = new DatabaseSchemaCreator(ScopeAccessor.AmbientScope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); helper.CreateTable(); helper.CreateTable(); @@ -377,7 +377,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence { using (var scope = ScopeProvider.CreateScope()) { - var helper = new DatabaseSchemaCreator(scope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); + var helper = new DatabaseSchemaCreator(ScopeAccessor.AmbientScope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); helper.CreateTable(); helper.CreateTable(); @@ -392,7 +392,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence { using (var scope = ScopeProvider.CreateScope()) { - var helper = new DatabaseSchemaCreator(scope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); + var helper = new DatabaseSchemaCreator(ScopeAccessor.AmbientScope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); helper.CreateTable(); @@ -405,7 +405,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence { using (var scope = ScopeProvider.CreateScope()) { - var helper = new DatabaseSchemaCreator(scope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); + var helper = new DatabaseSchemaCreator(ScopeAccessor.AmbientScope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); helper.CreateTable(); @@ -418,7 +418,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence { using (var scope = ScopeProvider.CreateScope()) { - var helper = new DatabaseSchemaCreator(scope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); + var helper = new DatabaseSchemaCreator(ScopeAccessor.AmbientScope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); helper.CreateTable(); helper.CreateTable(); @@ -439,7 +439,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence { using (var scope = ScopeProvider.CreateScope()) { - var helper = new DatabaseSchemaCreator(scope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); + var helper = new DatabaseSchemaCreator(ScopeAccessor.AmbientScope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); helper.CreateTable(); @@ -452,7 +452,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence { using (var scope = ScopeProvider.CreateScope()) { - var helper = new DatabaseSchemaCreator(scope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); + var helper = new DatabaseSchemaCreator(ScopeAccessor.AmbientScope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); helper.CreateTable(); helper.CreateTable(); @@ -466,7 +466,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence { using (var scope = ScopeProvider.CreateScope()) { - var helper = new DatabaseSchemaCreator(scope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); + var helper = new DatabaseSchemaCreator(ScopeAccessor.AmbientScope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); helper.CreateTable(); helper.CreateTable(); @@ -480,7 +480,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence { using (var scope = ScopeProvider.CreateScope()) { - var helper = new DatabaseSchemaCreator(scope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); + var helper = new DatabaseSchemaCreator(ScopeAccessor.AmbientScope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); helper.CreateTable(); helper.CreateTable(); @@ -495,7 +495,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence { using (var scope = ScopeProvider.CreateScope()) { - var helper = new DatabaseSchemaCreator(scope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); + var helper = new DatabaseSchemaCreator(ScopeAccessor.AmbientScope.Database, _loggerFactory.CreateLogger(), _loggerFactory, UmbracoVersion, EventAggregator); helper.CreateTable(); helper.CreateTable(); diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Scoping/ScopeTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Scoping/ScopeTests.cs index 37a21cf9b4..bbb9ea8766 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Scoping/ScopeTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Scoping/ScopeTests.cs @@ -187,7 +187,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Scoping Assert.IsInstanceOf(scope); Assert.IsNotNull(scopeProvider.AmbientScope); Assert.AreSame(scope, scopeProvider.AmbientScope); - database = scope.Database; // populates scope's database + database = ScopeAccessor.AmbientScope.Database; // populates scope's database Assert.IsNotNull(database); Assert.IsNotNull(database.Connection); // in a transaction } @@ -360,7 +360,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Scoping Assert.IsInstanceOf(scope); Assert.IsNotNull(scopeProvider.AmbientScope); Assert.AreSame(scope, scopeProvider.AmbientScope); - database = scope.Database; // populates scope's database + database = ScopeAccessor.AmbientScope.Database; // populates scope's database Assert.IsNotNull(database); Assert.IsNotNull(database.Connection); // in a transaction using (IScope nested = scopeProvider.CreateScope()) @@ -369,7 +369,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Scoping Assert.IsNotNull(scopeProvider.AmbientScope); Assert.AreSame(nested, scopeProvider.AmbientScope); Assert.AreSame(scope, ((Scope)nested).ParentScope); - Assert.AreSame(database, nested.Database); + Assert.AreSame(database, ScopeAccessor.AmbientScope.Database); } Assert.IsNotNull(database.Connection); // still @@ -386,32 +386,32 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Scoping using (IScope scope = scopeProvider.CreateScope()) { - scope.Database.Execute("CREATE TABLE tmp3 (id INT, name NVARCHAR(64))"); + ScopeAccessor.AmbientScope.Database.Execute("CREATE TABLE tmp3 (id INT, name NVARCHAR(64))"); scope.Complete(); } using (IScope scope = scopeProvider.CreateScope()) { - scope.Database.Execute("INSERT INTO tmp3 (id, name) VALUES (1, 'a')"); - string n = scope.Database.ExecuteScalar("SELECT name FROM tmp3 WHERE id=1"); + ScopeAccessor.AmbientScope.Database.Execute("INSERT INTO tmp3 (id, name) VALUES (1, 'a')"); + string n = ScopeAccessor.AmbientScope.Database.ExecuteScalar("SELECT name FROM tmp3 WHERE id=1"); Assert.AreEqual("a", n); } using (IScope scope = scopeProvider.CreateScope()) { - string n = scope.Database.ExecuteScalar("SELECT name FROM tmp3 WHERE id=1"); + string n = ScopeAccessor.AmbientScope.Database.ExecuteScalar("SELECT name FROM tmp3 WHERE id=1"); Assert.IsNull(n); } using (IScope scope = scopeProvider.CreateScope()) { - scope.Database.Execute("INSERT INTO tmp3 (id, name) VALUES (1, 'a')"); + ScopeAccessor.AmbientScope.Database.Execute("INSERT INTO tmp3 (id, name) VALUES (1, 'a')"); scope.Complete(); } using (IScope scope = scopeProvider.CreateScope()) { - string n = scope.Database.ExecuteScalar("SELECT name FROM tmp3 WHERE id=1"); + string n = ScopeAccessor.AmbientScope.Database.ExecuteScalar("SELECT name FROM tmp3 WHERE id=1"); Assert.AreEqual("a", n); } } @@ -423,24 +423,24 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Scoping using (IScope scope = scopeProvider.CreateScope()) { - scope.Database.Execute($"CREATE TABLE tmp1 (id INT, name NVARCHAR(64))"); + ScopeAccessor.AmbientScope.Database.Execute($"CREATE TABLE tmp1 (id INT, name NVARCHAR(64))"); scope.Complete(); } using (IScope scope = scopeProvider.CreateScope()) { - scope.Database.Execute("INSERT INTO tmp1 (id, name) VALUES (1, 'a')"); - string n = scope.Database.ExecuteScalar("SELECT name FROM tmp1 WHERE id=1"); + ScopeAccessor.AmbientScope.Database.Execute("INSERT INTO tmp1 (id, name) VALUES (1, 'a')"); + string n = ScopeAccessor.AmbientScope.Database.ExecuteScalar("SELECT name FROM tmp1 WHERE id=1"); Assert.AreEqual("a", n); using (IScope nested = scopeProvider.CreateScope()) { - nested.Database.Execute("INSERT INTO tmp1 (id, name) VALUES (2, 'b')"); - string nn = nested.Database.ExecuteScalar("SELECT name FROM tmp1 WHERE id=2"); + ScopeAccessor.AmbientScope.Database.Execute("INSERT INTO tmp1 (id, name) VALUES (2, 'b')"); + string nn = ScopeAccessor.AmbientScope.Database.ExecuteScalar("SELECT name FROM tmp1 WHERE id=2"); Assert.AreEqual("b", nn); } - n = scope.Database.ExecuteScalar("SELECT name FROM tmp1 WHERE id=2"); + n = ScopeAccessor.AmbientScope.Database.ExecuteScalar("SELECT name FROM tmp1 WHERE id=2"); Assert.AreEqual("b", n); scope.Complete(); @@ -448,9 +448,9 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Scoping using (IScope scope = scopeProvider.CreateScope()) { - string n = scope.Database.ExecuteScalar("SELECT name FROM tmp1 WHERE id=1"); + string n = ScopeAccessor.AmbientScope.Database.ExecuteScalar("SELECT name FROM tmp1 WHERE id=1"); Assert.IsNull(n); - n = scope.Database.ExecuteScalar("SELECT name FROM tmp1 WHERE id=2"); + n = ScopeAccessor.AmbientScope.Database.ExecuteScalar("SELECT name FROM tmp1 WHERE id=2"); Assert.IsNull(n); } } @@ -462,33 +462,33 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Scoping using (IScope scope = scopeProvider.CreateScope()) { - scope.Database.Execute("CREATE TABLE tmp2 (id INT, name NVARCHAR(64))"); + ScopeAccessor.AmbientScope.Database.Execute("CREATE TABLE tmp2 (id INT, name NVARCHAR(64))"); scope.Complete(); } using (IScope scope = scopeProvider.CreateScope()) { - scope.Database.Execute("INSERT INTO tmp2 (id, name) VALUES (1, 'a')"); - string n = scope.Database.ExecuteScalar("SELECT name FROM tmp2 WHERE id=1"); + ScopeAccessor.AmbientScope.Database.Execute("INSERT INTO tmp2 (id, name) VALUES (1, 'a')"); + string n = ScopeAccessor.AmbientScope.Database.ExecuteScalar("SELECT name FROM tmp2 WHERE id=1"); Assert.AreEqual("a", n); using (IScope nested = scopeProvider.CreateScope()) { - nested.Database.Execute("INSERT INTO tmp2 (id, name) VALUES (2, 'b')"); - string nn = nested.Database.ExecuteScalar("SELECT name FROM tmp2 WHERE id=2"); + ScopeAccessor.AmbientScope.Database.Execute("INSERT INTO tmp2 (id, name) VALUES (2, 'b')"); + string nn = ScopeAccessor.AmbientScope.Database.ExecuteScalar("SELECT name FROM tmp2 WHERE id=2"); Assert.AreEqual("b", nn); nested.Complete(); } - n = scope.Database.ExecuteScalar("SELECT name FROM tmp2 WHERE id=2"); + n = ScopeAccessor.AmbientScope.Database.ExecuteScalar("SELECT name FROM tmp2 WHERE id=2"); Assert.AreEqual("b", n); } using (IScope scope = scopeProvider.CreateScope()) { - string n = scope.Database.ExecuteScalar("SELECT name FROM tmp2 WHERE id=1"); + string n = ScopeAccessor.AmbientScope.Database.ExecuteScalar("SELECT name FROM tmp2 WHERE id=1"); Assert.IsNull(n); - n = scope.Database.ExecuteScalar("SELECT name FROM tmp2 WHERE id=2"); + n = ScopeAccessor.AmbientScope.Database.ExecuteScalar("SELECT name FROM tmp2 WHERE id=2"); Assert.IsNull(n); } } @@ -500,34 +500,34 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Scoping using (IScope scope = scopeProvider.CreateScope()) { - scope.Database.Execute("CREATE TABLE tmp (id INT, name NVARCHAR(64))"); + ScopeAccessor.AmbientScope.Database.Execute("CREATE TABLE tmp (id INT, name NVARCHAR(64))"); scope.Complete(); } using (IScope scope = scopeProvider.CreateScope()) { - scope.Database.Execute("INSERT INTO tmp (id, name) VALUES (1, 'a')"); - string n = scope.Database.ExecuteScalar("SELECT name FROM tmp WHERE id=1"); + ScopeAccessor.AmbientScope.Database.Execute("INSERT INTO tmp (id, name) VALUES (1, 'a')"); + string n = ScopeAccessor.AmbientScope.Database.ExecuteScalar("SELECT name FROM tmp WHERE id=1"); Assert.AreEqual("a", n); using (IScope nested = scopeProvider.CreateScope()) { - nested.Database.Execute("INSERT INTO tmp (id, name) VALUES (2, 'b')"); - string nn = nested.Database.ExecuteScalar("SELECT name FROM tmp WHERE id=2"); + ScopeAccessor.AmbientScope.Database.Execute("INSERT INTO tmp (id, name) VALUES (2, 'b')"); + string nn = ScopeAccessor.AmbientScope.Database.ExecuteScalar("SELECT name FROM tmp WHERE id=2"); Assert.AreEqual("b", nn); nested.Complete(); } - n = scope.Database.ExecuteScalar("SELECT name FROM tmp WHERE id=2"); + n = ScopeAccessor.AmbientScope.Database.ExecuteScalar("SELECT name FROM tmp WHERE id=2"); Assert.AreEqual("b", n); scope.Complete(); } using (IScope scope = scopeProvider.CreateScope()) { - string n = scope.Database.ExecuteScalar("SELECT name FROM tmp WHERE id=1"); + string n = ScopeAccessor.AmbientScope.Database.ExecuteScalar("SELECT name FROM tmp WHERE id=1"); Assert.AreEqual("a", n); - n = scope.Database.ExecuteScalar("SELECT name FROM tmp WHERE id=2"); + n = ScopeAccessor.AmbientScope.Database.ExecuteScalar("SELECT name FROM tmp WHERE id=2"); Assert.AreEqual("b", n); } } @@ -615,13 +615,17 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Scoping public void ScopeReference() { ScopeProvider scopeProvider = ScopeProvider; - IScope scope = scopeProvider.CreateScope(); - IScope nested = scopeProvider.CreateScope(); + Scope scope = (Scope) scopeProvider.CreateScope(); + Scope nested = (Scope) scopeProvider.CreateScope(); + Assert.IsNotNull(scopeProvider.AmbientScope); + var scopeRef = new HttpScopeReference(scopeProvider); scopeRef.Register(); scopeRef.Dispose(); + Assert.IsNull(scopeProvider.AmbientScope); + Assert.Throws(() => { IUmbracoDatabase db = scope.Database; diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/CacheInstructionServiceTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/CacheInstructionServiceTests.cs index bce214eada..80005f8058 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/CacheInstructionServiceTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/CacheInstructionServiceTests.cs @@ -142,7 +142,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services .From(); using (IScope scope = ScopeProvider.CreateScope()) { - cacheInstructions = scope.Database.Fetch(sql); + cacheInstructions = ScopeAccessor.AmbientScope.Database.Fetch(sql); scope.Complete(); } diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServiceTagsTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServiceTagsTests.cs index 32883138c2..c082d93946 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServiceTagsTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServiceTagsTests.cs @@ -624,15 +624,15 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services using (IScope scope = ScopeProvider.CreateScope()) { - Assert.AreEqual(4, scope.Database.ExecuteScalar( + Assert.AreEqual(4, ScopeAccessor.AmbientScope.Database.ExecuteScalar( "SELECT COUNT(*) FROM cmsTagRelationship WHERE nodeId=@nodeId AND propertyTypeId=@propTypeId", new { nodeId = content.Id, propTypeId = propertyTypeId })); - Assert.AreEqual(3, scope.Database.ExecuteScalar( + Assert.AreEqual(3, ScopeAccessor.AmbientScope.Database.ExecuteScalar( "SELECT COUNT(*) FROM cmsTagRelationship WHERE nodeId=@nodeId AND propertyTypeId=@propTypeId", new { nodeId = child1.Id, propTypeId = propertyTypeId })); - Assert.AreEqual(2, scope.Database.ExecuteScalar( + Assert.AreEqual(2, ScopeAccessor.AmbientScope.Database.ExecuteScalar( "SELECT COUNT(*) FROM cmsTagRelationship WHERE nodeId=@nodeId AND propertyTypeId=@propTypeId", new { nodeId = child2.Id, propTypeId = propertyTypeId })); @@ -667,7 +667,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services int propertyTypeId = contentType.PropertyTypes.Single(x => x.Alias == "tags").Id; using (IScope scope = ScopeProvider.CreateScope()) { - Assert.AreEqual(4, scope.Database.ExecuteScalar( + Assert.AreEqual(4, ScopeAccessor.AmbientScope.Database.ExecuteScalar( "SELECT COUNT(*) FROM cmsTagRelationship WHERE nodeId=@nodeId AND propertyTypeId=@propTypeId", new { nodeId = content.Id, propTypeId = propertyTypeId })); scope.Complete(); @@ -696,7 +696,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services int propertyTypeId = contentType.PropertyTypes.Single(x => x.Alias == "tags").Id; using (IScope scope = ScopeProvider.CreateScope()) { - Assert.AreEqual(4, scope.Database.ExecuteScalar( + Assert.AreEqual(4, ScopeAccessor.AmbientScope.Database.ExecuteScalar( "SELECT COUNT(*) FROM cmsTagRelationship WHERE nodeId=@nodeId AND propertyTypeId=@propTypeId", new { nodeId = content.Id, propTypeId = propertyTypeId })); @@ -727,7 +727,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services int propertyTypeId = contentType.PropertyTypes.Single(x => x.Alias == "tags").Id; using (IScope scope = ScopeProvider.CreateScope()) { - Assert.AreEqual(5, scope.Database.ExecuteScalar( + Assert.AreEqual(5, ScopeAccessor.AmbientScope.Database.ExecuteScalar( "SELECT COUNT(*) FROM cmsTagRelationship WHERE nodeId=@nodeId AND propertyTypeId=@propTypeId", new { nodeId = content.Id, propTypeId = propertyTypeId })); @@ -758,7 +758,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services int propertyTypeId = contentType.PropertyTypes.Single(x => x.Alias == "tags").Id; using (IScope scope = ScopeProvider.CreateScope()) { - Assert.AreEqual(2, scope.Database.ExecuteScalar( + Assert.AreEqual(2, ScopeAccessor.AmbientScope.Database.ExecuteScalar( "SELECT COUNT(*) FROM cmsTagRelationship WHERE nodeId=@nodeId AND propertyTypeId=@propTypeId", new { nodeId = content.Id, propTypeId = propertyTypeId })); diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentTypeServiceVariantsTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentTypeServiceVariantsTests.cs index 04617ae5f3..985aed0597 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentTypeServiceVariantsTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentTypeServiceVariantsTests.cs @@ -75,7 +75,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) { Sql selectJson = SqlContext.Sql().Select().From().Where(x => x.NodeId == id && !x.Published); - ContentNuDto dto = scope.Database.Fetch(selectJson).FirstOrDefault(); + ContentNuDto dto = ScopeAccessor.AmbientScope.Database.Fetch(selectJson).FirstOrDefault(); Assert.IsNotNull(dto); string json = dto.Data; return json; diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentVersionCleanupServiceTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentVersionCleanupServiceTest.cs index 08200a6f7e..97a5698ef0 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentVersionCleanupServiceTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentVersionCleanupServiceTest.cs @@ -77,9 +77,9 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) { // SQL CE is fun! - var contentVersions = scope.Database.Single(@"select count(1) from umbracoContentVersion"); - var documentVersions = scope.Database.Single(@"select count(1) from umbracoDocumentVersion"); - var propertyData = scope.Database.Single(@"select count(1) from umbracoPropertyData"); + var contentVersions = ScopeAccessor.AmbientScope.Database.Single(@"select count(1) from umbracoContentVersion"); + var documentVersions = ScopeAccessor.AmbientScope.Database.Single(@"select count(1) from umbracoDocumentVersion"); + var propertyData = ScopeAccessor.AmbientScope.Database.Single(@"select count(1) from umbracoPropertyData"); return new Report { @@ -103,7 +103,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services Updated = DateTime.Today }; - scope.Database.Insert(entity); + ScopeAccessor.AmbientScope.Database.Insert(entity); } } diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ExternalLoginServiceTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ExternalLoginServiceTests.cs index b4f6c1ae5f..09870a08e1 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ExternalLoginServiceTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ExternalLoginServiceTests.cs @@ -36,14 +36,14 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services using (global::Umbraco.Cms.Core.Scoping.IScope scope = ScopeProvider.CreateScope()) { // insert duplicates manuall - scope.Database.Insert(new ExternalLoginDto + ScopeAccessor.AmbientScope.Database.Insert(new ExternalLoginDto { UserId = user.Id, LoginProvider = "test1", ProviderKey = providerKey, CreateDate = latest }); - scope.Database.Insert(new ExternalLoginDto + ScopeAccessor.AmbientScope.Database.Insert(new ExternalLoginDto { UserId = user.Id, LoginProvider = "test1", diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/LocalizationServiceTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/LocalizationServiceTests.cs index dee9ec819e..aca0ee4183 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/LocalizationServiceTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/LocalizationServiceTests.cs @@ -142,17 +142,17 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services currParentId = desc1.Key; } - scope.Database.AsUmbracoDatabase().EnableSqlTrace = true; - scope.Database.AsUmbracoDatabase().EnableSqlCount = true; + ScopeAccessor.AmbientScope.Database.AsUmbracoDatabase().EnableSqlTrace = true; + ScopeAccessor.AmbientScope.Database.AsUmbracoDatabase().EnableSqlCount = true; IDictionaryItem[] items = LocalizationService.GetDictionaryItemDescendants(_parentItemGuidId).ToArray(); - Debug.WriteLine("SQL CALLS: " + scope.Database.AsUmbracoDatabase().SqlCount); + Debug.WriteLine("SQL CALLS: " + ScopeAccessor.AmbientScope.Database.AsUmbracoDatabase().SqlCount); Assert.AreEqual(51, items.Length); // There's a call or two to get languages, so apart from that there should only be one call per level. - Assert.Less(scope.Database.AsUmbracoDatabase().SqlCount, 30); + Assert.Less(ScopeAccessor.AmbientScope.Database.AsUmbracoDatabase().SqlCount, 30); } } diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/MacroServiceTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/MacroServiceTests.cs index 75dae7515b..1f847356a1 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/MacroServiceTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/MacroServiceTests.cs @@ -13,6 +13,7 @@ using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Core.Services; using Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Cms.Tests.Common.Builders; using Umbraco.Cms.Tests.Common.Builders.Extensions; using Umbraco.Cms.Tests.Common.Testing; diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/MediaServiceTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/MediaServiceTests.cs index 786a665509..16b9430ff7 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/MediaServiceTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/MediaServiceTests.cs @@ -109,7 +109,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services 0, 11, out long total, - provider.SqlContext.Query() + provider.CreateQuery() .Where(x => new[] { mediaType1.Id, mediaType2.Id }.Contains(x.ContentTypeId)), Ordering.By("SortOrder", Direction.Ascending)); Assert.AreEqual(11, result.Count()); @@ -120,7 +120,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services 1, 11, out total, - provider.SqlContext.Query() + provider.CreateQuery() .Where(x => new[] { mediaType1.Id, mediaType2.Id }.Contains(x.ContentTypeId)), Ordering.By("SortOrder", Direction.Ascending)); Assert.AreEqual(9, result.Count()); diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/MemberServiceTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/MemberServiceTests.cs index 96a91af10f..2fe543c1e2 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/MemberServiceTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/MemberServiceTests.cs @@ -333,7 +333,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services int roleId; using (IScope scope = ScopeProvider.CreateScope()) { - roleId = scope.Database.ExecuteScalar("SELECT id from umbracoNode where [text] = 'MyTestRole1'"); + roleId = ScopeAccessor.AmbientScope.Database.ExecuteScalar("SELECT id from umbracoNode where [text] = 'MyTestRole1'"); scope.Complete(); } @@ -346,8 +346,8 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services using (IScope scope = ScopeProvider.CreateScope()) { - scope.Database.Insert(new Member2MemberGroupDto { MemberGroup = roleId, Member = member1.Id }); - scope.Database.Insert(new Member2MemberGroupDto { MemberGroup = roleId, Member = member2.Id }); + ScopeAccessor.AmbientScope.Database.Insert(new Member2MemberGroupDto { MemberGroup = roleId, Member = member1.Id }); + ScopeAccessor.AmbientScope.Database.Insert(new Member2MemberGroupDto { MemberGroup = roleId, Member = member2.Id }); scope.Complete(); } @@ -1281,7 +1281,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services List colResult; using (IScope scope = ScopeProvider.CreateScope()) { - colResult = scope.Database.Fetch(sql); + colResult = ScopeAccessor.AmbientScope.Database.Fetch(sql); scope.Complete(); } diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/RedirectUrlServiceTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/RedirectUrlServiceTests.cs index 1c10f31e18..a0abfd70ee 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/RedirectUrlServiceTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/RedirectUrlServiceTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Umbraco. +// Copyright (c) Umbraco. // See LICENSE for more details. using System.Linq; @@ -11,6 +11,7 @@ using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Core.Services; using Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ThreadSafetyServiceTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ThreadSafetyServiceTest.cs index 9eded84598..7611bea687 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ThreadSafetyServiceTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ThreadSafetyServiceTest.cs @@ -54,7 +54,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services { using (IScope scope = ScopeProvider.CreateScope()) { - scope.Database.Execute("SET LOCK_TIMEOUT 60000"); + ScopeAccessor.AmbientScope.Database.Execute("SET LOCK_TIMEOUT 60000"); service.Save(content); scope.Complete(); } @@ -64,7 +64,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services { using (IScope scope = ScopeProvider.CreateScope()) { - scope.Database.Execute("SET LOCK_TIMEOUT 60000"); + ScopeAccessor.AmbientScope.Database.Execute("SET LOCK_TIMEOUT 60000"); service.Save(media); scope.Complete(); } diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Cache/DefaultCachePolicyTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Cache/DefaultCachePolicyTests.cs index 2caa33aa3f..85e1c9a221 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Cache/DefaultCachePolicyTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Cache/DefaultCachePolicyTests.cs @@ -8,6 +8,7 @@ using NUnit.Framework; using Umbraco.Cms.Core.Cache; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Scoping; +using Umbraco.Cms.Infrastructure.Scoping; namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Cache { @@ -19,7 +20,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Cache get { var accessor = new Mock(); - var scope = new Mock(); + var scope = new Mock(); scope.Setup(x => x.RepositoryCacheMode).Returns(RepositoryCacheMode.Default); accessor.Setup(x => x.AmbientScope).Returns(scope.Object); return accessor.Object; diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Cache/FullDataSetCachePolicyTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Cache/FullDataSetCachePolicyTests.cs index d4b91a196f..578e133a16 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Cache/FullDataSetCachePolicyTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Cache/FullDataSetCachePolicyTests.cs @@ -11,6 +11,7 @@ using Umbraco.Cms.Core.Cache; using Umbraco.Cms.Core.Collections; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Scoping; +using Umbraco.Cms.Infrastructure.Scoping; namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Cache { @@ -22,7 +23,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Cache get { var accessor = new Mock(); - var scope = new Mock(); + var scope = new Mock(); scope.Setup(x => x.RepositoryCacheMode).Returns(RepositoryCacheMode.Default); accessor.Setup(x => x.AmbientScope).Returns(scope.Object); return accessor.Object; diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Cache/SingleItemsOnlyCachePolicyTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Cache/SingleItemsOnlyCachePolicyTests.cs index 4696dc708c..20c6d173c2 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Cache/SingleItemsOnlyCachePolicyTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Cache/SingleItemsOnlyCachePolicyTests.cs @@ -8,6 +8,7 @@ using NUnit.Framework; using Umbraco.Cms.Core.Cache; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Scoping; +using Umbraco.Cms.Infrastructure.Scoping; namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Cache { @@ -19,7 +20,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Cache get { var accessor = new Mock(); - var scope = new Mock(); + var scope = new Mock(); scope.Setup(x => x.RepositoryCacheMode).Returns(RepositoryCacheMode.Default); accessor.Setup(x => x.AmbientScope).Returns(scope.Object); return accessor.Object; diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Migrations/MigrationPlanTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Migrations/MigrationPlanTests.cs index 08bcee255e..2e1ac83cd8 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Migrations/MigrationPlanTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Migrations/MigrationPlanTests.cs @@ -19,6 +19,7 @@ using Umbraco.Cms.Infrastructure.Migrations; using Umbraco.Cms.Infrastructure.Migrations.Upgrade; using Umbraco.Cms.Infrastructure.Persistence; using Umbraco.Cms.Infrastructure.Persistence.SqlSyntax; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Cms.Tests.Common.TestHelpers; using Umbraco.Cms.Tests.UnitTests.TestHelpers; using Umbraco.Extensions; @@ -34,7 +35,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.Migrations NullLoggerFactory loggerFactory = NullLoggerFactory.Instance; var database = new TestDatabase(); - IScope scope = Mock.Of(x => x.Notifications == Mock.Of()); + IDatabaseScope scope = Mock.Of(x => x.Notifications == Mock.Of()); Mock.Get(scope) .Setup(x => x.Database) .Returns(database); @@ -58,7 +59,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.Migrations } }); - var executor = new MigrationPlanExecutor(scopeProvider, loggerFactory, migrationBuilder); + var executor = new MigrationPlanExecutor(scopeProvider, scopeProvider, loggerFactory, migrationBuilder); MigrationPlan plan = new MigrationPlan("default") .From(string.Empty) diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Migrations/MigrationTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Migrations/MigrationTests.cs index 7dd2b8be2b..2f2e36221c 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Migrations/MigrationTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Migrations/MigrationTests.cs @@ -10,20 +10,22 @@ using Microsoft.Extensions.Logging; using Moq; using NUnit.Framework; using Umbraco.Cms.Core.Events; +using Umbraco.Cms.Core.Persistence.Querying; using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Infrastructure.Migrations; using Umbraco.Cms.Infrastructure.Persistence; +using Umbraco.Cms.Infrastructure.Scoping; namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.Migrations { [TestFixture] public class MigrationTests { - public class TestScopeProvider : IScopeProvider + public class TestScopeProvider : IScopeProvider, IScopeAccessor { - private readonly IScope _scope; + private readonly IDatabaseScope _scope; - public TestScopeProvider(IScope scope) => _scope = scope; + public TestScopeProvider(IDatabaseScope scope) => _scope = scope; public IScope CreateScope( IsolationLevel isolationLevel = IsolationLevel.Unspecified, @@ -44,6 +46,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.Migrations public IScope DetachScope() => throw new NotImplementedException(); public IScopeContext Context { get; set; } + public IQuery CreateQuery() => SqlContext.Query(); public ISqlContext SqlContext { get; set; } @@ -54,6 +57,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.Migrations } public IEnumerable ScopeInfos => throw new NotImplementedException(); #endif + public IDatabaseScope AmbientScope => _scope; } private class TestPlan : MigrationPlan diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Migrations/PostMigrationTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Migrations/PostMigrationTests.cs index a61de49ee5..09d0cb99d1 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Migrations/PostMigrationTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Migrations/PostMigrationTests.cs @@ -18,6 +18,7 @@ using Umbraco.Cms.Infrastructure.Migrations; using Umbraco.Cms.Infrastructure.Migrations.Upgrade; using Umbraco.Cms.Infrastructure.Persistence; using Umbraco.Cms.Infrastructure.Persistence.SqlSyntax; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Cms.Tests.Common.TestHelpers; namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.Migrations @@ -26,8 +27,8 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.Migrations public class PostMigrationTests { private static readonly ILoggerFactory s_loggerFactory = NullLoggerFactory.Instance; - private IMigrationPlanExecutor GetMigrationPlanExecutor(IScopeProvider scopeProvider, IMigrationBuilder builder) - => new MigrationPlanExecutor(scopeProvider, s_loggerFactory, builder); + private IMigrationPlanExecutor GetMigrationPlanExecutor(IScopeProvider scopeProvider, IScopeAccessor scopeAccessor,IMigrationBuilder builder) + => new MigrationPlanExecutor(scopeProvider, scopeAccessor, s_loggerFactory, builder); [Test] public void ExecutesPlanPostMigration() @@ -49,7 +50,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.Migrations }); var database = new TestDatabase(); - IScope scope = Mock.Of(x => x.Notifications == Mock.Of()); + IDatabaseScope scope = Mock.Of(x => x.Notifications == Mock.Of()); Mock.Get(scope) .Setup(x => x.Database) .Returns(database); @@ -67,7 +68,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.Migrations TestPostMigration.MigrateCount = 0; var upgrader = new Upgrader(plan); - IMigrationPlanExecutor executor = GetMigrationPlanExecutor(scopeProvider, builder); + IMigrationPlanExecutor executor = GetMigrationPlanExecutor(scopeProvider, scopeProvider, builder); upgrader.Execute( executor, scopeProvider, @@ -98,7 +99,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.Migrations }); var database = new TestDatabase(); - IScope scope = Mock.Of(x => x.Notifications == Mock.Of()); + IDatabaseScope scope = Mock.Of(x => x.Notifications == Mock.Of()); Mock.Get(scope) .Setup(x => x.Database) .Returns(database); @@ -118,7 +119,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.Migrations new MigrationContext(plan, database, s_loggerFactory.CreateLogger()); var upgrader = new Upgrader(plan); - IMigrationPlanExecutor executor = GetMigrationPlanExecutor(scopeProvider, builder); + IMigrationPlanExecutor executor = GetMigrationPlanExecutor(scopeProvider, scopeProvider, builder); upgrader.Execute( executor, scopeProvider,