Files
Umbraco-CMS/tests/Umbraco.Tests.UnitTests/Umbraco.Web.Common/FileNameTests.cs
Bjarke Berg 13f6d4791c Move umbraco views to static assets and make that an RCL + Embedded language files (#12324)
* RCL for static assets to replace the nuspec

* Fix build

* Fix unit tests

* clean up in build.ps1

* Removed test (lang files will be removed later anyway)

* Fixed namespaces.. + Ensure we set web root path if missing (e.g. wwwroot folder do not exist) + Added StaticWebAssetBasePath

* fixed namespace

* cleanup

* Set root variable

* Added static assets

* Experimenting with StaticWebAssetBasePath

* Embedded lang files into Umbraco.Core

* Removed legacy test. New test can be implemented instead

* Fixed tests

* clean up

* Fix merge issue
2022-05-02 19:38:33 +02:00

100 lines
3.6 KiB
C#

// Copyright (c) Umbraco.
// See LICENSE for more details.
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using AutoFixture.NUnit3;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
using Microsoft.Extensions.Options;
using Moq;
using NUnit.Framework;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.Hosting;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Tests.UnitTests.AutoFixture;
using Umbraco.Cms.Web.BackOffice.Controllers;
using Umbraco.Cms.Web.BackOffice.Install;
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Web.Common
{
[TestFixture]
internal class FileNameTests
{
private string GetViewName(ViewResult viewResult, string separator = "/")
{
var sections = viewResult.ViewName.Split(separator);
return sections[^1];
}
private IEnumerable<string> GetUiFiles(IEnumerable<string> pathFromNetCore)
{
var root = TestContext.CurrentContext.TestDirectory.Split("tests")[0];
var pathToFiles = Path.Combine(root, "src", "Umbraco.Cms.StaticAssets");
foreach (var pathSection in pathFromNetCore)
{
pathToFiles = Path.Combine(pathToFiles, pathSection);
}
return new DirectoryInfo(pathToFiles).GetFiles().Select(f => f.Name).ToArray();
}
[Test]
[AutoMoqData]
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;
var fileName = GetViewName(viewResult, Path.DirectorySeparatorChar.ToString());
IEnumerable<string> views = GetUiFiles(new[] { "umbraco", "UmbracoInstall" });
Assert.True(views.Contains(fileName), $"Expected {fileName} to exist, but it didn't");
}
[Test]
[AutoMoqData]
public void PreviewViewExists(
[Frozen] IOptions<GlobalSettings> globalSettings,
PreviewController sut)
{
globalSettings.Value.UmbracoPath = "/";
var viewResult = sut.Index() as ViewResult;
var fileName = GetViewName(viewResult);
IEnumerable<string> views = GetUiFiles(new[] { "umbraco", "UmbracoBackOffice" });
Assert.True(views.Contains(fileName), $"Expected {fileName} to exist, but it didn't");
}
[Test]
[AutoMoqData]
public async Task BackOfficeDefaultExists(
[Frozen] IOptions<GlobalSettings> globalSettings,
[Frozen] IHostingEnvironment hostingEnvironment,
[Frozen] ITempDataDictionary tempDataDictionary,
[Frozen] IRuntimeState runtimeState,
BackOfficeController sut)
{
globalSettings.Value.UmbracoPath = "/";
Mock.Get(hostingEnvironment).Setup(x => x.ToAbsolute("/")).Returns("http://localhost/");
Mock.Get(hostingEnvironment).SetupGet(x => x.ApplicationVirtualPath).Returns("/");
Mock.Get(runtimeState).Setup(x => x.Level).Returns(RuntimeLevel.Run);
sut.TempData = tempDataDictionary;
var viewResult = await sut.Default() as ViewResult;
var fileName = GetViewName(viewResult);
IEnumerable<string> views = GetUiFiles(new[] { "umbraco", "UmbracoBackOffice" });
Assert.True(views.Contains(fileName), $"Expected {fileName} to exist, but it didn't");
}
}
}