|
1 | | -// using Microsoft.Extensions.Logging; |
2 | | -// using Microsoft.Extensions.Options; |
3 | | -// using Moq; |
4 | | -// using NUnit.Framework; |
5 | | -// using Umbraco.Cms.Core.Configuration.Models; |
6 | | -// using Umbraco.Cms.Core.Routing; |
7 | | -// using Umbraco.Cms.Core.Web; |
8 | | -// using Umbraco.Extensions; |
9 | | -// |
10 | | -// namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Routing; |
11 | | -// |
12 | | -// FIXME: Reintroduce if relevant |
13 | | -// [TestFixture] |
14 | | -// public class ContentFinderByKeyTests : ContentFinderByIdentifierTestsBase |
15 | | -// { |
16 | | -// [SetUp] |
17 | | -// public override void Setup() |
18 | | -// { |
19 | | -// base.Setup(); |
20 | | -// } |
21 | | -// |
22 | | -// [TestCase("/1598901d-ebbe-4996-b7fb-6a6cbac13a62", "1598901d-ebbe-4996-b7fb-6a6cbac13a62", true)] |
23 | | -// [TestCase("/1598901d-ebbe-4996-b7fb-6a6cbac13a62", "a383f6ed-cc54-46f1-a577-33f42e7214de", false)] |
24 | | -// public async Task Lookup_By_Key(string urlAsString, string nodeKeyString, bool shouldSucceed) |
25 | | -// { |
26 | | -// var nodeKey = Guid.Parse(nodeKeyString); |
27 | | -// |
28 | | -// PopulateCache(9999, nodeKey); |
29 | | -// |
30 | | -// var umbracoContextAccessor = GetUmbracoContextAccessor(urlAsString); |
31 | | -// var umbracoContext = umbracoContextAccessor.GetRequiredUmbracoContext(); |
32 | | -// var publishedRouter = CreatePublishedRouter(umbracoContextAccessor); |
33 | | -// var frequest = await publishedRouter.CreateRequestAsync(umbracoContext.CleanedUmbracoUrl); |
34 | | -// var webRoutingSettings = new WebRoutingSettings(); |
35 | | -// var lookup = new ContentFinderByKeyPath( |
36 | | -// Mock.Of<IOptionsMonitor<WebRoutingSettings>>(x => x.CurrentValue == webRoutingSettings), |
37 | | -// Mock.Of<ILogger<ContentFinderByKeyPath>>(), |
38 | | -// Mock.Of<IRequestAccessor>(), |
39 | | -// umbracoContextAccessor); |
40 | | -// |
41 | | -// var result = await lookup.TryFindContent(frequest); |
42 | | -// |
43 | | -// Assert.AreEqual(shouldSucceed, result); |
44 | | -// if (shouldSucceed) |
45 | | -// { |
46 | | -// Assert.AreEqual(frequest.PublishedContent!.Key, nodeKey); |
47 | | -// } |
48 | | -// else |
49 | | -// { |
50 | | -// Assert.IsNull(frequest.PublishedContent); |
51 | | -// } |
52 | | -// } |
53 | | -// } |
| 1 | +using AutoFixture.NUnit3; |
| 2 | +using Microsoft.Extensions.Logging; |
| 3 | +using Microsoft.Extensions.Options; |
| 4 | +using Moq; |
| 5 | +using NUnit.Framework; |
| 6 | +using Umbraco.Cms.Core.Configuration.Models; |
| 7 | +using Umbraco.Cms.Core.Models.PublishedContent; |
| 8 | +using Umbraco.Cms.Core.Routing; |
| 9 | +using Umbraco.Cms.Core.Services; |
| 10 | +using Umbraco.Cms.Core.Web; |
| 11 | +using Umbraco.Cms.Tests.UnitTests.AutoFixture; |
| 12 | + |
| 13 | +namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Routing; |
| 14 | + |
| 15 | +[TestFixture] |
| 16 | +public class ContentFinderByKeyTests |
| 17 | +{ |
| 18 | + [Test] |
| 19 | + [InlineAutoMoqData("/1598901d-ebbe-4996-b7fb-6a6cbac13a62", "1598901d-ebbe-4996-b7fb-6a6cbac13a62", true)] |
| 20 | + [InlineAutoMoqData("/1598901d-ebbe-4996-b7fb-6a6cbac13a62", "9E966427-25AB-4909-B403-DED1F421D1A7", false)] |
| 21 | + public async Task Lookup_By_Key( |
| 22 | + string urlAsString, |
| 23 | + string nodeKeyString, |
| 24 | + bool shouldSucceed, |
| 25 | + [Frozen] IPublishedContent publishedContent, |
| 26 | + [Frozen] IUmbracoContextAccessor umbracoContextAccessor, |
| 27 | + [Frozen] IUmbracoContext umbracoContext, |
| 28 | + IFileService fileService) |
| 29 | + { |
| 30 | + var absoluteUrl = "http://localhost" + urlAsString; |
| 31 | + |
| 32 | + Guid nodeKey = Guid.Parse(nodeKeyString); |
| 33 | + |
| 34 | + Mock.Get(umbracoContextAccessor).Setup(x => x.TryGetUmbracoContext(out umbracoContext)).Returns(true); |
| 35 | + Mock.Get(umbracoContext).Setup(x => x.Content.GetById(nodeKey)).Returns(publishedContent); |
| 36 | + Mock.Get(publishedContent).Setup(x => x.Key).Returns(nodeKey); |
| 37 | + |
| 38 | + var publishedRequestBuilder = new PublishedRequestBuilder(new Uri(absoluteUrl, UriKind.Absolute), fileService); |
| 39 | + var webRoutingSettings = new WebRoutingSettings(); |
| 40 | + |
| 41 | + var sut = new ContentFinderByKeyPath( |
| 42 | + Mock.Of<IOptionsMonitor<WebRoutingSettings>>(x => x.CurrentValue == webRoutingSettings), |
| 43 | + Mock.Of<ILogger<ContentFinderByKeyPath>>(), |
| 44 | + Mock.Of<IRequestAccessor>(), |
| 45 | + umbracoContextAccessor); |
| 46 | + |
| 47 | + await sut.TryFindContent(publishedRequestBuilder); |
| 48 | + |
| 49 | + if (shouldSucceed) |
| 50 | + { |
| 51 | + Assert.AreEqual(publishedRequestBuilder.PublishedContent!.Key, nodeKey); |
| 52 | + } |
| 53 | + else |
| 54 | + { |
| 55 | + Assert.AreNotEqual(publishedRequestBuilder.PublishedContent!.Key, nodeKey); |
| 56 | + } |
| 57 | + } |
| 58 | +} |
0 commit comments