Files
Umbraco-CMS/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Routing/ContentFinderByAliasWithDomainsTests.cs
Shannon Deminick c77dc5dc00 Migrating tests that depend on Published Cache from the old test project (#11242)
* starts cleaning up old test project, removing ones we'll never convert, moves new test to where it should be.

* Makes ContentNodeKit immutable properties, moves first nucache tests over

* Gets the Nucache unit tests working and refactors a bit to use builder pattern for models.

* Migrates first xml based cache test to use nucache.

* Migrates a bunch more

* Migrates remaining tests for PublishedContentTests

* Moves PublishedRouterTests

* Moves PublishedContentExtensionTests

* Moves more tests.

* committing wip

* committing wip

* Gets PublishedContentLanguageVariantTests converted and working.

* Fixes DataTable ext method and moves PublishedContentDataTableTests

* Moves PublishedMediaTests

* wip - moving EntityXmlSerializerTests

* Moves more tests

* moves more tests

* moves more tests

* Move another test

* Moves more tests

* Fix test

* move another test

* Moves more tests

* Moves more tests

* Moves more tests

* wip before merge

* More tests

* More tests

* More tests

* More tests

* More tests

* More tests

* Cleanup and moving classes.

* Remove unused code

* Fixed failing tests, due to new null checks, that did not exist in v8

* Avoid breaking changes

* Unbreak more things, even that it the old solution was crazy..

* Fixed bug where ordering of stream readings was changed..

* cleanup

Co-authored-by: Bjarke Berg <mail@bergmania.dk>
2021-10-19 14:11:54 +02:00

66 lines
2.8 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Moq;
using NUnit.Framework;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Models.PublishedContent;
using Umbraco.Cms.Core.PropertyEditors;
using Umbraco.Cms.Core.Routing;
using Umbraco.Cms.Infrastructure.PublishedCache;
using Umbraco.Cms.Tests.Common.Published;
using Umbraco.Cms.Tests.UnitTests.TestHelpers;
using Umbraco.Extensions;
using Constants = Umbraco.Cms.Core.Constants;
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Routing
{
[TestFixture]
public class ContentFinderByAliasWithDomainsTests : UrlRoutingTestBase
{
[TestCase("http://domain1.com/this/is/my/alias", "de-DE", -1001)] // alias to domain's page fails - no alias on domain's home
[TestCase("http://domain1.com/page2/alias", "de-DE", 10011)] // alias to sub-page works
[TestCase("http://domain1.com/en/flux", "en-US", -10011)] // alias to domain's page fails - no alias on domain's home
[TestCase("http://domain1.com/endanger", "de-DE", 10011)] // alias to sub-page works, even with "en..."
[TestCase("http://domain1.com/en/endanger", "en-US", -10011)] // no
[TestCase("http://domain1.com/only/one/alias", "de-DE", 100111)] // ok
[TestCase("http://domain1.com/entropy", "de-DE", 100111)] // ok
[TestCase("http://domain1.com/bar/foo", "de-DE", 100111)] // ok
[TestCase("http://domain1.com/en/bar/foo", "en-US", -100111)] // no, alias must include "en/"
[TestCase("http://domain1.com/en/bar/nil", "en-US", 100111)] // ok, alias includes "en/"
public async Task Lookup_By_Url_Alias_And_Domain(string inputUrl, string expectedCulture, int expectedNode)
{
//SetDomains1();
var umbracoContextAccessor = GetUmbracoContextAccessor(inputUrl);
var publishedRouter = CreatePublishedRouter(umbracoContextAccessor);
var umbracoContext = umbracoContextAccessor.GetRequiredUmbracoContext();
var request = await publishedRouter.CreateRequestAsync(umbracoContext.CleanedUmbracoUrl);
// must lookup domain
publishedRouter.FindDomain(request);
if (expectedNode > 0)
{
Assert.AreEqual(expectedCulture, request.Culture);
}
var finder = new ContentFinderByUrlAlias(Mock.Of<ILogger<ContentFinderByUrlAlias>>(), Mock.Of<IPublishedValueFallback>(), VariationContextAccessor, umbracoContextAccessor);
var result = finder.TryFindContent(request);
if (expectedNode > 0)
{
Assert.IsTrue(result);
Assert.AreEqual(request.PublishedContent.Id, expectedNode);
}
else
{
Assert.IsFalse(result);
}
}
}
}