* Update gitignore * Move csproj * Update project references * Update solutions * Update build scripts * Tests used to share editorconfig with projects in src * Fix broken tests. * Stop copying around .editorconfig merged root one with linting * csharp_style_expression_bodied -> suggestion * Move StyleCop rulesets to matching directories and update shared build properties * Remove legacy build files, update NuGet.cofig and solution files * Restore myget source * Clean up .gitignore * Update .gitignore * Move new test classes to tests after merge * Gitignore + nuget config * Move new test Co-authored-by: Ronald Barendse <ronald@barend.se>
62 lines
2.4 KiB
C#
62 lines
2.4 KiB
C#
// Copyright (c) Umbraco.
|
|
// See LICENSE for more details.
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.Options;
|
|
using Moq;
|
|
using NUnit.Framework;
|
|
using Umbraco.Cms.Core.Configuration.Models;
|
|
using Umbraco.Cms.Core.IO;
|
|
using Umbraco.Cms.Core.Web;
|
|
using Umbraco.Cms.Tests.Common;
|
|
using Umbraco.Cms.Web.Website.Controllers;
|
|
using Umbraco.Cms.Web.Website.Models;
|
|
|
|
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Web.Website.Controllers
|
|
{
|
|
[TestFixture]
|
|
public class RenderNoContentControllerTests
|
|
{
|
|
[Test]
|
|
public void Redirects_To_Root_When_Content_Published()
|
|
{
|
|
var mockUmbracoContext = new Mock<IUmbracoContext>();
|
|
mockUmbracoContext.Setup(x => x.Content.HasContent()).Returns(true);
|
|
var mockIOHelper = new Mock<IIOHelper>();
|
|
var controller = new RenderNoContentController(new TestUmbracoContextAccessor(mockUmbracoContext.Object), mockIOHelper.Object, Options.Create(new GlobalSettings()));
|
|
|
|
var result = controller.Index() as RedirectResult;
|
|
|
|
Assert.IsNotNull(result);
|
|
Assert.AreEqual("~/", result.Url);
|
|
}
|
|
|
|
[Test]
|
|
public void Renders_View_When_No_Content_Published()
|
|
{
|
|
const string UmbracoPathSetting = "~/umbraco";
|
|
const string UmbracoPath = "/umbraco";
|
|
const string ViewPath = "~/config/splashes/NoNodes.cshtml";
|
|
var mockUmbracoContext = new Mock<IUmbracoContext>();
|
|
mockUmbracoContext.Setup(x => x.Content.HasContent()).Returns(false);
|
|
var mockIOHelper = new Mock<IIOHelper>();
|
|
mockIOHelper.Setup(x => x.ResolveUrl(It.Is<string>(y => y == UmbracoPathSetting))).Returns(UmbracoPath);
|
|
|
|
IOptions<GlobalSettings> globalSettings = Options.Create(new GlobalSettings()
|
|
{
|
|
UmbracoPath = UmbracoPathSetting,
|
|
NoNodesViewPath = ViewPath,
|
|
});
|
|
var controller = new RenderNoContentController(new TestUmbracoContextAccessor(mockUmbracoContext.Object), mockIOHelper.Object, globalSettings);
|
|
|
|
var result = controller.Index() as ViewResult;
|
|
Assert.IsNotNull(result);
|
|
Assert.AreEqual(ViewPath, result.ViewName);
|
|
|
|
var model = result.Model as NoNodesViewModel;
|
|
Assert.IsNotNull(model);
|
|
Assert.AreEqual(UmbracoPath, model.UmbracoPath);
|
|
}
|
|
}
|
|
}
|