V10: fix build warnings in test projects (#12509)
* Run code cleanup * Dotnet format benchmarks project * Fix up Test.Common * Run dotnet format + manual cleanup * Run code cleanup for unit tests * Run dotnet format * Fix up errors * Manual cleanup of Unit test project * Update tests/Umbraco.Tests.Benchmarks/HexStringBenchmarks.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update tests/Umbraco.Tests.Integration/Testing/TestDbMeta.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update tests/Umbraco.Tests.Benchmarks/TypeFinderBenchmarks.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update tests/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update tests/Umbraco.Tests.Integration/Umbraco.Core/Events/EventAggregatorTests.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Fix according to review * Fix after merge * Fix errors Co-authored-by: Nikolaj Geisle <niko737@edu.ucl.dk> Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> Co-authored-by: Zeegaan <nge@umbraco.dk>
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
// See LICENSE for more details.
|
||||
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Cms.Core.Configuration.Models;
|
||||
@@ -13,54 +12,55 @@ 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
|
||||
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Web.Website.Controllers;
|
||||
|
||||
[TestFixture]
|
||||
public class RenderNoContentControllerTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class RenderNoContentControllerTests
|
||||
[Test]
|
||||
public void Redirects_To_Root_When_Content_Published()
|
||||
{
|
||||
[Test]
|
||||
public void Redirects_To_Root_When_Content_Published()
|
||||
var mockUmbracoContext = new Mock<IUmbracoContext>();
|
||||
mockUmbracoContext.Setup(x => x.Content.HasContent()).Returns(true);
|
||||
var mockHostingEnvironment = new Mock<IHostingEnvironment>();
|
||||
var controller = new RenderNoContentController(
|
||||
new TestUmbracoContextAccessor(mockUmbracoContext.Object),
|
||||
new TestOptionsSnapshot<GlobalSettings>(new GlobalSettings()),
|
||||
mockHostingEnvironment.Object);
|
||||
|
||||
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);
|
||||
var mockHostingEnvironment = new Mock<IHostingEnvironment>();
|
||||
mockHostingEnvironment.Setup(x => x.ToAbsolute(It.Is<string>(y => y == umbracoPathSetting)))
|
||||
.Returns(umbracoPath);
|
||||
|
||||
var globalSettings = new TestOptionsSnapshot<GlobalSettings>(new GlobalSettings
|
||||
{
|
||||
var mockUmbracoContext = new Mock<IUmbracoContext>();
|
||||
mockUmbracoContext.Setup(x => x.Content.HasContent()).Returns(true);
|
||||
var mockHostingEnvironment = new Mock<IHostingEnvironment>();
|
||||
var controller = new RenderNoContentController(new TestUmbracoContextAccessor(mockUmbracoContext.Object), new TestOptionsSnapshot<GlobalSettings>(new GlobalSettings()), mockHostingEnvironment.Object);
|
||||
UmbracoPath = umbracoPathSetting,
|
||||
NoNodesViewPath = viewPath,
|
||||
});
|
||||
var controller = new RenderNoContentController(new TestUmbracoContextAccessor(mockUmbracoContext.Object), globalSettings, mockHostingEnvironment.Object);
|
||||
|
||||
var result = controller.Index() as RedirectResult;
|
||||
var result = controller.Index() as ViewResult;
|
||||
Assert.IsNotNull(result);
|
||||
Assert.AreEqual(viewPath, result.ViewName);
|
||||
|
||||
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);
|
||||
var mockHostingEnvironment = new Mock<IHostingEnvironment>();
|
||||
mockHostingEnvironment.Setup(x => x.ToAbsolute(It.Is<string>(y => y == UmbracoPathSetting)))
|
||||
.Returns(UmbracoPath);
|
||||
|
||||
|
||||
var globalSettings = new TestOptionsSnapshot<GlobalSettings>(new GlobalSettings()
|
||||
{
|
||||
UmbracoPath = UmbracoPathSetting,
|
||||
NoNodesViewPath = ViewPath,
|
||||
});
|
||||
var controller = new RenderNoContentController(new TestUmbracoContextAccessor(mockUmbracoContext.Object), globalSettings, mockHostingEnvironment.Object);
|
||||
|
||||
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);
|
||||
}
|
||||
var model = result.Model as NoNodesViewModel;
|
||||
Assert.IsNotNull(model);
|
||||
Assert.AreEqual(umbracoPath, model.UmbracoPath);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user