-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
133 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/Our.Umbraco.InvisibleNodes.Tests.Integration/Tests/IntegrationTestBase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright 2023 Luke Fisher | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
using System; | ||
using System.Net.Http; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Our.Umbraco.InvisibleNodes.Tests.Integration.Core; | ||
using Umbraco.Cms.Core; | ||
using Umbraco.Cms.Core.Routing; | ||
using Umbraco.Cms.Core.Services; | ||
using Umbraco.Cms.Core.Web; | ||
|
||
namespace Our.Umbraco.InvisibleNodes.Tests.Integration.Tests; | ||
|
||
public abstract class IntegrationTestBase(TestWebApplicationFactory factory) : IDisposable | ||
{ | ||
private IContentService? _contentService; | ||
private IDomainService? _domainService; | ||
private ILocalizationService? _localizationService; | ||
|
||
protected IServiceProvider Services => factory.Services; | ||
|
||
protected HttpClient HttpClient => factory.CreateClient(); | ||
|
||
protected IContentService ContentService => | ||
_contentService ??= Services.GetRequiredService<IContentService>(); | ||
|
||
protected IDomainService DomainService => | ||
_domainService ??= Services.GetRequiredService<IDomainService>(); | ||
|
||
protected ILocalizationService LocalizationService => | ||
_localizationService ??= Services.GetRequiredService<ILocalizationService>(); | ||
|
||
protected IPublishedUrlProvider PublishedUrlProvider => Services.GetRequiredService<IPublishedUrlProvider>(); | ||
|
||
private UmbracoContextReference UmbracoContextReference => Services | ||
.GetRequiredService<IUmbracoContextFactory>() | ||
.EnsureUmbracoContext(); | ||
|
||
protected IUmbracoContext UmbracoContext => UmbracoContextReference.UmbracoContext; | ||
|
||
public void Dispose() | ||
{ | ||
// Cleanup content if used | ||
if (_contentService is not null) | ||
foreach (var content in _contentService.GetRootContent()) | ||
_contentService.Delete(content); | ||
|
||
// Cleanup domains if used | ||
if (_domainService is not null) | ||
foreach (var content in _domainService.GetAll(true)) | ||
_domainService.Delete(content); | ||
} | ||
} |
Oops, something went wrong.