2020-08-26 09:55:14 +02:00
|
|
|
using System.Collections.Generic;
|
2020-08-27 11:31:46 +02:00
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
2020-08-26 09:55:14 +02:00
|
|
|
using System.Threading.Tasks;
|
2020-08-27 11:31:46 +02:00
|
|
|
using AutoFixture.NUnit3;
|
2020-08-26 09:55:14 +02:00
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2020-08-27 11:31:46 +02:00
|
|
|
using Microsoft.AspNetCore.Mvc.ViewFeatures;
|
2020-08-26 09:55:14 +02:00
|
|
|
using Moq;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using Umbraco.Core.Configuration;
|
|
|
|
|
using Umbraco.Core.Hosting;
|
2020-08-27 11:31:46 +02:00
|
|
|
using Umbraco.Tests.UnitTests.AutoFixture;
|
2020-08-26 09:55:14 +02:00
|
|
|
using Umbraco.Web.BackOffice.Controllers;
|
2020-08-27 11:31:46 +02:00
|
|
|
using Umbraco.Web.Common.Install;
|
2020-08-26 09:55:14 +02:00
|
|
|
|
|
|
|
|
namespace Umbraco.Tests.UnitTests.Umbraco.Web.Common
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
2020-08-27 11:31:46 +02:00
|
|
|
internal class FileNameTests
|
2020-08-26 09:55:14 +02:00
|
|
|
{
|
2020-08-27 11:31:46 +02:00
|
|
|
private string GetViewName(ViewResult viewResult, string separator = "/")
|
2020-08-26 09:55:14 +02:00
|
|
|
{
|
2020-08-27 11:31:46 +02:00
|
|
|
var sections = viewResult.ViewName.Split(separator);
|
|
|
|
|
return sections[^1];
|
2020-08-26 09:55:14 +02:00
|
|
|
}
|
|
|
|
|
|
2020-08-27 11:31:46 +02:00
|
|
|
private IEnumerable<string> GetUiFiles(IEnumerable<string> pathFromNetCore)
|
2020-08-26 09:55:14 +02:00
|
|
|
{
|
|
|
|
|
var sourceRoot = TestContext.CurrentContext.TestDirectory.Split("Umbraco.Tests.UnitTests")[0];
|
|
|
|
|
var pathToFiles = Path.Combine(sourceRoot, "Umbraco.Web.UI.NetCore");
|
2020-08-27 11:31:46 +02:00
|
|
|
foreach (var pathSection in pathFromNetCore)
|
2020-08-26 09:55:14 +02:00
|
|
|
{
|
|
|
|
|
pathToFiles = Path.Combine(pathToFiles, pathSection);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new DirectoryInfo(pathToFiles).GetFiles().Select(f => f.Name).ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-27 11:31:46 +02:00
|
|
|
[Test]
|
|
|
|
|
[AutoMoqData]
|
2020-08-26 09:55:14 +02:00
|
|
|
public async Task InstallViewExists(
|
|
|
|
|
[Frozen] IHostingEnvironment hostingEnvironment,
|
|
|
|
|
InstallController sut)
|
|
|
|
|
{
|
|
|
|
|
Mock.Get(hostingEnvironment).Setup(x => x.ToAbsolute(It.IsAny<string>())).Returns("http://localhost/");
|
|
|
|
|
var viewResult = await sut.Index() as ViewResult;
|
2020-08-27 11:31:46 +02:00
|
|
|
var fileName = GetViewName(viewResult, Path.DirectorySeparatorChar.ToString());
|
2020-08-26 09:55:14 +02:00
|
|
|
|
2020-08-27 11:31:46 +02:00
|
|
|
var views = GetUiFiles(new[] { "Umbraco", "UmbracoInstall" });
|
2020-08-26 09:55:14 +02:00
|
|
|
Assert.True(views.Contains(fileName), $"Expected {fileName} to exist, but it didn't");
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-27 11:31:46 +02:00
|
|
|
[Test]
|
|
|
|
|
[AutoMoqData]
|
|
|
|
|
public void PreviewViewExists(
|
2020-08-26 09:55:14 +02:00
|
|
|
[Frozen] IGlobalSettings globalSettings,
|
|
|
|
|
PreviewController sut)
|
|
|
|
|
{
|
|
|
|
|
Mock.Get(globalSettings).Setup(x => x.UmbracoPath).Returns("/");
|
|
|
|
|
|
|
|
|
|
var viewResult = sut.Index() as ViewResult;
|
2020-08-27 11:31:46 +02:00
|
|
|
var fileName = GetViewName(viewResult);
|
2020-08-26 09:55:14 +02:00
|
|
|
|
2020-08-27 11:31:46 +02:00
|
|
|
var views = GetUiFiles(new[] { "Umbraco", "UmbracoBackOffice" });
|
2020-08-26 09:55:14 +02:00
|
|
|
|
|
|
|
|
Assert.True(views.Contains(fileName), $"Expected {fileName} to exist, but it didn't");
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-27 11:31:46 +02:00
|
|
|
[Test]
|
|
|
|
|
[AutoMoqData]
|
2020-08-26 09:55:14 +02:00
|
|
|
public async Task BackOfficeDefaultExists(
|
|
|
|
|
[Frozen] IGlobalSettings globalSettings,
|
|
|
|
|
[Frozen] IHostingEnvironment hostingEnvironment,
|
|
|
|
|
[Frozen] ITempDataDictionary tempDataDictionary,
|
|
|
|
|
BackOfficeController sut)
|
|
|
|
|
{
|
|
|
|
|
Mock.Get(globalSettings).Setup(x => x.UmbracoPath).Returns("/");
|
|
|
|
|
Mock.Get(hostingEnvironment).Setup(x => x.ToAbsolute("/")).Returns("http://localhost/");
|
|
|
|
|
Mock.Get(hostingEnvironment).SetupGet(x => x.ApplicationVirtualPath).Returns("/");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sut.TempData = tempDataDictionary;
|
|
|
|
|
|
|
|
|
|
var viewResult = await sut.Default() as ViewResult;
|
2020-08-27 11:31:46 +02:00
|
|
|
var fileName = GetViewName(viewResult);
|
|
|
|
|
var views = GetUiFiles(new[] { "Umbraco", "UmbracoBackOffice" });
|
2020-08-26 09:55:14 +02:00
|
|
|
|
|
|
|
|
Assert.True(views.Contains(fileName), $"Expected {fileName} to exist, but it didn't");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void LanguageFilesAreLowercase()
|
|
|
|
|
{
|
2020-08-27 11:31:46 +02:00
|
|
|
var files = GetUiFiles(new[] { "Umbraco", "config", "lang" });
|
2020-08-26 09:55:14 +02:00
|
|
|
foreach (var fileName in files)
|
|
|
|
|
{
|
2020-08-27 11:31:46 +02:00
|
|
|
Assert.AreEqual(fileName.ToLower(), fileName,
|
|
|
|
|
$"Language files must be all lowercase but {fileName} is not lowercase.");
|
2020-08-26 09:55:14 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|