Merge branch 'v15/dev' into contrib
This commit is contained in:
@@ -27,26 +27,68 @@ public class RefresherTests
|
||||
Assert.AreEqual(source[0].ChangeTypes, payload[0].ChangeTypes);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ContentCacheRefresherCanDeserializeJsonPayload()
|
||||
[TestCase(TreeChangeTypes.None, false)]
|
||||
[TestCase(TreeChangeTypes.RefreshAll, true)]
|
||||
[TestCase(TreeChangeTypes.RefreshBranch, false)]
|
||||
[TestCase(TreeChangeTypes.Remove, true)]
|
||||
[TestCase(TreeChangeTypes.RefreshNode, false)]
|
||||
public void ContentCacheRefresherCanDeserializeJsonPayload(TreeChangeTypes changeTypes, bool blueprint)
|
||||
{
|
||||
var key = Guid.NewGuid();
|
||||
ContentCacheRefresher.JsonPayload[] source =
|
||||
{
|
||||
new ContentCacheRefresher.JsonPayload()
|
||||
{
|
||||
Id = 1234,
|
||||
Key = Guid.NewGuid(),
|
||||
ChangeTypes = TreeChangeTypes.None
|
||||
Key = key,
|
||||
ChangeTypes = changeTypes,
|
||||
Blueprint = blueprint
|
||||
}
|
||||
};
|
||||
|
||||
var json = JsonSerializer.Serialize(source);
|
||||
var payload = JsonSerializer.Deserialize<ContentCacheRefresher.JsonPayload[]>(json);
|
||||
|
||||
Assert.AreEqual(source[0].Id, payload[0].Id);
|
||||
Assert.AreEqual(source[0].Key, payload[0].Key);
|
||||
Assert.AreEqual(source[0].ChangeTypes, payload[0].ChangeTypes);
|
||||
Assert.AreEqual(source[0].Blueprint, payload[0].Blueprint);
|
||||
Assert.AreEqual(1234, payload[0].Id);
|
||||
Assert.AreEqual(key, payload[0].Key);
|
||||
Assert.AreEqual(changeTypes, payload[0].ChangeTypes);
|
||||
Assert.AreEqual(blueprint, payload[0].Blueprint);
|
||||
Assert.IsNull(payload[0].PublishedCultures);
|
||||
Assert.IsNull(payload[0].UnpublishedCultures);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ContentCacheRefresherCanDeserializeJsonPayloadWithCultures()
|
||||
{
|
||||
var key = Guid.NewGuid();
|
||||
ContentCacheRefresher.JsonPayload[] source =
|
||||
{
|
||||
new ContentCacheRefresher.JsonPayload()
|
||||
{
|
||||
Id = 1234,
|
||||
Key = key,
|
||||
PublishedCultures = ["en-US", "da-DK"],
|
||||
UnpublishedCultures = ["de-DE"]
|
||||
}
|
||||
};
|
||||
|
||||
var json = JsonSerializer.Serialize(source);
|
||||
var payload = JsonSerializer.Deserialize<ContentCacheRefresher.JsonPayload[]>(json);
|
||||
|
||||
Assert.IsNotNull(payload[0].PublishedCultures);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.AreEqual(2, payload[0].PublishedCultures.Length);
|
||||
Assert.AreEqual("en-US", payload[0].PublishedCultures.First());
|
||||
Assert.AreEqual("da-DK", payload[0].PublishedCultures.Last());
|
||||
});
|
||||
|
||||
Assert.IsNotNull(payload[0].UnpublishedCultures);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.AreEqual(1, payload[0].UnpublishedCultures.Length);
|
||||
Assert.AreEqual("de-DE", payload[0].UnpublishedCultures.First());
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Cms.Core.DeliveryApi;
|
||||
using Umbraco.Cms.Core.Services;
|
||||
|
||||
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.DeliveryApi;
|
||||
|
||||
[TestFixture]
|
||||
public class ApiDocumentUrlServiceTests
|
||||
{
|
||||
[Test]
|
||||
public void Can_Resolve_Document_Key_With_Start_Node()
|
||||
{
|
||||
var documentKey = Guid.NewGuid();
|
||||
var documentUrlServiceMock = new Mock<IDocumentUrlService>();
|
||||
documentUrlServiceMock
|
||||
.Setup(m => m.GetDocumentKeyByRoute(
|
||||
"/some/where",
|
||||
It.IsAny<string?>(),
|
||||
1234,
|
||||
false))
|
||||
.Returns(documentKey);
|
||||
|
||||
var apiDocumentUrlService = new ApiDocumentUrlService(documentUrlServiceMock.Object);
|
||||
var result = apiDocumentUrlService.GetDocumentKeyByRoute("1234/some/where", null, false);
|
||||
Assert.AreEqual(documentKey, result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Resolve_Document_Key_Without_Start_Node()
|
||||
{
|
||||
var documentKey = Guid.NewGuid();
|
||||
var documentUrlServiceMock = new Mock<IDocumentUrlService>();
|
||||
documentUrlServiceMock
|
||||
.Setup(m => m.GetDocumentKeyByRoute(
|
||||
"/some/where",
|
||||
It.IsAny<string?>(),
|
||||
null,
|
||||
false))
|
||||
.Returns(documentKey);
|
||||
|
||||
var apiDocumentUrlService = new ApiDocumentUrlService(documentUrlServiceMock.Object);
|
||||
var result = apiDocumentUrlService.GetDocumentKeyByRoute("/some/where", null, false);
|
||||
Assert.AreEqual(documentKey, result);
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,6 @@ using Umbraco.Cms.Core.DeliveryApi;
|
||||
using Umbraco.Cms.Core.Models.PublishedContent;
|
||||
using Umbraco.Cms.Core.PublishedCache;
|
||||
using Umbraco.Cms.Core.Services;
|
||||
using Umbraco.Cms.Infrastructure.HybridCache;
|
||||
|
||||
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.DeliveryApi;
|
||||
|
||||
@@ -17,8 +16,9 @@ public class PublishedContentCacheTests : DeliveryApiTests
|
||||
|
||||
private readonly Guid _contentTwoId = Guid.Parse("4EF11E1E-FB50-4627-8A86-E10ED6F4DCE4");
|
||||
|
||||
private readonly Guid _contentThreeId = Guid.Parse("013387EE-57AF-4ABD-B03C-F991B0722CCA");
|
||||
|
||||
private IPublishedContentCache _contentCache;
|
||||
private IPublishedContentCache _contentCacheMock;
|
||||
private IDocumentUrlService _documentUrlService;
|
||||
|
||||
[SetUp]
|
||||
@@ -34,37 +34,41 @@ public class PublishedContentCacheTests : DeliveryApiTests
|
||||
var contentTwoMock = new Mock<IPublishedContent>();
|
||||
ConfigurePublishedContentMock(contentTwoMock, _contentTwoId, "Content Two", "content-two", contentTypeTwoMock.Object, Array.Empty<IPublishedProperty>());
|
||||
|
||||
var contentTypeThreeMock = new Mock<IPublishedContentType>();
|
||||
contentTypeThreeMock.SetupGet(m => m.Alias).Returns("theThirdContentType");
|
||||
var contentThreeMock = new Mock<IPublishedContent>();
|
||||
ConfigurePublishedContentMock(contentThreeMock, _contentThreeId, "Content Three", "content-three", contentTypeThreeMock.Object, Array.Empty<IPublishedProperty>());
|
||||
|
||||
var documentUrlService = new Mock<IDocumentUrlService>();
|
||||
documentUrlService
|
||||
.Setup(x => x.GetDocumentKeyByRoute("content-one", It.IsAny<string?>(), It.IsAny<int?>(), It.IsAny<bool>()))
|
||||
.Setup(x => x.GetDocumentKeyByRoute("/content-one", It.IsAny<string?>(), It.IsAny<int?>(), It.IsAny<bool>()))
|
||||
.Returns(_contentOneId);
|
||||
documentUrlService
|
||||
.Setup(x => x.GetDocumentKeyByRoute("content-two", It.IsAny<string?>(), It.IsAny<int?>(), It.IsAny<bool>()))
|
||||
.Setup(x => x.GetDocumentKeyByRoute("/content-two", It.IsAny<string?>(), It.IsAny<int?>(), It.IsAny<bool>()))
|
||||
.Returns(_contentTwoId);
|
||||
documentUrlService
|
||||
.Setup(x => x.GetDocumentKeyByRoute("/content-three", It.IsAny<string?>(), 1234, It.IsAny<bool>()))
|
||||
.Returns(_contentThreeId);
|
||||
|
||||
var contentCacheMock = new Mock<IPublishedContentCache>();
|
||||
contentCacheMock
|
||||
.Setup(m => m.GetByRoute(It.IsAny<bool>(), "content-one", null, null))
|
||||
.Returns(contentOneMock.Object);
|
||||
contentCacheMock
|
||||
.Setup(m => m.GetById(It.IsAny<bool>(), _contentOneId))
|
||||
.Returns(contentOneMock.Object);
|
||||
contentCacheMock
|
||||
.Setup(m => m.GetByRoute(It.IsAny<bool>(), "content-two", null, null))
|
||||
.Returns(contentTwoMock.Object);
|
||||
contentCacheMock
|
||||
.Setup(m => m.GetById(It.IsAny<bool>(), _contentTwoId))
|
||||
.Returns(contentTwoMock.Object);
|
||||
contentCacheMock
|
||||
.Setup(m => m.GetById(It.IsAny<bool>(), _contentThreeId))
|
||||
.Returns(contentThreeMock.Object);
|
||||
|
||||
_contentCache = contentCacheMock.Object;
|
||||
_contentCacheMock = contentCacheMock.Object;
|
||||
_documentUrlService = documentUrlService.Object;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PublishedContentCache_CanGetById()
|
||||
{
|
||||
var publishedContentCache = new ApiPublishedContentCache(CreateRequestPreviewService(), CreateRequestCultureService(), CreateDeliveryApiSettings(), _documentUrlService, _contentCacheMock);
|
||||
var publishedContentCache = new ApiPublishedContentCache(CreateRequestPreviewService(), CreateRequestCultureService(), CreateDeliveryApiSettings(), CreateApiDocumentUrlService(), _contentCache);
|
||||
var content = publishedContentCache.GetById(_contentOneId);
|
||||
Assert.IsNotNull(content);
|
||||
Assert.AreEqual(_contentOneId, content.Key);
|
||||
@@ -75,18 +79,29 @@ public class PublishedContentCacheTests : DeliveryApiTests
|
||||
[Test]
|
||||
public void PublishedContentCache_CanGetByRoute()
|
||||
{
|
||||
var publishedContentCache = new ApiPublishedContentCache(CreateRequestPreviewService(), CreateRequestCultureService(), CreateDeliveryApiSettings(), _documentUrlService, _contentCacheMock);
|
||||
var content = publishedContentCache.GetByRoute("content-two");
|
||||
var publishedContentCache = new ApiPublishedContentCache(CreateRequestPreviewService(), CreateRequestCultureService(), CreateDeliveryApiSettings(), CreateApiDocumentUrlService(), _contentCache);
|
||||
var content = publishedContentCache.GetByRoute("/content-two");
|
||||
Assert.IsNotNull(content);
|
||||
Assert.AreEqual(_contentTwoId, content.Key);
|
||||
Assert.AreEqual("content-two", content.UrlSegment);
|
||||
Assert.AreEqual("theOtherContentType", content.ContentType.Alias);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PublishedContentCache_CanGetByRoute_WithStartNodeIdPrefix()
|
||||
{
|
||||
var publishedContentCache = new ApiPublishedContentCache(CreateRequestPreviewService(), CreateRequestCultureService(), CreateDeliveryApiSettings(), CreateApiDocumentUrlService(), _contentCache);
|
||||
var content = publishedContentCache.GetByRoute("1234/content-three");
|
||||
Assert.IsNotNull(content);
|
||||
Assert.AreEqual(_contentThreeId, content.Key);
|
||||
Assert.AreEqual("content-three", content.UrlSegment);
|
||||
Assert.AreEqual("theThirdContentType", content.ContentType.Alias);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PublishedContentCache_CanGetByIds()
|
||||
{
|
||||
var publishedContentCache = new ApiPublishedContentCache(CreateRequestPreviewService(), CreateRequestCultureService(), CreateDeliveryApiSettings(), _documentUrlService, _contentCacheMock);
|
||||
var publishedContentCache = new ApiPublishedContentCache(CreateRequestPreviewService(), CreateRequestCultureService(), CreateDeliveryApiSettings(), CreateApiDocumentUrlService(), _contentCache);
|
||||
var content = publishedContentCache.GetByIds(new[] { _contentOneId, _contentTwoId }).ToArray();
|
||||
Assert.AreEqual(2, content.Length);
|
||||
Assert.AreEqual(_contentOneId, content.First().Key);
|
||||
@@ -98,7 +113,7 @@ public class PublishedContentCacheTests : DeliveryApiTests
|
||||
public void PublishedContentCache_GetById_SupportsDenyList(bool denied)
|
||||
{
|
||||
var denyList = denied ? new[] { "theOtherContentType" } : null;
|
||||
var publishedContentCache = new ApiPublishedContentCache(CreateRequestPreviewService(), CreateRequestCultureService(), CreateDeliveryApiSettings(denyList), _documentUrlService, _contentCacheMock);
|
||||
var publishedContentCache = new ApiPublishedContentCache(CreateRequestPreviewService(), CreateRequestCultureService(), CreateDeliveryApiSettings(denyList), CreateApiDocumentUrlService(), _contentCache);
|
||||
var content = publishedContentCache.GetById(_contentTwoId);
|
||||
|
||||
if (denied)
|
||||
@@ -116,8 +131,8 @@ public class PublishedContentCacheTests : DeliveryApiTests
|
||||
public void PublishedContentCache_GetByRoute_SupportsDenyList(bool denied)
|
||||
{
|
||||
var denyList = denied ? new[] { "theContentType" } : null;
|
||||
var publishedContentCache = new ApiPublishedContentCache(CreateRequestPreviewService(), CreateRequestCultureService(), CreateDeliveryApiSettings(denyList), _documentUrlService, _contentCacheMock);
|
||||
var content = publishedContentCache.GetByRoute("content-one");
|
||||
var publishedContentCache = new ApiPublishedContentCache(CreateRequestPreviewService(), CreateRequestCultureService(), CreateDeliveryApiSettings(denyList), CreateApiDocumentUrlService(), _contentCache);
|
||||
var content = publishedContentCache.GetByRoute("/content-one");
|
||||
|
||||
if (denied)
|
||||
{
|
||||
@@ -134,7 +149,7 @@ public class PublishedContentCacheTests : DeliveryApiTests
|
||||
public void PublishedContentCache_GetByIds_SupportsDenyList(string deniedContentType)
|
||||
{
|
||||
var denyList = new[] { deniedContentType };
|
||||
var publishedContentCache = new ApiPublishedContentCache(CreateRequestPreviewService(), CreateRequestCultureService(), CreateDeliveryApiSettings(denyList), _documentUrlService, _contentCacheMock);
|
||||
var publishedContentCache = new ApiPublishedContentCache(CreateRequestPreviewService(), CreateRequestCultureService(), CreateDeliveryApiSettings(denyList), CreateApiDocumentUrlService(), _contentCache);
|
||||
var content = publishedContentCache.GetByIds(new[] { _contentOneId, _contentTwoId }).ToArray();
|
||||
|
||||
Assert.AreEqual(1, content.Length);
|
||||
@@ -152,7 +167,7 @@ public class PublishedContentCacheTests : DeliveryApiTests
|
||||
public void PublishedContentCache_GetById_CanRetrieveContentTypesOutsideTheDenyList()
|
||||
{
|
||||
var denyList = new[] { "theContentType" };
|
||||
var publishedContentCache = new ApiPublishedContentCache(CreateRequestPreviewService(), CreateRequestCultureService(), CreateDeliveryApiSettings(denyList), _documentUrlService, _contentCacheMock);
|
||||
var publishedContentCache = new ApiPublishedContentCache(CreateRequestPreviewService(), CreateRequestCultureService(), CreateDeliveryApiSettings(denyList), CreateApiDocumentUrlService(), _contentCache);
|
||||
var content = publishedContentCache.GetById(_contentTwoId);
|
||||
Assert.IsNotNull(content);
|
||||
Assert.AreEqual(_contentTwoId, content.Key);
|
||||
@@ -164,8 +179,8 @@ public class PublishedContentCacheTests : DeliveryApiTests
|
||||
public void PublishedContentCache_GetByRoute_CanRetrieveContentTypesOutsideTheDenyList()
|
||||
{
|
||||
var denyList = new[] { "theOtherContentType" };
|
||||
var publishedContentCache = new ApiPublishedContentCache(CreateRequestPreviewService(), CreateRequestCultureService(), CreateDeliveryApiSettings(denyList), _documentUrlService, _contentCacheMock);
|
||||
var content = publishedContentCache.GetByRoute("content-one");
|
||||
var publishedContentCache = new ApiPublishedContentCache(CreateRequestPreviewService(), CreateRequestCultureService(), CreateDeliveryApiSettings(denyList), CreateApiDocumentUrlService(), _contentCache);
|
||||
var content = publishedContentCache.GetByRoute("/content-one");
|
||||
Assert.IsNotNull(content);
|
||||
Assert.AreEqual(_contentOneId, content.Key);
|
||||
Assert.AreEqual("content-one", content.UrlSegment);
|
||||
@@ -176,7 +191,7 @@ public class PublishedContentCacheTests : DeliveryApiTests
|
||||
public void PublishedContentCache_GetByIds_CanDenyAllRequestedContent()
|
||||
{
|
||||
var denyList = new[] { "theContentType", "theOtherContentType" };
|
||||
var publishedContentCache = new ApiPublishedContentCache(CreateRequestPreviewService(), CreateRequestCultureService(), CreateDeliveryApiSettings(denyList), _documentUrlService, _contentCacheMock);
|
||||
var publishedContentCache = new ApiPublishedContentCache(CreateRequestPreviewService(), CreateRequestCultureService(), CreateDeliveryApiSettings(denyList), CreateApiDocumentUrlService(), _contentCache);
|
||||
var content = publishedContentCache.GetByIds(new[] { _contentOneId, _contentTwoId }).ToArray();
|
||||
Assert.IsEmpty(content);
|
||||
}
|
||||
@@ -185,8 +200,8 @@ public class PublishedContentCacheTests : DeliveryApiTests
|
||||
public void PublishedContentCache_DenyListIsCaseInsensitive()
|
||||
{
|
||||
var denyList = new[] { "THEcontentTYPE" };
|
||||
var publishedContentCache = new ApiPublishedContentCache(CreateRequestPreviewService(), CreateRequestCultureService(), CreateDeliveryApiSettings(denyList), _documentUrlService, _contentCacheMock);
|
||||
var content = publishedContentCache.GetByRoute("content-one");
|
||||
var publishedContentCache = new ApiPublishedContentCache(CreateRequestPreviewService(), CreateRequestCultureService(), CreateDeliveryApiSettings(denyList), CreateApiDocumentUrlService(), _contentCache);
|
||||
var content = publishedContentCache.GetByRoute("/content-one");
|
||||
Assert.IsNull(content);
|
||||
}
|
||||
|
||||
@@ -211,4 +226,6 @@ public class PublishedContentCacheTests : DeliveryApiTests
|
||||
deliveryApiOptionsMonitorMock.SetupGet(s => s.CurrentValue).Returns(deliveryApiSettings);
|
||||
return deliveryApiOptionsMonitorMock.Object;
|
||||
}
|
||||
|
||||
private IApiDocumentUrlService CreateApiDocumentUrlService() => new ApiDocumentUrlService(_documentUrlService);
|
||||
}
|
||||
|
||||
@@ -357,6 +357,48 @@ public class RichTextParserTests : PropertyValueConverterTests
|
||||
Assert.IsEmpty(blockLevelBlock.Elements);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParseElement_CanHandleWhitespaceAroundInlineElemements()
|
||||
{
|
||||
var parser = CreateRichTextElementParser();
|
||||
|
||||
var element = parser.Parse("<p>What follows from <strong>here</strong> <em>is</em> <a href=\"#\">just</a> a bunch of text.</p>") as RichTextRootElement;
|
||||
Assert.IsNotNull(element);
|
||||
var paragraphElement = element.Elements.Single() as RichTextGenericElement;
|
||||
Assert.IsNotNull(paragraphElement);
|
||||
|
||||
var childElements = paragraphElement.Elements.ToArray();
|
||||
Assert.AreEqual(7, childElements.Length);
|
||||
|
||||
var childElementCounter = 0;
|
||||
|
||||
void AssertNextChildElementIsText(string expectedText)
|
||||
{
|
||||
var textElement = childElements[childElementCounter++] as RichTextTextElement;
|
||||
Assert.IsNotNull(textElement);
|
||||
Assert.AreEqual(expectedText, textElement.Text);
|
||||
}
|
||||
|
||||
void AssertNextChildElementIsGeneric(string expectedTag, string expectedInnerText)
|
||||
{
|
||||
var genericElement = childElements[childElementCounter++] as RichTextGenericElement;
|
||||
Assert.IsNotNull(genericElement);
|
||||
Assert.AreEqual(expectedTag, genericElement.Tag);
|
||||
Assert.AreEqual(1, genericElement.Elements.Count());
|
||||
var textElement = genericElement.Elements.First() as RichTextTextElement;
|
||||
Assert.IsNotNull(textElement);
|
||||
Assert.AreEqual(expectedInnerText, textElement.Text);
|
||||
}
|
||||
|
||||
AssertNextChildElementIsText("What follows from ");
|
||||
AssertNextChildElementIsGeneric("strong", "here");
|
||||
AssertNextChildElementIsText(" ");
|
||||
AssertNextChildElementIsGeneric("em", "is");
|
||||
AssertNextChildElementIsText(" ");
|
||||
AssertNextChildElementIsGeneric("a", "just");
|
||||
AssertNextChildElementIsText(" a bunch of text.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParseMarkup_CanParseContentLink()
|
||||
{
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Cms.Api.Delivery.Querying.Selectors;
|
||||
using Umbraco.Cms.Core.DeliveryApi;
|
||||
using Umbraco.Cms.Core.Services;
|
||||
using Umbraco.Cms.Core.Services.Navigation;
|
||||
|
||||
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.DeliveryApi.Selectors;
|
||||
|
||||
[TestFixture]
|
||||
public class AncestorsSelectorTests
|
||||
{
|
||||
private readonly Guid _documentKey = Guid.NewGuid();
|
||||
private IDocumentNavigationQueryService _documentNavigationQueryService;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
IEnumerable<Guid> ancestorKeys =
|
||||
[
|
||||
new("863e10d5-b0f8-421d-902d-5e4d1bd8e780"),
|
||||
new("11fc9bdc-8366-4a6b-a9c2-6b8b2717c4b8")
|
||||
];
|
||||
var documentNavigationQueryServiceMock = new Mock<IDocumentNavigationQueryService>();
|
||||
documentNavigationQueryServiceMock
|
||||
.Setup(m => m.TryGetAncestorsKeys(_documentKey, out ancestorKeys))
|
||||
.Returns(true);
|
||||
_documentNavigationQueryService = documentNavigationQueryServiceMock.Object;
|
||||
}
|
||||
|
||||
[TestCase(null)]
|
||||
[TestCase(1234)]
|
||||
public void Can_Build_Selector_Option_For_Path(int? documentStartNodeId)
|
||||
{
|
||||
var documentUrlServiceMock = new Mock<IDocumentUrlService>();
|
||||
documentUrlServiceMock
|
||||
.Setup(m => m.GetDocumentKeyByRoute(
|
||||
"/some/where",
|
||||
It.IsAny<string?>(),
|
||||
documentStartNodeId,
|
||||
false))
|
||||
.Returns(_documentKey);
|
||||
|
||||
var requestRoutingServiceMock = new Mock<IRequestRoutingService>();
|
||||
requestRoutingServiceMock.Setup(m => m.GetContentRoute("/some/where")).Returns($"{documentStartNodeId}/some/where");
|
||||
|
||||
var subject = new AncestorsSelector(
|
||||
requestRoutingServiceMock.Object,
|
||||
Mock.Of<IRequestPreviewService>(),
|
||||
Mock.Of<IRequestCultureService>(),
|
||||
new ApiDocumentUrlService(documentUrlServiceMock.Object),
|
||||
_documentNavigationQueryService);
|
||||
|
||||
var result = subject.BuildSelectorOption("ancestors:/some/where");
|
||||
Assert.AreEqual(2, result.Values.Length);
|
||||
Assert.AreEqual("863e10d5-b0f8-421d-902d-5e4d1bd8e780", result.Values[0]);
|
||||
Assert.AreEqual("11fc9bdc-8366-4a6b-a9c2-6b8b2717c4b8", result.Values[1]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Build_Selector_Option_For_Id()
|
||||
{
|
||||
var subject = new AncestorsSelector(
|
||||
Mock.Of<IRequestRoutingService>(),
|
||||
Mock.Of<IRequestPreviewService>(),
|
||||
Mock.Of<IRequestCultureService>(),
|
||||
Mock.Of<IApiDocumentUrlService>(),
|
||||
_documentNavigationQueryService);
|
||||
|
||||
var result = subject.BuildSelectorOption($"ancestors:{_documentKey:D}");
|
||||
Assert.AreEqual(2, result.Values.Length);
|
||||
Assert.AreEqual("863e10d5-b0f8-421d-902d-5e4d1bd8e780", result.Values[0]);
|
||||
Assert.AreEqual("11fc9bdc-8366-4a6b-a9c2-6b8b2717c4b8", result.Values[1]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Cms.Api.Delivery.Querying.Selectors;
|
||||
using Umbraco.Cms.Core.DeliveryApi;
|
||||
using Umbraco.Cms.Core.Services;
|
||||
|
||||
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.DeliveryApi.Selectors;
|
||||
|
||||
[TestFixture]
|
||||
public class ChildrenSelectorTests
|
||||
{
|
||||
[TestCase(null)]
|
||||
[TestCase(1234)]
|
||||
public void Can_Build_Selector_Option_For_Path(int? documentStartNodeId)
|
||||
{
|
||||
var documentKey = Guid.NewGuid();
|
||||
|
||||
var documentUrlServiceMock = new Mock<IDocumentUrlService>();
|
||||
documentUrlServiceMock
|
||||
.Setup(m => m.GetDocumentKeyByRoute(
|
||||
"/some/where",
|
||||
It.IsAny<string?>(),
|
||||
documentStartNodeId,
|
||||
false))
|
||||
.Returns(documentKey);
|
||||
|
||||
var requestRoutingServiceMock = new Mock<IRequestRoutingService>();
|
||||
requestRoutingServiceMock.Setup(m => m.GetContentRoute("/some/where")).Returns($"{documentStartNodeId}/some/where");
|
||||
|
||||
var subject = new ChildrenSelector(
|
||||
requestRoutingServiceMock.Object,
|
||||
Mock.Of<IRequestPreviewService>(),
|
||||
Mock.Of<IRequestCultureService>(),
|
||||
new ApiDocumentUrlService(documentUrlServiceMock.Object));
|
||||
|
||||
var result = subject.BuildSelectorOption("children:/some/where");
|
||||
Assert.AreEqual(1, result.Values.Length);
|
||||
Assert.AreEqual(documentKey.ToString("D"), result.Values[0]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Build_Selector_Option_For_Id()
|
||||
{
|
||||
var documentKey = Guid.NewGuid();
|
||||
|
||||
var subject = new ChildrenSelector(
|
||||
Mock.Of<IRequestRoutingService>(),
|
||||
Mock.Of<IRequestPreviewService>(),
|
||||
Mock.Of<IRequestCultureService>(),
|
||||
Mock.Of<IApiDocumentUrlService>());
|
||||
|
||||
var result = subject.BuildSelectorOption($"children:{documentKey:D}");
|
||||
Assert.AreEqual(1, result.Values.Length);
|
||||
Assert.AreEqual(documentKey.ToString("D"), result.Values[0]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Cms.Api.Delivery.Querying.Selectors;
|
||||
using Umbraco.Cms.Core.DeliveryApi;
|
||||
using Umbraco.Cms.Core.Services;
|
||||
|
||||
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.DeliveryApi.Selectors;
|
||||
|
||||
[TestFixture]
|
||||
public class DescendantsSelectorTests
|
||||
{
|
||||
[TestCase(null)]
|
||||
[TestCase(1234)]
|
||||
public void Can_Build_Selector_Option_For_Path(int? documentStartNodeId)
|
||||
{
|
||||
var documentKey = Guid.NewGuid();
|
||||
|
||||
var documentUrlServiceMock = new Mock<IDocumentUrlService>();
|
||||
documentUrlServiceMock
|
||||
.Setup(m => m.GetDocumentKeyByRoute(
|
||||
"/some/where",
|
||||
It.IsAny<string?>(),
|
||||
documentStartNodeId,
|
||||
false))
|
||||
.Returns(documentKey);
|
||||
|
||||
var requestRoutingServiceMock = new Mock<IRequestRoutingService>();
|
||||
requestRoutingServiceMock.Setup(m => m.GetContentRoute("/some/where")).Returns($"{documentStartNodeId}/some/where");
|
||||
|
||||
var subject = new DescendantsSelector(
|
||||
requestRoutingServiceMock.Object,
|
||||
Mock.Of<IRequestPreviewService>(),
|
||||
Mock.Of<IRequestCultureService>(),
|
||||
new ApiDocumentUrlService(documentUrlServiceMock.Object));
|
||||
|
||||
var result = subject.BuildSelectorOption("descendants:/some/where");
|
||||
Assert.AreEqual(1, result.Values.Length);
|
||||
Assert.AreEqual(documentKey.ToString("D"), result.Values[0]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Build_Selector_Option_For_Id()
|
||||
{
|
||||
var documentKey = Guid.NewGuid();
|
||||
|
||||
var subject = new DescendantsSelector(
|
||||
Mock.Of<IRequestRoutingService>(),
|
||||
Mock.Of<IRequestPreviewService>(),
|
||||
Mock.Of<IRequestCultureService>(),
|
||||
Mock.Of<IApiDocumentUrlService>());
|
||||
|
||||
var result = subject.BuildSelectorOption($"descendants:{documentKey:D}");
|
||||
Assert.AreEqual(1, result.Values.Length);
|
||||
Assert.AreEqual(documentKey.ToString("D"), result.Values[0]);
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,6 @@ using Umbraco.Cms.Core.PropertyEditors;
|
||||
using Umbraco.Cms.Core.PropertyEditors.ValueConverters;
|
||||
using Umbraco.Cms.Core.Strings;
|
||||
using Umbraco.Cms.Infrastructure.Serialization;
|
||||
using Umbraco.Cms.Tests.Common.Builders;
|
||||
|
||||
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.PropertyEditors;
|
||||
|
||||
@@ -47,54 +46,30 @@ public class PropertyEditorValueConverterTests
|
||||
}
|
||||
}
|
||||
|
||||
[TestCase("TRUE", null, true)]
|
||||
[TestCase("True", null, true)]
|
||||
[TestCase("true", null, true)]
|
||||
[TestCase("1", null, true)]
|
||||
[TestCase(1, null, true)]
|
||||
[TestCase(true, null, true)]
|
||||
[TestCase("FALSE", null, false)]
|
||||
[TestCase("False", null, false)]
|
||||
[TestCase("false", null, false)]
|
||||
[TestCase("0", null, false)]
|
||||
[TestCase(0, null, false)]
|
||||
[TestCase(false, null, false)]
|
||||
[TestCase("", null, false)]
|
||||
[TestCase("blah", null, false)]
|
||||
[TestCase(null, false, false)]
|
||||
[TestCase(null, true, true)]
|
||||
public void CanConvertTrueFalsePropertyEditor(object value, bool initialStateConfigurationValue, bool expected)
|
||||
[TestCase("TRUE", true)]
|
||||
[TestCase("True", true)]
|
||||
[TestCase("true", true)]
|
||||
[TestCase("1", true)]
|
||||
[TestCase(1, true)]
|
||||
[TestCase(true, true)]
|
||||
[TestCase("FALSE", false)]
|
||||
[TestCase("False", false)]
|
||||
[TestCase("false", false)]
|
||||
[TestCase("0", false)]
|
||||
[TestCase(0, false)]
|
||||
[TestCase(false, false)]
|
||||
[TestCase("", false)]
|
||||
[TestCase(null, false)]
|
||||
[TestCase("blah", false)]
|
||||
public void CanConvertYesNoPropertyEditor(object value, bool expected)
|
||||
{
|
||||
var publishedDataType = CreatePublishedDataType(initialStateConfigurationValue);
|
||||
|
||||
var publishedPropertyTypeMock = new Mock<IPublishedPropertyType>();
|
||||
publishedPropertyTypeMock
|
||||
.SetupGet(p => p.DataType)
|
||||
.Returns(publishedDataType);
|
||||
|
||||
var converter = new YesNoValueConverter();
|
||||
var intermediateResult = converter.ConvertSourceToIntermediate(null, publishedPropertyTypeMock.Object, value, false);
|
||||
var result = converter.ConvertIntermediateToObject(null, publishedPropertyTypeMock.Object, PropertyCacheLevel.Element, intermediateResult, false);
|
||||
var result =
|
||||
converter.ConvertSourceToIntermediate(null, null, value, false); // does not use type for conversion
|
||||
|
||||
Assert.AreEqual(expected, result);
|
||||
}
|
||||
|
||||
private static PublishedDataType CreatePublishedDataType(bool initialStateConfigurationValue)
|
||||
{
|
||||
var dataTypeConfiguration = new TrueFalseConfiguration
|
||||
{
|
||||
InitialState = initialStateConfigurationValue
|
||||
};
|
||||
|
||||
var dateTypeMock = new Mock<IDataType>();
|
||||
dateTypeMock.SetupGet(x => x.Id).Returns(1000);
|
||||
dateTypeMock.SetupGet(x => x.EditorAlias).Returns(global::Umbraco.Cms.Core.Constants.PropertyEditors.Aliases.Boolean);
|
||||
dateTypeMock.SetupGet(x => x.EditorUiAlias).Returns("Umb.PropertyEditorUi.Toggle");
|
||||
dateTypeMock.SetupGet(x => x.ConfigurationObject).Returns(dataTypeConfiguration);
|
||||
|
||||
return new PublishedDataType(dateTypeMock.Object.Id, dateTypeMock.Object.EditorAlias, dateTypeMock.Object.EditorUiAlias, new Lazy<object>(() => dataTypeConfiguration));
|
||||
}
|
||||
|
||||
[TestCase("[\"apples\"]", new[] { "apples" })]
|
||||
[TestCase("[\"apples\",\"oranges\"]", new[] { "apples", "oranges" })]
|
||||
[TestCase("[\"apples\",\"oranges\",\"pears\"]", new[] { "apples", "oranges", "pears" })]
|
||||
|
||||
Reference in New Issue
Block a user