Add unit test

This commit is contained in:
nikolajlauridsen
2021-10-07 14:12:37 +02:00
parent df1d456c98
commit 11bfef4750
2 changed files with 94 additions and 1 deletions

View File

@@ -0,0 +1,93 @@
using System.Collections.Generic;
using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.Logging.Abstractions;
using Moq;
using NUnit.Framework;
using Umbraco.Cms.Core.Actions;
using Umbraco.Cms.Core.Dictionary;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Mapping;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.PropertyEditors;
using Umbraco.Cms.Core.Routing;
using Umbraco.Cms.Core.Scoping;
using Umbraco.Cms.Core.Security;
using Umbraco.Cms.Core.Serialization;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Strings;
using Umbraco.Cms.Infrastructure.Persistence;
using Umbraco.Cms.Tests.Common.Builders;
using Umbraco.Cms.Tests.Common.Builders.Extensions;
using Umbraco.Cms.Web.BackOffice.Controllers;
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Web.BackOffice.Controllers
{
[TestFixture]
public class ContentControllerTests
{
[Test]
public void Root_Node_With_Domains_Causes_No_Error()
{
// Setup domain service
var domainServiceMock = new Mock<IDomainService>();
domainServiceMock.Setup(x => x.GetAssignedDomains(1060, It.IsAny<bool>()))
.Returns(new List<IDomain>{new UmbracoDomain("/", "da-dk"), new UmbracoDomain("/en", "en-us")});
// Create content type and content
IContentType contentType = new ContentTypeBuilder().WithContentVariation(ContentVariation.Culture).Build();
// Create content, we need to specify and ID configure domain service
Content rootNode = new ContentBuilder()
.WithContentType(contentType)
.WithId(1060)
.AddContentCultureInfosCollection()
.AddCultureInfos()
.WithCultureIso("da-dk")
.Done()
.AddCultureInfos()
.WithCultureIso("en-us")
.Done()
.Done()
.Build();
var culturesPublished = new List<string> { "en-us", "da-dk" };
var publishResult = new PublishResult(new EventMessages(), rootNode);
ContentController contentController = CreateContentController(domainServiceMock.Object);
contentController.VerifyDomainsForCultures(rootNode, culturesPublished, publishResult);
IEnumerable<EventMessage> eventMessages = publishResult.EventMessages.GetAll();
Assert.IsEmpty(eventMessages);
}
private ContentController CreateContentController(IDomainService domainService)
{
var controller = new ContentController(
Mock.Of<ICultureDictionary>(),
NullLoggerFactory.Instance,
Mock.Of<IShortStringHelper>(),
Mock.Of<IEventMessagesFactory>(),
Mock.Of<ILocalizedTextService>(),
new PropertyEditorCollection(new DataEditorCollection(() => null)),
Mock.Of<IContentService>(),
Mock.Of<IUserService>(),
Mock.Of<IBackOfficeSecurityAccessor>(),
Mock.Of<IContentTypeService>(),
Mock.Of<IUmbracoMapper>(),
Mock.Of<IPublishedUrlProvider>(),
domainService,
Mock.Of<IDataTypeService>(),
Mock.Of<ILocalizationService>(),
Mock.Of<IFileService>(),
Mock.Of<INotificationService>(),
new ActionCollection(() => null),
Mock.Of<ISqlContext>(),
Mock.Of<IJsonSerializer>(),
Mock.Of<IScopeProvider>(),
Mock.Of<IAuthorizationService>()
);
return controller;
}
}
}

View File

@@ -1441,7 +1441,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
/// <param name="persistedContent"></param>
/// <param name="culturesPublished"></param>
/// <param name="publishResult"></param>
private void VerifyDomainsForCultures(IContent persistedContent, IEnumerable<string> culturesPublished, PublishResult publishResult)
internal void VerifyDomainsForCultures(IContent persistedContent, IEnumerable<string> culturesPublished, PublishResult publishResult)
{
var publishedCultures = persistedContent.PublishedCultures.ToList();
// If only a single culture is published we shouldn't have any routing issues