2020-12-20 08:36:11 +01:00
|
|
|
// Copyright (c) Umbraco.
|
|
|
|
|
// See LICENSE for more details.
|
|
|
|
|
|
2017-05-12 14:49:44 +02:00
|
|
|
using NUnit.Framework;
|
2021-02-18 11:06:02 +01:00
|
|
|
using Umbraco.Cms.Core.Strings;
|
|
|
|
|
using Umbraco.Cms.Tests.UnitTests.AutoFixture;
|
|
|
|
|
using Umbraco.Cms.Web.Common.AspNetCore;
|
2017-05-12 14:49:44 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Web.Website;
|
|
|
|
|
|
|
|
|
|
[TestFixture]
|
|
|
|
|
public class AspNetCoreHostingEnvironmentTests
|
2017-05-12 14:49:44 +02:00
|
|
|
{
|
2022-06-21 08:09:38 +02:00
|
|
|
[InlineAutoMoqData("~/Scripts", "/Scripts", null)]
|
|
|
|
|
[InlineAutoMoqData("/Scripts", "/Scripts", null)]
|
|
|
|
|
[InlineAutoMoqData("../Scripts", "/Scripts", typeof(InvalidOperationException))]
|
|
|
|
|
public void IOHelper_ResolveUrl(string input, string expected, Type expectedExceptionType, AspNetCoreHostingEnvironment sut)
|
2017-05-12 14:49:44 +02:00
|
|
|
{
|
2022-06-21 08:09:38 +02:00
|
|
|
if (expectedExceptionType != null)
|
2017-07-20 11:21:28 +02:00
|
|
|
{
|
2022-06-21 08:09:38 +02:00
|
|
|
Assert.Throws(expectedExceptionType, () => sut.ToAbsolute(input));
|
2017-07-20 11:21:28 +02:00
|
|
|
}
|
2022-06-21 08:09:38 +02:00
|
|
|
else
|
2017-05-12 14:49:44 +02:00
|
|
|
{
|
2022-06-21 08:09:38 +02:00
|
|
|
var result = sut.ToAbsolute(input);
|
|
|
|
|
Assert.AreEqual(expected, result);
|
2017-05-12 14:49:44 +02:00
|
|
|
}
|
2022-06-21 08:09:38 +02:00
|
|
|
}
|
2021-08-03 14:04:19 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
[Test]
|
|
|
|
|
public void EnsurePathIsApplicationRootPrefixed()
|
|
|
|
|
{
|
|
|
|
|
// Assert
|
|
|
|
|
Assert.AreEqual("~/Views/Template.cshtml", PathUtility.EnsurePathIsApplicationRootPrefixed("Views/Template.cshtml"));
|
|
|
|
|
Assert.AreEqual("~/Views/Template.cshtml", PathUtility.EnsurePathIsApplicationRootPrefixed("/Views/Template.cshtml"));
|
|
|
|
|
Assert.AreEqual("~/Views/Template.cshtml", PathUtility.EnsurePathIsApplicationRootPrefixed("~/Views/Template.cshtml"));
|
|
|
|
|
}
|
2021-08-03 14:04:19 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
[AutoMoqData]
|
|
|
|
|
[Test]
|
|
|
|
|
public void EnsureApplicationMainUrl(AspNetCoreHostingEnvironment sut)
|
|
|
|
|
{
|
|
|
|
|
var url = new Uri("http://localhost:5000");
|
|
|
|
|
sut.EnsureApplicationMainUrl(url);
|
|
|
|
|
Assert.AreEqual(sut.ApplicationMainUrl, url);
|
2017-05-12 14:49:44 +02:00
|
|
|
}
|
|
|
|
|
}
|