2021-10-19 23:11:54 +11:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Web;
|
|
|
|
|
using Moq;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using Umbraco.Cms.Core.Routing;
|
|
|
|
|
using Umbraco.Cms.Core.Web;
|
|
|
|
|
using Umbraco.Cms.Infrastructure.PublishedCache;
|
|
|
|
|
using Umbraco.Cms.Tests.Common.Published;
|
|
|
|
|
using Umbraco.Cms.Tests.UnitTests.TestHelpers;
|
|
|
|
|
using Umbraco.Extensions;
|
|
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Routing;
|
|
|
|
|
|
|
|
|
|
[TestFixture]
|
|
|
|
|
public class ContentFinderByPageIdQueryTests : PublishedSnapshotServiceTestBase
|
2021-10-19 23:11:54 +11:00
|
|
|
{
|
2022-06-21 08:09:38 +02:00
|
|
|
[SetUp]
|
|
|
|
|
public override void Setup()
|
2021-10-19 23:11:54 +11:00
|
|
|
{
|
2022-06-21 08:09:38 +02:00
|
|
|
base.Setup();
|
2021-10-19 23:11:54 +11:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
var xml = PublishedContentXml.BaseWebTestXml(1234);
|
2021-10-19 23:11:54 +11:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
IEnumerable<ContentNodeKit> kits = PublishedContentXmlAdapter.GetContentNodeKits(
|
|
|
|
|
xml,
|
|
|
|
|
TestHelper.ShortStringHelper,
|
|
|
|
|
out var contentTypes,
|
|
|
|
|
out var dataTypes).ToList();
|
2021-10-19 23:11:54 +11:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
InitializedCache(kits, contentTypes, dataTypes);
|
|
|
|
|
}
|
2021-10-19 23:11:54 +11:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
[TestCase("/?umbPageId=1046", 1046)]
|
|
|
|
|
[TestCase("/?UMBPAGEID=1046", 1046)]
|
|
|
|
|
[TestCase("/default.aspx?umbPageId=1046", 1046)] // TODO: Should this match??
|
|
|
|
|
[TestCase("/some/other/page?umbPageId=1046", 1046)] // TODO: Should this match??
|
|
|
|
|
[TestCase("/some/other/page.aspx?umbPageId=1046", 1046)] // TODO: Should this match??
|
|
|
|
|
public async Task Lookup_By_Page_Id(string urlAsString, int nodeMatch)
|
|
|
|
|
{
|
|
|
|
|
var umbracoContextAccessor = GetUmbracoContextAccessor(urlAsString);
|
|
|
|
|
var umbracoContext = umbracoContextAccessor.GetRequiredUmbracoContext();
|
|
|
|
|
var publishedRouter = CreatePublishedRouter(umbracoContextAccessor);
|
|
|
|
|
var frequest = await publishedRouter.CreateRequestAsync(umbracoContext.CleanedUmbracoUrl);
|
2021-10-19 23:11:54 +11:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
var queryStrings = HttpUtility.ParseQueryString(umbracoContext.CleanedUmbracoUrl.Query);
|
2021-10-19 23:11:54 +11:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
var mockRequestAccessor = new Mock<IRequestAccessor>();
|
|
|
|
|
mockRequestAccessor.Setup(x => x.GetRequestValue("umbPageID"))
|
|
|
|
|
.Returns(queryStrings["umbPageID"]);
|
2021-10-19 23:11:54 +11:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
var lookup = new ContentFinderByPageIdQuery(mockRequestAccessor.Object, umbracoContextAccessor);
|
2021-10-19 23:11:54 +11:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
var result = await lookup.TryFindContent(frequest);
|
2021-10-19 23:11:54 +11:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
Assert.IsTrue(result);
|
|
|
|
|
Assert.AreEqual(frequest.PublishedContent.Id, nodeMatch);
|
2021-10-19 23:11:54 +11:00
|
|
|
}
|
|
|
|
|
}
|