Files
Umbraco-CMS/tests/Umbraco.Tests/Routing/UrlRoutingTestBase.cs
Paul Johnson 00133e880d Move test projects from src/ to tests/ (#11357)
* Update gitignore

* Move csproj

* Update project references

* Update solutions

* Update build scripts

* Tests used to share editorconfig with projects in src

* Fix broken tests.

* Stop copying around .editorconfig

merged root one with linting

* csharp_style_expression_bodied -> suggestion

* Move StyleCop rulesets to matching directories and update shared build properties

* Remove legacy build files, update NuGet.cofig and solution files

* Restore myget source

* Clean up .gitignore

* Update .gitignore

* Move new test classes to tests after merge

* Gitignore + nuget config

* Move new test

Co-authored-by: Ronald Barendse <ronald@barend.se>
2021-10-18 08:14:04 +01:00

66 lines
2.6 KiB
C#

using System.Collections.Generic;
using System.Linq;
using Moq;
using NUnit.Framework;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Tests.Common.Testing;
using Umbraco.Extensions;
using Umbraco.Tests.TestHelpers;
using Umbraco.Tests.Testing;
namespace Umbraco.Tests.Routing
{
[TestFixture]
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerFixture)]
public abstract class UrlRoutingTestBase : BaseWebTest
{
/// <summary>
/// Sets up the mock domain service
/// </summary>
/// <param name="allDomains"></param>
protected IDomainService SetupDomainServiceMock(IEnumerable<IDomain> allDomains)
{
var domainService = Mock.Get(ServiceContext.DomainService);
//setup mock domain service
domainService.Setup(service => service.GetAll(It.IsAny<bool>()))
.Returns((bool incWildcards) => incWildcards ? allDomains : allDomains.Where(d => d.IsWildcard == false));
domainService.Setup(service => service.GetAssignedDomains(It.IsAny<int>(), It.IsAny<bool>()))
.Returns((int id, bool incWildcards) => allDomains.Where(d => d.RootContentId == id && (incWildcards || d.IsWildcard == false)));
return domainService.Object;
}
protected override void Compose()
{
base.Compose();
Builder.Services.AddUnique(GetServiceContext());
}
protected ServiceContext GetServiceContext()
{
// get the mocked service context to get the mocked domain service
var serviceContext = TestObjects.GetServiceContextMock(Factory);
//setup mock domain service
var domainService = Mock.Get(serviceContext.DomainService);
domainService.Setup(service => service.GetAll(It.IsAny<bool>()))
.Returns((bool incWildcards) => new[]
{
new UmbracoDomain("domain1.com/"){Id = 1, LanguageId = LangDeId, RootContentId = 1001, LanguageIsoCode = "de-DE"},
new UmbracoDomain("domain1.com/en"){Id = 1, LanguageId = LangEngId, RootContentId = 10011, LanguageIsoCode = "en-US"},
new UmbracoDomain("domain1.com/fr"){Id = 1, LanguageId = LangFrId, RootContentId = 10012, LanguageIsoCode = "fr-FR"}
});
return serviceContext;
}
public const int LangDeId = 333;
public const int LangEngId = 334;
public const int LangFrId = 335;
public const int LangCzId = 336;
public const int LangNlId = 337;
public const int LangDkId = 338;
}
}