-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
227: Fix global regex redirect (#242)
- Loading branch information
1 parent
ca1e828
commit b37e81b
Showing
5 changed files
with
87 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using Moq; | ||
using SeoToolkit.Umbraco.Redirects.Core.Interfaces; | ||
using SeoToolkit.Umbraco.Redirects.Core.Models.Business; | ||
using SeoToolkit.Umbraco.Redirects.Core.Services; | ||
using Umbraco.Cms.Core; | ||
using Umbraco.Cms.Core.PublishedCache; | ||
using Umbraco.Cms.Core.Routing; | ||
using Umbraco.Cms.Core.Web; | ||
|
||
namespace SeoToolkit.Tests | ||
{ | ||
[TestFixture] | ||
public class RedirectTests | ||
{ | ||
[Test] | ||
public void TestRegexAllSitesRedirect() | ||
{ | ||
// Arrange | ||
var redirectId = 1; | ||
var redirectRepository = new Mock<IRedirectsRepository>(); | ||
redirectRepository.Setup(it => it.GetAllRegexRedirects()).Returns(() => new Redirect[] | ||
{ | ||
new Redirect { Domain = null, IsRegex = true, Id = redirectId, OldUrl = "^/test" } | ||
}); | ||
|
||
var umbracoContextFactory = GetContextFactoryWithDomain(); | ||
var redirectService = new RedirectsService(redirectRepository.Object, umbracoContextFactory); | ||
|
||
// Act | ||
var redirect = redirectService.GetByUrl(new Uri("https://test.nl/test123")); | ||
|
||
// Assert | ||
Assert.IsNotNull(redirect); | ||
} | ||
|
||
private IUmbracoContextFactory GetContextFactoryWithDomain() | ||
{ | ||
var umbracoContextFactory = new Mock<IUmbracoContextFactory>(); | ||
var umbracoContext = new Mock<IUmbracoContext>(); | ||
var domainCache = new Mock<IDomainCache>(); | ||
|
||
domainCache.Setup(it => it.GetAll(false)).Returns(Enumerable.Empty<Domain>); | ||
umbracoContext.Setup(it => it.Domains).Returns(() => domainCache.Object); | ||
umbracoContextFactory.Setup(it => it.EnsureUmbracoContext()).Returns(() => new UmbracoContextReference(umbracoContext.Object, true, Mock.Of<IUmbracoContextAccessor>())); | ||
|
||
return umbracoContextFactory.Object; | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/SeoToolkit.Tests/SeoToolkit.Tests/SeoToolkit.Tests.csproj
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,24 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" /> | ||
<PackageReference Include="Moq" Version="4.20.69" /> | ||
<PackageReference Include="NUnit" Version="3.13.3" /> | ||
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" /> | ||
<PackageReference Include="NUnit.Analyzers" Version="3.3.0" /> | ||
<PackageReference Include="coverlet.collector" Version="3.1.2" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\SeoToolkit.Umbraco\SeoToolkit.Umbraco.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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 @@ | ||
global using NUnit.Framework; |
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
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