Files
Umbraco-CMS/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Routing/PublishedRouterTests.cs
Shannon Deminick c77dc5dc00 Migrating tests that depend on Published Cache from the old test project (#11242)
* starts cleaning up old test project, removing ones we'll never convert, moves new test to where it should be.

* Makes ContentNodeKit immutable properties, moves first nucache tests over

* Gets the Nucache unit tests working and refactors a bit to use builder pattern for models.

* Migrates first xml based cache test to use nucache.

* Migrates a bunch more

* Migrates remaining tests for PublishedContentTests

* Moves PublishedRouterTests

* Moves PublishedContentExtensionTests

* Moves more tests.

* committing wip

* committing wip

* Gets PublishedContentLanguageVariantTests converted and working.

* Fixes DataTable ext method and moves PublishedContentDataTableTests

* Moves PublishedMediaTests

* wip - moving EntityXmlSerializerTests

* Moves more tests

* moves more tests

* moves more tests

* Move another test

* Moves more tests

* Fix test

* move another test

* Moves more tests

* Moves more tests

* Moves more tests

* wip before merge

* More tests

* More tests

* More tests

* More tests

* More tests

* More tests

* Cleanup and moving classes.

* Remove unused code

* Fixed failing tests, due to new null checks, that did not exist in v8

* Avoid breaking changes

* Unbreak more things, even that it the old solution was crazy..

* Fixed bug where ordering of stream readings was changed..

* cleanup

Co-authored-by: Bjarke Berg <mail@bergmania.dk>
2021-10-19 14:11:54 +02:00

89 lines
3.9 KiB
C#

using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Moq;
using NUnit.Framework;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Logging;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Models.PublishedContent;
using Umbraco.Cms.Core.Routing;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Web;
using Umbraco.Cms.Tests.Common;
using Umbraco.Extensions;
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Routing
{
[TestFixture]
public class PublishedRouterTests
{
private PublishedRouter CreatePublishedRouter(IUmbracoContextAccessor umbracoContextAccessor)
=> new PublishedRouter(
Microsoft.Extensions.Options.Options.Create(new WebRoutingSettings()),
new ContentFinderCollection(() => Enumerable.Empty<IContentFinder>()),
new TestLastChanceFinder(),
new TestVariationContextAccessor(),
Mock.Of<IProfilingLogger>(),
Mock.Of<ILogger<PublishedRouter>>(),
Mock.Of<IPublishedUrlProvider>(),
Mock.Of<IRequestAccessor>(),
Mock.Of<IPublishedValueFallback>(),
Mock.Of<IFileService>(),
Mock.Of<IContentTypeService>(),
umbracoContextAccessor,
Mock.Of<IEventAggregator>());
private IUmbracoContextAccessor GetUmbracoContextAccessor()
{
var uri = new Uri("http://example.com");
var umbracoContext = Mock.Of<IUmbracoContext>(x => x.CleanedUmbracoUrl == uri);
var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext);
return umbracoContextAccessor;
}
[Test]
public async Task ConfigureRequest_Returns_False_Without_HasPublishedContent()
{
var umbracoContextAccessor = GetUmbracoContextAccessor();
var publishedRouter = CreatePublishedRouter(umbracoContextAccessor);
var request = await publishedRouter.CreateRequestAsync(umbracoContextAccessor.GetRequiredUmbracoContext().CleanedUmbracoUrl);
var result = publishedRouter.BuildRequest(request);
Assert.IsFalse(result.Success());
}
[Test]
public async Task ConfigureRequest_Returns_False_When_IsRedirect()
{
var umbracoContextAccessor = GetUmbracoContextAccessor();
var publishedRouter = CreatePublishedRouter(umbracoContextAccessor);
var request = await publishedRouter.CreateRequestAsync(umbracoContextAccessor.GetRequiredUmbracoContext().CleanedUmbracoUrl);
var content = GetPublishedContentMock();
request.SetPublishedContent(content.Object);
request.SetCulture("en-AU");
request.SetRedirect("/hello");
var result = publishedRouter.BuildRequest(request);
Assert.IsFalse(result.Success());
}
private Mock<IPublishedContent> GetPublishedContentMock()
{
var pc = new Mock<IPublishedContent>();
pc.Setup(content => content.Id).Returns(1);
pc.Setup(content => content.Name).Returns("test");
pc.Setup(content => content.CreateDate).Returns(DateTime.Now);
pc.Setup(content => content.UpdateDate).Returns(DateTime.Now);
pc.Setup(content => content.Path).Returns("-1,1");
pc.Setup(content => content.Parent).Returns(() => null);
pc.Setup(content => content.Properties).Returns(new Collection<IPublishedProperty>());
pc.Setup(content => content.ContentType).Returns(new PublishedContentType(Guid.NewGuid(), 22, "anything", PublishedItemType.Content, Enumerable.Empty<string>(), Enumerable.Empty<PublishedPropertyType>(), ContentVariation.Nothing));
return pc;
}
}
}