Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http;
using Umbraco.Cms.Core.DeliveryApi;

namespace Umbraco.Cms.Api.Delivery.Services;
Expand All @@ -11,5 +11,5 @@ public RequestPreviewService(IHttpContextAccessor httpContextAccessor)
}

/// <inheritdoc />
public bool IsPreview() => GetHeaderValue("Preview") == "true";
public bool IsPreview() => string.Equals(GetHeaderValue("Preview"), "true", StringComparison.OrdinalIgnoreCase);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Microsoft.AspNetCore.Http;
using Moq;
using NUnit.Framework;
using Umbraco.Cms.Api.Delivery.Services;

namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Cms.Api.Delivery.Services;

[TestFixture]
public class RequestPreviewServiceTests
{
[TestCase(null, false)]
[TestCase("", false)]
[TestCase("false", false)]
[TestCase("true", true)]
[TestCase("True", true)]
public void IsPreview_Returns_Expected_Result(string? headerValue, bool expected)
{
var httpContext = new DefaultHttpContext();
httpContext.Request.Headers["Preview"] = headerValue;

var httpContextAccessorMock = new Mock<IHttpContextAccessor>();
httpContextAccessorMock
.Setup(x => x.HttpContext)
.Returns(httpContext);
var sut = new RequestPreviewService(httpContextAccessorMock.Object);

var result = sut.IsPreview();

Assert.AreEqual(expected, result);
}
}
Loading