Merge branch 'v15/dev' into v16/dev
# Conflicts: # src/Umbraco.Core/Configuration/Models/RuntimeSettings.cs
This commit is contained in:
@@ -18,6 +18,8 @@ public class PublishedContentCacheTests : DeliveryApiTests
|
||||
|
||||
private readonly Guid _contentThreeId = Guid.Parse("013387EE-57AF-4ABD-B03C-F991B0722CCA");
|
||||
|
||||
private readonly Guid _contentFourId = Guid.Parse("76D02780-F7D9-49E9-B5C3-3B992ED98F59");
|
||||
|
||||
private IPublishedContentCache _contentCache;
|
||||
private IDocumentUrlService _documentUrlService;
|
||||
|
||||
@@ -39,6 +41,11 @@ public class PublishedContentCacheTests : DeliveryApiTests
|
||||
var contentThreeMock = new Mock<IPublishedContent>();
|
||||
ConfigurePublishedContentMock(contentThreeMock, _contentThreeId, "Content Three", "content-three", contentTypeThreeMock.Object, Array.Empty<IPublishedProperty>());
|
||||
|
||||
var contentTypeFourMock = new Mock<IPublishedContentType>();
|
||||
contentTypeFourMock.SetupGet(m => m.Alias).Returns("theFourthContentType");
|
||||
var contentFourMock = new Mock<IPublishedContent>();
|
||||
ConfigurePublishedContentMock(contentFourMock, _contentFourId, "Content Four", "content-four", contentTypeFourMock.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>()))
|
||||
@@ -49,6 +56,9 @@ public class PublishedContentCacheTests : DeliveryApiTests
|
||||
documentUrlService
|
||||
.Setup(x => x.GetDocumentKeyByRoute("/content-three", It.IsAny<string?>(), 1234, It.IsAny<bool>()))
|
||||
.Returns(_contentThreeId);
|
||||
documentUrlService
|
||||
.Setup(x => x.GetDocumentKeyByRoute("/content-four", It.IsIn("en-US", "da-DK"), It.IsAny<int?>(), It.IsAny<bool>()))
|
||||
.Returns(_contentFourId);
|
||||
|
||||
var contentCacheMock = new Mock<IPublishedContentCache>();
|
||||
contentCacheMock
|
||||
@@ -60,6 +70,9 @@ public class PublishedContentCacheTests : DeliveryApiTests
|
||||
contentCacheMock
|
||||
.Setup(m => m.GetById(It.IsAny<bool>(), _contentThreeId))
|
||||
.Returns(contentThreeMock.Object);
|
||||
contentCacheMock
|
||||
.Setup(m => m.GetById(It.IsAny<bool>(), _contentFourId))
|
||||
.Returns(contentFourMock.Object);
|
||||
|
||||
_contentCache = contentCacheMock.Object;
|
||||
_documentUrlService = documentUrlService.Object;
|
||||
@@ -68,7 +81,7 @@ public class PublishedContentCacheTests : DeliveryApiTests
|
||||
[Test]
|
||||
public void PublishedContentCache_CanGetById()
|
||||
{
|
||||
var publishedContentCache = new ApiPublishedContentCache(CreateRequestPreviewService(), CreateRequestCultureService(), CreateDeliveryApiSettings(), CreateApiDocumentUrlService(), _contentCache);
|
||||
var publishedContentCache = new ApiPublishedContentCache(CreateRequestPreviewService(), CreateDeliveryApiSettings(), CreateApiDocumentUrlService(), _contentCache, CreateVariationContextAccessor());
|
||||
var content = publishedContentCache.GetById(_contentOneId);
|
||||
Assert.IsNotNull(content);
|
||||
Assert.AreEqual(_contentOneId, content.Key);
|
||||
@@ -79,7 +92,7 @@ public class PublishedContentCacheTests : DeliveryApiTests
|
||||
[Test]
|
||||
public void PublishedContentCache_CanGetByRoute()
|
||||
{
|
||||
var publishedContentCache = new ApiPublishedContentCache(CreateRequestPreviewService(), CreateRequestCultureService(), CreateDeliveryApiSettings(), CreateApiDocumentUrlService(), _contentCache);
|
||||
var publishedContentCache = new ApiPublishedContentCache(CreateRequestPreviewService(), CreateDeliveryApiSettings(), CreateApiDocumentUrlService(), _contentCache, CreateVariationContextAccessor());
|
||||
var content = publishedContentCache.GetByRoute("/content-two");
|
||||
Assert.IsNotNull(content);
|
||||
Assert.AreEqual(_contentTwoId, content.Key);
|
||||
@@ -90,7 +103,7 @@ public class PublishedContentCacheTests : DeliveryApiTests
|
||||
[Test]
|
||||
public void PublishedContentCache_CanGetByRoute_WithStartNodeIdPrefix()
|
||||
{
|
||||
var publishedContentCache = new ApiPublishedContentCache(CreateRequestPreviewService(), CreateRequestCultureService(), CreateDeliveryApiSettings(), CreateApiDocumentUrlService(), _contentCache);
|
||||
var publishedContentCache = new ApiPublishedContentCache(CreateRequestPreviewService(), CreateDeliveryApiSettings(), CreateApiDocumentUrlService(), _contentCache, CreateVariationContextAccessor());
|
||||
var content = publishedContentCache.GetByRoute("1234/content-three");
|
||||
Assert.IsNotNull(content);
|
||||
Assert.AreEqual(_contentThreeId, content.Key);
|
||||
@@ -101,7 +114,7 @@ public class PublishedContentCacheTests : DeliveryApiTests
|
||||
[Test]
|
||||
public void PublishedContentCache_CanGetByIds()
|
||||
{
|
||||
var publishedContentCache = new ApiPublishedContentCache(CreateRequestPreviewService(), CreateRequestCultureService(), CreateDeliveryApiSettings(), CreateApiDocumentUrlService(), _contentCache);
|
||||
var publishedContentCache = new ApiPublishedContentCache(CreateRequestPreviewService(), CreateDeliveryApiSettings(), CreateApiDocumentUrlService(), _contentCache, CreateVariationContextAccessor());
|
||||
var content = publishedContentCache.GetByIds(new[] { _contentOneId, _contentTwoId }).ToArray();
|
||||
Assert.AreEqual(2, content.Length);
|
||||
Assert.AreEqual(_contentOneId, content.First().Key);
|
||||
@@ -113,7 +126,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), CreateApiDocumentUrlService(), _contentCache);
|
||||
var publishedContentCache = new ApiPublishedContentCache(CreateRequestPreviewService(), CreateDeliveryApiSettings(denyList), CreateApiDocumentUrlService(), _contentCache, CreateVariationContextAccessor());
|
||||
var content = publishedContentCache.GetById(_contentTwoId);
|
||||
|
||||
if (denied)
|
||||
@@ -131,7 +144,7 @@ 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), CreateApiDocumentUrlService(), _contentCache);
|
||||
var publishedContentCache = new ApiPublishedContentCache(CreateRequestPreviewService(), CreateDeliveryApiSettings(denyList), CreateApiDocumentUrlService(), _contentCache, CreateVariationContextAccessor());
|
||||
var content = publishedContentCache.GetByRoute("/content-one");
|
||||
|
||||
if (denied)
|
||||
@@ -149,7 +162,7 @@ public class PublishedContentCacheTests : DeliveryApiTests
|
||||
public void PublishedContentCache_GetByIds_SupportsDenyList(string deniedContentType)
|
||||
{
|
||||
var denyList = new[] { deniedContentType };
|
||||
var publishedContentCache = new ApiPublishedContentCache(CreateRequestPreviewService(), CreateRequestCultureService(), CreateDeliveryApiSettings(denyList), CreateApiDocumentUrlService(), _contentCache);
|
||||
var publishedContentCache = new ApiPublishedContentCache(CreateRequestPreviewService(), CreateDeliveryApiSettings(denyList), CreateApiDocumentUrlService(), _contentCache, CreateVariationContextAccessor());
|
||||
var content = publishedContentCache.GetByIds(new[] { _contentOneId, _contentTwoId }).ToArray();
|
||||
|
||||
Assert.AreEqual(1, content.Length);
|
||||
@@ -167,7 +180,7 @@ public class PublishedContentCacheTests : DeliveryApiTests
|
||||
public void PublishedContentCache_GetById_CanRetrieveContentTypesOutsideTheDenyList()
|
||||
{
|
||||
var denyList = new[] { "theContentType" };
|
||||
var publishedContentCache = new ApiPublishedContentCache(CreateRequestPreviewService(), CreateRequestCultureService(), CreateDeliveryApiSettings(denyList), CreateApiDocumentUrlService(), _contentCache);
|
||||
var publishedContentCache = new ApiPublishedContentCache(CreateRequestPreviewService(), CreateDeliveryApiSettings(denyList), CreateApiDocumentUrlService(), _contentCache, CreateVariationContextAccessor());
|
||||
var content = publishedContentCache.GetById(_contentTwoId);
|
||||
Assert.IsNotNull(content);
|
||||
Assert.AreEqual(_contentTwoId, content.Key);
|
||||
@@ -179,7 +192,7 @@ public class PublishedContentCacheTests : DeliveryApiTests
|
||||
public void PublishedContentCache_GetByRoute_CanRetrieveContentTypesOutsideTheDenyList()
|
||||
{
|
||||
var denyList = new[] { "theOtherContentType" };
|
||||
var publishedContentCache = new ApiPublishedContentCache(CreateRequestPreviewService(), CreateRequestCultureService(), CreateDeliveryApiSettings(denyList), CreateApiDocumentUrlService(), _contentCache);
|
||||
var publishedContentCache = new ApiPublishedContentCache(CreateRequestPreviewService(), CreateDeliveryApiSettings(denyList), CreateApiDocumentUrlService(), _contentCache, CreateVariationContextAccessor());
|
||||
var content = publishedContentCache.GetByRoute("/content-one");
|
||||
Assert.IsNotNull(content);
|
||||
Assert.AreEqual(_contentOneId, content.Key);
|
||||
@@ -187,11 +200,32 @@ public class PublishedContentCacheTests : DeliveryApiTests
|
||||
Assert.AreEqual("theContentType", content.ContentType.Alias);
|
||||
}
|
||||
|
||||
[TestCase("en-US")]
|
||||
[TestCase("da-DK")]
|
||||
public void PublishedContentCache_GetByRoute_CanRetrieveForCulture(string culture)
|
||||
{
|
||||
var publishedContentCache = new ApiPublishedContentCache(CreateRequestPreviewService(), CreateDeliveryApiSettings(), CreateApiDocumentUrlService(), _contentCache, CreateVariationContextAccessor(culture));
|
||||
var content = publishedContentCache.GetByRoute("/content-four");
|
||||
Assert.IsNotNull(content);
|
||||
Assert.AreEqual(_contentFourId, content.Key);
|
||||
Assert.AreEqual("content-four", content.UrlSegment);
|
||||
Assert.AreEqual("theFourthContentType", content.ContentType.Alias);
|
||||
}
|
||||
|
||||
[TestCase("de-DE")]
|
||||
[TestCase(null)]
|
||||
public void PublishedContentCache_GetByRoute_CannotRetrieveForMissingOrUnknownCulture(string? culture)
|
||||
{
|
||||
var publishedContentCache = new ApiPublishedContentCache(CreateRequestPreviewService(), CreateDeliveryApiSettings(), CreateApiDocumentUrlService(), _contentCache, CreateVariationContextAccessor(culture));
|
||||
var content = publishedContentCache.GetByRoute("/content-four");
|
||||
Assert.IsNull(content);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PublishedContentCache_GetByIds_CanDenyAllRequestedContent()
|
||||
{
|
||||
var denyList = new[] { "theContentType", "theOtherContentType" };
|
||||
var publishedContentCache = new ApiPublishedContentCache(CreateRequestPreviewService(), CreateRequestCultureService(), CreateDeliveryApiSettings(denyList), CreateApiDocumentUrlService(), _contentCache);
|
||||
var publishedContentCache = new ApiPublishedContentCache(CreateRequestPreviewService(), CreateDeliveryApiSettings(denyList), CreateApiDocumentUrlService(), _contentCache, CreateVariationContextAccessor());
|
||||
var content = publishedContentCache.GetByIds(new[] { _contentOneId, _contentTwoId }).ToArray();
|
||||
Assert.IsEmpty(content);
|
||||
}
|
||||
@@ -200,15 +234,15 @@ public class PublishedContentCacheTests : DeliveryApiTests
|
||||
public void PublishedContentCache_DenyListIsCaseInsensitive()
|
||||
{
|
||||
var denyList = new[] { "THEcontentTYPE" };
|
||||
var publishedContentCache = new ApiPublishedContentCache(CreateRequestPreviewService(), CreateRequestCultureService(), CreateDeliveryApiSettings(denyList), CreateApiDocumentUrlService(), _contentCache);
|
||||
var publishedContentCache = new ApiPublishedContentCache(CreateRequestPreviewService(), CreateDeliveryApiSettings(denyList), CreateApiDocumentUrlService(), _contentCache, CreateVariationContextAccessor());
|
||||
var content = publishedContentCache.GetByRoute("/content-one");
|
||||
Assert.IsNull(content);
|
||||
}
|
||||
|
||||
private IRequestCultureService CreateRequestCultureService()
|
||||
private IVariationContextAccessor CreateVariationContextAccessor(string? culture = null)
|
||||
{
|
||||
var mock = new Mock<IRequestCultureService>();
|
||||
|
||||
var mock = new Mock<IVariationContextAccessor>();
|
||||
mock.SetupGet(m => m.VariationContext).Returns(new VariationContext(culture));
|
||||
return mock.Object;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user