|
| 1 | +using Moq; |
| 2 | +using NUnit.Framework; |
| 3 | +using Umbraco.Cms.Api.Management.Services.Signs; |
| 4 | +using Umbraco.Cms.Api.Management.ViewModels.Tree; |
| 5 | +using Umbraco.Cms.Core.Models.Entities; |
| 6 | +using Umbraco.Cms.Core.Services; |
| 7 | + |
| 8 | +namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Cms.Api.Management.Services.Signs; |
| 9 | + |
| 10 | +[TestFixture] |
| 11 | +internal class HasScheduleSignProviderTests |
| 12 | +{ |
| 13 | + [Test] |
| 14 | + public async Task HasScheduleSignProvider_Should_Populate_Signs() |
| 15 | + { |
| 16 | + var entities = new List<EntitySlim> |
| 17 | + { |
| 18 | + new() { Key = Guid.NewGuid(), Name = "Item 1" }, |
| 19 | + new() { Key = Guid.NewGuid(), Name = "Item 2" }, |
| 20 | + }; |
| 21 | + |
| 22 | + var contentServiceMock = new Mock<IContentService>(); |
| 23 | + contentServiceMock |
| 24 | + .Setup(x => x.GetScheduledContentKeys(It.IsAny<IEnumerable<Guid>>())) |
| 25 | + .Returns([entities[1].Key]); |
| 26 | + var sut = new HasScheduleSignProvider(contentServiceMock.Object); |
| 27 | + |
| 28 | + Assert.IsTrue(sut.CanProvideTreeSigns<DocumentTreeItemResponseModel>()); |
| 29 | + |
| 30 | + var viewModels = new List<DocumentTreeItemResponseModel> |
| 31 | + { |
| 32 | + new() { Id = entities[0].Key }, |
| 33 | + new() { Id = entities[1].Key }, |
| 34 | + }; |
| 35 | + |
| 36 | + await sut.PopulateTreeSignsAsync(viewModels.ToArray(), entities); |
| 37 | + |
| 38 | + Assert.AreEqual(viewModels[0].Signs.Count(), 0); |
| 39 | + Assert.AreEqual(viewModels[1].Signs.Count(), 1); |
| 40 | + |
| 41 | + var signModel = viewModels[1].Signs.First(); |
| 42 | + Assert.AreEqual(global::Umbraco.Cms.Core.Constants.System.UmbracoSignProvider, signModel.Provider); |
| 43 | + Assert.AreEqual("ScheduledForPublish", signModel.Alias); |
| 44 | + } |
| 45 | +} |
0 commit comments