2020-12-23 11:35:49 +01:00
// Copyright (c) Umbraco.
// See LICENSE for more details.
2020-12-27 09:50:56 +01:00
#pragma warning disable SA1124 // Do not use regions (justification: regions are currently adding some useful organisation to this file)
2020-12-23 13:57:41 +11:00
using Microsoft.Extensions.Logging ;
2016-05-27 11:34:03 +02:00
using NUnit.Framework ;
2021-03-12 21:48:24 +01:00
using Umbraco.Cms.Core ;
2021-02-09 10:22:42 +01:00
using Umbraco.Cms.Core.Cache ;
2021-03-12 21:48:24 +01:00
using Umbraco.Cms.Core.Events ;
2021-02-09 10:22:42 +01:00
using Umbraco.Cms.Core.Models ;
2021-05-11 14:33:49 +02:00
using Umbraco.Cms.Core.Notifications ;
2021-04-20 12:17:11 +02:00
using Umbraco.Cms.Core.Persistence.Repositories ;
2021-02-09 10:22:42 +01:00
using Umbraco.Cms.Core.Sync ;
using Umbraco.Cms.Core.Web ;
2024-03-01 12:51:21 +01:00
using Umbraco.Cms.Infrastructure.Serialization ;
2021-02-15 12:54:13 +01:00
using Umbraco.Cms.Infrastructure.Sync ;
2023-09-12 14:16:27 +02:00
using Umbraco.Cms.Tests.Common.Attributes ;
2021-02-10 14:45:44 +01:00
using Umbraco.Cms.Tests.Common.Builders ;
using Umbraco.Cms.Tests.Common.Testing ;
2021-02-11 08:30:27 +01:00
using Umbraco.Cms.Tests.Integration.Testing ;
2016-05-27 11:34:03 +02:00
2021-02-11 08:30:27 +01:00
namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services
2016-05-27 11:34:03 +02:00
{
2017-12-02 16:14:21 +01:00
[TestFixture]
2016-11-05 19:23:55 +01:00
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)]
2020-10-14 11:08:55 +02:00
public class ContentEventsTests : UmbracoIntegrationTestWithContent
2016-05-27 11:34:03 +02:00
{
2020-10-14 11:08:55 +02:00
private CacheRefresherCollection CacheRefresherCollection = > GetRequiredService < CacheRefresherCollection > ( ) ;
2020-12-23 13:57:41 +11:00
2020-12-23 11:35:49 +01:00
private IUmbracoContextFactory UmbracoContextFactory = > GetRequiredService < IUmbracoContextFactory > ( ) ;
2016-05-27 11:34:03 +02:00
2020-12-23 11:35:49 +01:00
private ILogger < ContentEventsTests > Logger = > GetRequiredService < ILogger < ContentEventsTests > > ( ) ;
2020-12-27 09:50:56 +01:00
#region Setup
2021-04-20 12:17:11 +02:00
private class TestNotificationHandler :
INotificationHandler < ContentCacheRefresherNotification > ,
INotificationHandler < ContentDeletedNotification > ,
INotificationHandler < ContentDeletingVersionsNotification > ,
INotificationHandler < ContentRefreshNotification >
2021-03-12 21:48:24 +01:00
{
2021-04-20 12:17:11 +02:00
private readonly IDocumentRepository _documentRepository ;
public TestNotificationHandler ( IDocumentRepository documentRepository )
{
_documentRepository = documentRepository ;
}
2021-03-12 21:48:24 +01:00
public void Handle ( ContentCacheRefresherNotification args )
{
// reports the event as: "ContentCache/<action>,<action>.../X
// where
// <action> is(are) the action(s)
// X is the event content ID
if ( args . MessageType ! = MessageType . RefreshByPayload )
{
throw new NotSupportedException ( ) ;
}
2021-04-12 16:13:22 +02:00
// We're in between tests, don't do anything.
if ( _events is null )
{
return ;
}
2021-03-12 21:48:24 +01:00
foreach ( ContentCacheRefresher . JsonPayload payload in ( ContentCacheRefresher . JsonPayload [ ] ) args . MessageObject )
{
var e = new EventInstance
{
Message = _msgCount ,
Sender = "ContentCacheRefresher" ,
EventArgs = payload ,
Name = payload . ChangeTypes . ToString ( ) . Replace ( " " , string . Empty ) ,
Args = payload . Id . ToInvariantString ( )
} ;
_events . Add ( e ) ;
}
_msgCount + + ;
}
2021-04-20 12:17:11 +02:00
public void Handle ( ContentDeletedNotification notification )
{
// reports the event as : "ContentRepository/Remove/X"
// where
// X is the event content ID
var e = new EventInstance
{
Message = _msgCount + + ,
Sender = "ContentRepository" ,
EventArgs = null , // Notification has no event args
Name = "Remove" ,
Args = string . Join ( "," , notification . DeletedEntities . Select ( x = > x . Id ) )
} ;
_events . Add ( e ) ;
}
public void Handle ( ContentDeletingVersionsNotification notification )
{
// reports the event as : "ContentRepository/Remove/X:Y"
// where
// X is the event content ID
// Y is the event content version GUID
var e = new EventInstance
{
Message = _msgCount + + ,
Sender = "ContentRepository" ,
EventArgs = null , // Notification has no args
Name = "RemoveVersion" ,
Args = $"{notification.Id}:{notification.SpecificVersion}"
} ;
_events . Add ( e ) ;
}
public void Handle ( ContentRefreshNotification notification )
{
// reports the event as : "ContentRepository/Refresh/XY-Z"
// where
// X can be u (unpublished) or p (published) and is the state of the event content
// Y can be u (unchanged), x (unpublishing), p (published) or m (masked) and is the state of the published version
// Z is the event content ID
// reports the event as "ContentRepository/Refresh/id.xyz
// where
// id is the event content identifier
// x is u|p and is the (un)published state of the event content
// y is +|-|= and is the action (publish, unpublish, no change)
// z is u|p|m and is the (un)published state after the event
if ( _events is null )
{
return ;
}
IContent [ ] entities = new [ ] { notification . Entity } ; // args.Entities
var e = new EventInstance
{
Message = _msgCount + + ,
Sender = "ContentRepository" ,
Name = "Refresh" ,
Args = string . Join ( "," , entities . Select ( x = >
{
PublishedState publishedState = ( ( Content ) x ) . PublishedState ;
string xstate = x . Published ? "p" : "u" ;
if ( publishedState = = PublishedState . Publishing )
{
xstate + = "+" + ( x . ParentId = = - 1 | | _documentRepository . IsPathPublished ( _documentRepository . Get ( x . ParentId ) ) ? "p" : "m" ) ;
}
else if ( publishedState = = PublishedState . Unpublishing )
{
xstate + = "-u" ;
}
else
{
2022-06-21 08:09:38 +02:00
xstate + = "=" + ( x . Published ? _documentRepository . IsPathPublished ( x ) ? "p" : "m" : "u" ) ;
2021-04-20 12:17:11 +02:00
}
return $"{x.Id}.{xstate}" ;
} ) )
} ;
_events . Add ( e ) ;
}
2021-03-12 21:48:24 +01:00
}
protected override void CustomTestSetup ( IUmbracoBuilder builder )
{
2024-10-01 15:03:02 +02:00
builder . AddUmbracoHybridCache ( ) ;
2021-04-12 16:13:22 +02:00
builder . Services . AddUnique < IServerMessenger , LocalServerMessenger > ( ) ;
2021-04-20 12:17:11 +02:00
builder . Services . AddUnique < IServerMessenger , LocalServerMessenger > ( ) ;
builder
. AddNotificationHandler < ContentCacheRefresherNotification , TestNotificationHandler > ( )
. AddNotificationHandler < ContentDeletedNotification , TestNotificationHandler > ( )
. AddNotificationHandler < ContentDeletingVersionsNotification , TestNotificationHandler > ( )
. AddNotificationHandler < ContentRefreshNotification , TestNotificationHandler > ( )
;
2023-06-20 11:15:47 +02:00
builder . AddNotificationHandler < ContentTreeChangeNotification , ContentTreeChangeDistributedCacheNotificationHandler > ( ) ;
2021-03-12 21:48:24 +01:00
}
2020-10-14 11:08:55 +02:00
[SetUp]
public void SetUp ( )
2016-05-27 11:34:03 +02:00
{
_events = new List < EventInstance > ( ) ;
2020-10-14 11:08:55 +02:00
// prepare content type
2020-12-23 11:35:49 +01:00
Template template = TemplateBuilder . CreateTextPageTemplate ( ) ;
2020-10-14 11:08:55 +02:00
FileService . SaveTemplate ( template ) ;
2016-08-23 11:17:08 +02:00
2020-10-14 11:08:55 +02:00
_contentType = ContentTypeBuilder . CreateSimpleContentType ( "whatever" , "Whatever" , defaultTemplateId : template . Id ) ;
_contentType . Key = Guid . NewGuid ( ) ;
FileService . SaveTemplate ( _contentType . DefaultTemplate ) ;
ContentTypeService . Save ( _contentType ) ;
2016-05-27 11:34:03 +02:00
}
2021-03-12 21:48:24 +01:00
private static IList < EventInstance > _events ;
private static int _msgCount ;
2016-05-27 11:34:03 +02:00
private IContentType _contentType ;
private void ResetEvents ( )
{
_events = new List < EventInstance > ( ) ;
_msgCount = 0 ;
2020-10-14 11:08:55 +02:00
Logger . LogDebug ( "RESET EVENTS" ) ;
2016-05-27 11:34:03 +02:00
}
private IContent CreateContent ( int parentId = - 1 )
{
2020-12-23 11:35:49 +01:00
Content content1 = ContentBuilder . CreateSimpleContent ( _contentType , "Content1" , parentId ) ;
2020-10-14 11:08:55 +02:00
ContentService . Save ( content1 ) ;
2016-05-27 11:34:03 +02:00
return content1 ;
}
private IContent CreateBranch ( )
{
2020-12-23 11:35:49 +01:00
Content content1 = ContentBuilder . CreateSimpleContent ( _contentType , "Content1" ) ;
2023-11-22 12:52:08 +01:00
ContentService . Save ( content1 ) ;
ContentService . Publish ( content1 , content1 . AvailableCultures . ToArray ( ) ) ;
2016-05-27 11:34:03 +02:00
// 2 (published)
// .1 (published)
// .2 (not published)
2020-12-23 11:35:49 +01:00
Content content2 = ContentBuilder . CreateSimpleContent ( _contentType , "Content2" , content1 ) ;
2023-11-22 12:52:08 +01:00
ContentService . Save ( content2 ) ;
ContentService . Publish ( content2 , content2 . AvailableCultures . ToArray ( ) ) ;
2020-12-23 11:35:49 +01:00
Content content21 = ContentBuilder . CreateSimpleContent ( _contentType , "Content21" , content2 ) ;
2023-11-22 12:52:08 +01:00
ContentService . Save ( content21 ) ;
ContentService . Publish ( content21 , content21 . AvailableCultures . ToArray ( ) ) ;
2020-12-23 11:35:49 +01:00
Content content22 = ContentBuilder . CreateSimpleContent ( _contentType , "Content22" , content2 ) ;
2020-10-14 11:08:55 +02:00
ContentService . Save ( content22 ) ;
2016-05-27 11:34:03 +02:00
// 3 (not published)
// .1 (not published)
// .2 (not published)
2020-12-23 11:35:49 +01:00
Content content3 = ContentBuilder . CreateSimpleContent ( _contentType , "Content3" , content1 ) ;
2020-10-14 11:08:55 +02:00
ContentService . Save ( content3 ) ;
2020-12-23 11:35:49 +01:00
Content content31 = ContentBuilder . CreateSimpleContent ( _contentType , "Content31" , content3 ) ;
2020-10-14 11:08:55 +02:00
ContentService . Save ( content31 ) ;
2020-12-23 11:35:49 +01:00
Content content32 = ContentBuilder . CreateSimpleContent ( _contentType , "Content32" , content3 ) ;
2020-10-14 11:08:55 +02:00
ContentService . Save ( content32 ) ;
2016-05-27 11:34:03 +02:00
// 4 (published + saved)
// .1 (published)
// .2 (not published)
2020-12-23 11:35:49 +01:00
Content content4 = ContentBuilder . CreateSimpleContent ( _contentType , "Content4" , content1 ) ;
2023-11-22 12:52:08 +01:00
ContentService . Save ( content4 ) ;
ContentService . Publish ( content4 , content4 . AvailableCultures . ToArray ( ) ) ;
2016-05-27 11:34:03 +02:00
content4 . Name = "Content4X" ;
2020-10-14 11:08:55 +02:00
ContentService . Save ( content4 ) ;
2020-12-23 11:35:49 +01:00
Content content41 = ContentBuilder . CreateSimpleContent ( _contentType , "Content41" , content4 ) ;
2023-11-22 12:52:08 +01:00
ContentService . Save ( content41 ) ;
ContentService . Publish ( content41 , content41 . AvailableCultures . ToArray ( ) ) ;
2020-12-23 11:35:49 +01:00
Content content42 = ContentBuilder . CreateSimpleContent ( _contentType , "Content42" , content4 ) ;
2020-10-14 11:08:55 +02:00
ContentService . Save ( content42 ) ;
2016-05-27 11:34:03 +02:00
// 5 (not published)
// .1 (published)
// .2 (not published)
2020-12-23 11:35:49 +01:00
Content content5 = ContentBuilder . CreateSimpleContent ( _contentType , "Content5" , content1 ) ;
2023-11-22 12:52:08 +01:00
ContentService . Save ( content5 ) ;
ContentService . Publish ( content5 , content5 . AvailableCultures . ToArray ( ) ) ;
2020-12-23 11:35:49 +01:00
Content content51 = ContentBuilder . CreateSimpleContent ( _contentType , "Content51" , content5 ) ;
2023-11-22 12:52:08 +01:00
ContentService . Save ( content51 ) ;
ContentService . Publish ( content51 , content51 . AvailableCultures . ToArray ( ) ) ;
2020-12-23 11:35:49 +01:00
Content content52 = ContentBuilder . CreateSimpleContent ( _contentType , "Content52" , content5 ) ;
2020-10-14 11:08:55 +02:00
ContentService . Save ( content52 ) ;
ContentService . Unpublish ( content5 ) ;
2016-05-27 11:34:03 +02:00
return content1 ;
}
2020-12-27 09:50:56 +01:00
#endregion
#region Validate Setup
2018-06-22 21:03:47 +02:00
[Test]
2023-09-12 14:16:27 +02:00
[LongRunning]
2018-06-22 21:03:47 +02:00
public void CreatedBranchIsOk ( )
{
2020-12-23 11:35:49 +01:00
IContent content1 = CreateBranch ( ) ;
2018-06-22 21:03:47 +02:00
2020-12-23 11:35:49 +01:00
IContent [ ] children1 = Children ( content1 ) . ToArray ( ) ;
2018-06-22 21:03:47 +02:00
2020-12-23 11:35:49 +01:00
IContent content2 = children1 [ 0 ] ;
IContent [ ] children2 = Children ( content2 ) . ToArray ( ) ;
IContent content21 = children2 [ 0 ] ;
IContent content22 = children2 [ 1 ] ;
2018-06-22 21:03:47 +02:00
2020-12-23 11:35:49 +01:00
IContent content3 = children1 [ 1 ] ;
IContent [ ] children3 = Children ( content3 ) . ToArray ( ) ;
IContent content31 = children3 [ 0 ] ;
IContent content32 = children3 [ 1 ] ;
2018-06-22 21:03:47 +02:00
2020-12-23 11:35:49 +01:00
IContent content4 = children1 [ 2 ] ;
IContent [ ] children4 = Children ( content4 ) . ToArray ( ) ;
IContent content41 = children4 [ 0 ] ;
IContent content42 = children4 [ 1 ] ;
2018-06-22 21:03:47 +02:00
2020-12-23 11:35:49 +01:00
IContent content5 = children1 [ 3 ] ;
IContent [ ] children5 = Children ( content5 ) . ToArray ( ) ;
IContent content51 = children5 [ 0 ] ;
IContent content52 = children5 [ 1 ] ;
2018-06-22 21:03:47 +02:00
Assert . IsTrue ( content1 . Published ) ;
Assert . IsFalse ( content1 . Edited ) ;
Assert . IsTrue ( content2 . Published ) ;
Assert . IsFalse ( content2 . Edited ) ;
Assert . IsTrue ( content21 . Published ) ;
Assert . IsFalse ( content21 . Edited ) ;
Assert . IsFalse ( content22 . Published ) ;
Assert . IsTrue ( content22 . Edited ) ;
Assert . IsFalse ( content3 . Published ) ;
Assert . IsTrue ( content3 . Edited ) ;
Assert . IsFalse ( content31 . Published ) ;
Assert . IsTrue ( content31 . Edited ) ;
Assert . IsFalse ( content32 . Published ) ;
Assert . IsTrue ( content32 . Edited ) ;
Assert . IsTrue ( content4 . Published ) ;
Assert . IsTrue ( content4 . Edited ) ;
Assert . IsTrue ( content41 . Published ) ;
Assert . IsFalse ( content41 . Edited ) ;
Assert . IsFalse ( content42 . Published ) ;
Assert . IsTrue ( content42 . Edited ) ;
Assert . IsFalse ( content5 . Published ) ;
Assert . IsTrue ( content5 . Edited ) ;
Assert . IsTrue ( content51 . Published ) ;
Assert . IsFalse ( content51 . Edited ) ;
Assert . IsFalse ( content52 . Published ) ;
Assert . IsTrue ( content52 . Edited ) ;
}
2020-12-27 09:50:56 +01:00
#endregion
#region Events tracer
2016-05-27 11:34:03 +02:00
private class EventInstance
{
2017-12-02 16:14:21 +01:00
public int Message { get ; set ; }
2020-12-23 11:35:49 +01:00
2016-05-27 11:34:03 +02:00
public string Sender { get ; set ; }
2020-12-23 11:35:49 +01:00
2016-05-27 11:34:03 +02:00
public string Name { get ; set ; }
2020-12-23 11:35:49 +01:00
2016-05-27 11:34:03 +02:00
public string Args { get ; set ; }
2020-12-23 11:35:49 +01:00
2016-05-27 11:34:03 +02:00
public object EventArgs { get ; set ; }
2020-12-23 11:35:49 +01:00
public override string ToString ( ) = > $"{Message:000}: {Sender.Replace(" ", string.Empty)}/{Name}/{Args}" ;
2016-05-27 11:34:03 +02:00
}
2022-06-21 08:09:38 +02:00
private static readonly string [ ] _propertiesImpactingAllVersions = { "SortOrder" , "ParentId" , "Level" , "Path" , "Trashed" } ;
2016-05-27 11:34:03 +02:00
private static bool HasChangesImpactingAllVersions ( IContent icontent )
{
var content = ( Content ) icontent ;
// UpdateDate will be dirty
// Published may be dirty if saving a Published entity
// so cannot do this (would always be true):
2020-12-27 09:50:56 +01:00
////return content.IsEntityDirty();
2016-05-27 11:34:03 +02:00
// have to be more precise & specify properties
2022-06-21 08:09:38 +02:00
return _propertiesImpactingAllVersions . Any ( content . IsPropertyDirty ) ;
2016-05-27 11:34:03 +02:00
}
2017-07-18 19:24:27 +02:00
private void WriteEvents ( )
{
Console . WriteLine ( "EVENTS" ) ;
2020-12-23 11:35:49 +01:00
foreach ( EventInstance e in _events )
{
2017-07-18 19:24:27 +02:00
Console . WriteLine ( e ) ;
2020-12-23 11:35:49 +01:00
}
2017-07-18 19:24:27 +02:00
}
2020-12-27 09:50:56 +01:00
#endregion
#region Utils
2017-12-02 16:14:21 +01:00
private IEnumerable < IContent > Children ( IContent content )
2022-06-21 08:09:38 +02:00
= > ContentService . GetPagedChildren ( content . Id , 0 , int . MaxValue , out _ ) ;
2016-05-27 11:34:03 +02:00
2020-12-27 09:50:56 +01:00
#endregion
#region Save , Publish & Unpublish single content
2016-05-27 11:34:03 +02:00
[Test]
2023-09-12 14:16:27 +02:00
[LongRunning]
2016-05-27 11:34:03 +02:00
public void SaveUnpublishedContent ( )
{
// rule: when a content is saved,
2017-12-02 16:14:21 +01:00
// - repository : refresh u=u
// - content cache : refresh newest
2020-12-23 11:35:49 +01:00
IContent content = ContentService . GetRootContent ( ) . FirstOrDefault ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content ) ;
ResetEvents ( ) ;
content . Name = "changed" ;
2020-10-14 11:08:55 +02:00
ContentService . Save ( content ) ;
2016-05-27 11:34:03 +02:00
Assert . AreEqual ( 2 , _msgCount ) ;
Assert . AreEqual ( 2 , _events . Count ) ;
2020-12-23 11:35:49 +01:00
int i = 0 ;
int m = 0 ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentRepository/Refresh/{content.Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
m + + ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentCacheRefresher/RefreshNode/{content.Id}" , _events [ i ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
}
[Test]
2023-09-12 14:16:27 +02:00
[LongRunning]
2016-05-27 11:34:03 +02:00
public void SavePublishedContent_ContentProperty1 ( )
{
// rule: when a content is saved,
// - repository : refresh (u)
// - content cache :: refresh newest
2020-12-23 11:35:49 +01:00
IContent content = ContentService . GetRootContent ( ) . FirstOrDefault ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content ) ;
2023-11-22 12:52:08 +01:00
ContentService . Publish ( content , content . AvailableCultures . ToArray ( ) ) ;
2016-05-27 11:34:03 +02:00
ResetEvents ( ) ;
content . Name = "changed" ;
2020-10-14 11:08:55 +02:00
ContentService . Save ( content ) ;
2016-05-27 11:34:03 +02:00
Assert . AreEqual ( 2 , _msgCount ) ;
Assert . AreEqual ( 2 , _events . Count ) ;
2020-12-23 11:35:49 +01:00
int i = 0 ;
int m = 0 ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentRepository/Refresh/{content.Id}.p=p" , _events [ i + + ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
m + + ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentCacheRefresher/RefreshNode/{content.Id}" , _events [ i ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
ResetEvents ( ) ;
content . Name = "again" ;
2020-10-14 11:08:55 +02:00
ContentService . Save ( content ) ;
2016-05-27 11:34:03 +02:00
Assert . AreEqual ( 2 , _msgCount ) ;
Assert . AreEqual ( 2 , _events . Count ) ;
i = 0 ;
m = 0 ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentRepository/Refresh/{content.Id}.p=p" , _events [ i + + ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
m + + ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentCacheRefresher/RefreshNode/{content.Id}" , _events [ i ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
}
[Test]
2023-09-12 14:16:27 +02:00
[LongRunning]
2016-05-27 11:34:03 +02:00
public void SavePublishedContent_ContentProperty2 ( )
{
// rule: when a content is saved,
// - repository : refresh (u)
// - content cache :: refresh newest
2020-12-23 11:35:49 +01:00
IContent content = ContentService . GetRootContent ( ) . FirstOrDefault ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content ) ;
2023-11-22 12:52:08 +01:00
ContentService . Publish ( content , content . AvailableCultures . ToArray ( ) ) ;
2016-05-27 11:34:03 +02:00
ResetEvents ( ) ;
content . SortOrder = 666 ;
2020-10-14 11:08:55 +02:00
ContentService . Save ( content ) ;
2016-05-27 11:34:03 +02:00
Assert . AreEqual ( 2 , _msgCount ) ;
Assert . AreEqual ( 2 , _events . Count ) ;
2020-12-23 11:35:49 +01:00
int i = 0 ;
int m = 0 ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentRepository/Refresh/{content.Id}.p=p" , _events [ i + + ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
m + + ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentCacheRefresher/RefreshNode/{content.Id}" , _events [ i ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
ResetEvents ( ) ;
content . SortOrder = 667 ;
2020-10-14 11:08:55 +02:00
ContentService . Save ( content ) ;
2016-05-27 11:34:03 +02:00
Assert . AreEqual ( 2 , _msgCount ) ;
Assert . AreEqual ( 2 , _events . Count ) ;
i = 0 ;
m = 0 ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentRepository/Refresh/{content.Id}.p=p" , _events [ i + + ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
m + + ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentCacheRefresher/RefreshNode/{content.Id}" , _events [ i ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
}
[Test]
2023-09-12 14:16:27 +02:00
[LongRunning]
2016-05-27 11:34:03 +02:00
public void SavePublishedContent_UserProperty ( )
{
// rule: when a content is saved,
// - repository : refresh (u)
// - content cache :: refresh newest
2020-12-23 11:35:49 +01:00
IContent content = ContentService . GetRootContent ( ) . FirstOrDefault ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content ) ;
2023-11-22 12:52:08 +01:00
ContentService . Publish ( content , content . AvailableCultures . ToArray ( ) ) ;
2016-05-27 11:34:03 +02:00
ResetEvents ( ) ;
2017-11-07 19:49:14 +01:00
content . Properties . First ( ) . SetValue ( "changed" ) ;
2020-10-14 11:08:55 +02:00
ContentService . Save ( content ) ;
2016-05-27 11:34:03 +02:00
Assert . AreEqual ( 2 , _msgCount ) ;
Assert . AreEqual ( 2 , _events . Count ) ;
2020-12-23 11:35:49 +01:00
int i = 0 ;
int m = 0 ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentRepository/Refresh/{content.Id}.p=p" , _events [ i + + ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
m + + ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentCacheRefresher/RefreshNode/{content.Id}" , _events [ i ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
ResetEvents ( ) ;
2017-11-07 19:49:14 +01:00
content . Properties . First ( ) . SetValue ( "again" ) ;
2020-10-14 11:08:55 +02:00
ContentService . Save ( content ) ;
2016-05-27 11:34:03 +02:00
Assert . AreEqual ( 2 , _msgCount ) ;
Assert . AreEqual ( 2 , _events . Count ) ;
i = 0 ;
m = 0 ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentRepository/Refresh/{content.Id}.p=p" , _events [ i + + ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
m + + ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentCacheRefresher/RefreshNode/{content.Id}" , _events [ i ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
}
[Test]
2023-09-12 14:16:27 +02:00
[LongRunning]
2016-05-27 11:34:03 +02:00
public void SaveAndPublishUnpublishedContent ( )
{
// rule: when a content is saved&published,
// - repository : refresh (p)
// - content cache :: refresh published, newest
2020-12-23 11:35:49 +01:00
IContent content = ContentService . GetRootContent ( ) . FirstOrDefault ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content ) ;
ResetEvents ( ) ;
content . Name = "changed" ;
2023-11-22 12:52:08 +01:00
ContentService . Save ( content ) ;
ContentService . Publish ( content , Array . Empty < string > ( ) ) ;
2016-05-27 11:34:03 +02:00
2023-11-22 12:52:08 +01:00
Assert . AreEqual ( 4 , _msgCount ) ;
Assert . AreEqual ( 4 , _events . Count ) ;
2020-12-23 11:35:49 +01:00
int i = 0 ;
int m = 0 ;
2023-11-22 12:52:08 +01:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content.Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentCacheRefresher/RefreshNode/{content.Id}" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content.Id}.u+p" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentCacheRefresher/RefreshBranch/{content.Id}" , _events [ i + + ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
}
[Test]
2023-09-12 14:16:27 +02:00
[LongRunning]
2016-05-27 11:34:03 +02:00
public void SaveAndPublishPublishedContent ( )
{
// rule: when a content is saved&published,
// - repository : refresh (p)
// - content cache :: refresh published, newest
2020-12-23 11:35:49 +01:00
IContent content = ContentService . GetRootContent ( ) . FirstOrDefault ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content ) ;
2023-11-22 12:52:08 +01:00
ContentService . Publish ( content , content . AvailableCultures . ToArray ( ) ) ;
2016-05-27 11:34:03 +02:00
ResetEvents ( ) ;
content . Name = "changed" ;
2023-11-22 12:52:08 +01:00
ContentService . Save ( content ) ;
ContentService . Publish ( content , Array . Empty < string > ( ) ) ;
2016-05-27 11:34:03 +02:00
2023-11-22 12:52:08 +01:00
Assert . AreEqual ( 4 , _msgCount ) ;
Assert . AreEqual ( 4 , _events . Count ) ;
2020-12-23 11:35:49 +01:00
int i = 0 ;
int m = 0 ;
2023-11-22 12:52:08 +01:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content.Id}.p=p" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentCacheRefresher/RefreshNode/{content.Id}" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content.Id}.p+p" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentCacheRefresher/RefreshNode/{content.Id}" , _events [ i + + ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
}
[Test]
2023-09-12 14:16:27 +02:00
[LongRunning]
2016-05-27 11:34:03 +02:00
public void PublishUnpublishedContent ( )
{
// rule: when a content is published,
// - repository : refresh (p)
// - published page cache :: refresh
// note: whenever the published cache is refreshed, subscribers must
// assume that the unpublished cache is also refreshed, with the same
// values, and deal with it.
2020-12-23 11:35:49 +01:00
IContent content = ContentService . GetRootContent ( ) . FirstOrDefault ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content ) ;
content . Name = "changed" ;
2023-11-22 12:52:08 +01:00
ContentService . Save ( content ) ;
ResetEvents ( ) ;
ContentService . Publish ( content , Array . Empty < string > ( ) ) ;
2016-05-27 11:34:03 +02:00
Assert . AreEqual ( 2 , _msgCount ) ;
Assert . AreEqual ( 2 , _events . Count ) ;
2020-12-23 11:35:49 +01:00
int i = 0 ;
int m = 0 ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentRepository/Refresh/{content.Id}.u+p" , _events [ i + + ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
m + + ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentCacheRefresher/RefreshBranch/{content.Id}" , _events [ i + + ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
}
[Test]
2023-09-12 14:16:27 +02:00
[LongRunning]
2016-05-27 11:34:03 +02:00
public void UnpublishContent ( )
{
// rule: when a content is unpublished,
// - repository : refresh (u)
// - content cache :: refresh newest, remove published
2020-12-23 11:35:49 +01:00
IContent content = ContentService . GetRootContent ( ) . FirstOrDefault ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content ) ;
2023-11-22 12:52:08 +01:00
ContentService . Publish ( content , content . AvailableCultures . ToArray ( ) ) ;
2016-05-27 11:34:03 +02:00
ResetEvents ( ) ;
2020-10-14 11:08:55 +02:00
ContentService . Unpublish ( content ) ;
2016-05-27 11:34:03 +02:00
Assert . AreEqual ( 2 , _msgCount ) ;
Assert . AreEqual ( 2 , _events . Count ) ;
2020-12-23 11:35:49 +01:00
int i = 0 ;
int m = 0 ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentRepository/Refresh/{content.Id}.p-u" , _events [ i + + ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
m + + ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentCacheRefresher/RefreshBranch/{content.Id}" , _events [ i ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
}
[Test]
2023-09-12 14:16:27 +02:00
[LongRunning]
2016-05-27 11:34:03 +02:00
public void UnpublishContentWithChanges ( )
{
// rule: when a content is unpublished,
// - repository : refresh (u)
// - content cache :: refresh newest, remove published
2020-12-23 11:35:49 +01:00
IContent content = ContentService . GetRootContent ( ) . FirstOrDefault ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content ) ;
2023-11-22 12:52:08 +01:00
ContentService . Publish ( content , content . AvailableCultures . ToArray ( ) ) ;
2016-05-27 11:34:03 +02:00
content . Name = "changed" ;
2020-10-14 11:08:55 +02:00
ContentService . Save ( content ) ;
2016-05-27 11:34:03 +02:00
ResetEvents ( ) ;
2020-10-14 11:08:55 +02:00
ContentService . Unpublish ( content ) ;
2016-05-27 11:34:03 +02:00
Assert . AreEqual ( 2 , _msgCount ) ;
Assert . AreEqual ( 2 , _events . Count ) ;
2020-12-23 11:35:49 +01:00
int i = 0 ;
int m = 0 ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentRepository/Refresh/{content.Id}.p-u" , _events [ i + + ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
m + + ;
2020-12-27 09:50:56 +01:00
////Assert.AreEqual(string.Format("{0:000}: ContentCacheRefresher/Refresh/{1}", m, content.Id), _events[i++].ToString());
////Assert.AreEqual("changed", ContentService.GetById(((ContentCacheRefresher.JsonPayload)_events[i - 1].EventArgs).Id).Name);
2020-12-23 11:35:49 +01:00
Assert . AreEqual ( $"{m:000}: ContentCacheRefresher/RefreshBranch/{content.Id}" , _events [ i ] . ToString ( ) ) ;
}
2016-05-27 11:34:03 +02:00
2020-12-27 09:50:56 +01:00
#endregion
#region Publish & Unpublish branch
2016-05-27 11:34:03 +02:00
[Test]
2023-09-12 14:16:27 +02:00
[LongRunning]
2016-05-27 11:34:03 +02:00
public void UnpublishContentBranch ( )
{
// rule: when a content branch is unpublished,
// - repository :: refresh root (u)
// - unpublished page cache :: refresh root
// - published page cache :: remove root
// note: subscribers must take care of the hierarchy and unpublish
// the whole branch by themselves. Examine does it in UmbracoContentIndexer,
// content caches have to do it too... wondering whether we should instead
// trigger RemovePublished for all of the removed content?
2020-12-23 11:35:49 +01:00
IContent content1 = CreateBranch ( ) ;
2016-05-27 11:34:03 +02:00
ResetEvents ( ) ;
2020-10-14 11:08:55 +02:00
ContentService . Unpublish ( content1 ) ;
2016-05-27 11:34:03 +02:00
Assert . AreEqual ( 2 , _msgCount ) ;
Assert . AreEqual ( 2 , _events . Count ) ;
2020-12-23 11:35:49 +01:00
int i = 0 ;
int m = 0 ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentRepository/Refresh/{content1.Id}.p-u" , _events [ i + + ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
m + + ;
2020-12-27 09:50:56 +01:00
////Assert.AreEqual(string.Format("{0:000}: ContentCacheRefresher/Refresh/{1}", m, content1.Id), _events[i++].ToString());
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentCacheRefresher/RefreshBranch/{content1.Id}" , _events [ i ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
}
[Test]
2023-09-12 14:16:27 +02:00
[LongRunning]
2016-05-27 11:34:03 +02:00
public void PublishContentBranch ( )
{
// rule: when a content branch is published,
// - repository :: refresh root (p)
// - published page cache :: refresh root & descendants, database (level, sortOrder) order
2020-12-23 11:35:49 +01:00
IContent content1 = CreateBranch ( ) ;
2020-10-14 11:08:55 +02:00
ContentService . Unpublish ( content1 ) ;
2016-05-27 11:34:03 +02:00
ResetEvents ( ) ;
2023-11-22 12:52:08 +01:00
ContentService . Publish ( content1 , content1 . AvailableCultures . ToArray ( ) ) ;
2016-05-27 11:34:03 +02:00
Assert . AreEqual ( 2 , _msgCount ) ;
Assert . AreEqual ( 2 , _events . Count ) ;
2020-12-23 11:35:49 +01:00
int i = 0 ;
int m = 0 ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentRepository/Refresh/{content1.Id}.u+p" , _events [ i + + ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
m + + ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentCacheRefresher/RefreshBranch/{content1.Id}" , _events [ i + + ] . ToString ( ) ) ; // repub content1
2016-05-27 11:34:03 +02:00
/ *
var content1C = content1 . Children ( ) . ToArray ( ) ;
Assert . AreEqual ( string . Format ( "{0:000}: ContentCacheRefresher/RefreshPublished/{1}" , m , content1C [ 0 ] . Id ) , _events [ i + + ] . ToString ( ) ) ; // repub content1.content2
Assert . AreEqual ( string . Format ( "{0:000}: ContentCacheRefresher/RefreshPublished/{1}" , m , content1C [ 2 ] . Id ) , _events [ i + + ] . ToString ( ) ) ; // repub content1.content4
2020-10-14 11:08:55 +02:00
var c = ContentService . GetPublishedVersion ( ( ( ContentCacheRefresher . JsonPayload ) _events [ i - 1 ] . EventArgs ) . Id ) ;
2016-05-27 11:34:03 +02:00
Assert . IsTrue ( c . Published ) ; // get the published one
Assert . AreEqual ( "Content4" , c . Name ) ; // published has old name
var content2C = content1C [ 0 ] . Children ( ) . ToArray ( ) ;
Assert . AreEqual ( string . Format ( "{0:000}: ContentCacheRefresher/RefreshPublished/{1}" , m , content2C [ 0 ] . Id ) , _events [ i + + ] . ToString ( ) ) ; // repub content1.content2.content21
var content4C = content1C [ 2 ] . Children ( ) . ToArray ( ) ;
Assert . AreEqual ( string . Format ( "{0:000}: ContentCacheRefresher/RefreshPublished/{1}" , m , content4C [ 0 ] . Id ) , _events [ i ] . ToString ( ) ) ; // repub content1.content4.content41
* /
}
[Test]
2023-09-12 14:16:27 +02:00
[LongRunning]
2016-05-27 11:34:03 +02:00
public void PublishContentBranchWithPublishedChildren ( )
{
// rule?
2020-12-23 11:35:49 +01:00
IContent content1 = CreateBranch ( ) ;
2020-10-14 11:08:55 +02:00
ContentService . Unpublish ( content1 ) ;
2016-05-27 11:34:03 +02:00
2018-06-22 21:03:47 +02:00
// branch is:
2016-05-27 11:34:03 +02:00
ResetEvents ( ) ;
2023-11-22 12:52:08 +01:00
ContentService . PublishBranch ( content1 , force : false , cultures : content1 . AvailableCultures . ToArray ( ) ) ; // force = false, don't publish unpublished items
2018-06-22 21:03:47 +02:00
2020-12-23 11:35:49 +01:00
foreach ( EventInstance e in _events )
{
2018-06-22 21:03:47 +02:00
Console . WriteLine ( e ) ;
2020-12-23 11:35:49 +01:00
}
2016-05-27 11:34:03 +02:00
2018-06-22 21:03:47 +02:00
Assert . AreEqual ( 3 , _msgCount ) ;
Assert . AreEqual ( 3 , _events . Count ) ;
2020-12-23 11:35:49 +01:00
int i = 0 ;
int m = 0 ;
IContent [ ] content1C = Children ( content1 ) . ToArray ( ) ;
IContent [ ] content2C = Children ( content1C [ 0 ] ) . ToArray ( ) ;
IContent [ ] content4C = Children ( content1C [ 2 ] ) . ToArray ( ) ;
2018-06-22 21:03:47 +02:00
// force:false => only republish the root node + nodes that are edited
2020-12-27 09:50:56 +01:00
#pragma warning disable SA1003 // Symbols should be spaced correctly (justification: suppression necessary here as it's used in an interpolated string format.
2018-06-22 21:03:47 +02:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content1.Id}.u+p" , _events [ i + + ] . ToString ( ) ) ; // content1 was unpublished, now published
// change: only content4 shows here, because it has changes - others don't need to be published
2020-12-27 09:50:56 +01:00
////Assert.AreEqual($"{m++:000}: ContentRepository/Refresh/{content1C[0].Id}.p+p", _events[i++].ToString()); // content1/content2
2018-06-22 21:03:47 +02:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content1C[2].Id}.p+p" , _events [ i + + ] . ToString ( ) ) ; // content1/content4
2020-12-27 09:50:56 +01:00
////Assert.AreEqual($"{m++:000}: ContentRepository/Refresh/{content2C[0].Id}.p+p", _events[i++].ToString()); // content1/content2/content21
////Assert.AreEqual($"{m++:000}: ContentRepository/Refresh/{content4C[0].Id}.p+p", _events[i++].ToString()); // content1/content4/content41
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentCacheRefresher/RefreshBranch/{content1.Id}" , _events [ i + + ] . ToString ( ) ) ; // repub content1
2020-12-23 11:35:49 +01:00
#pragma warning restore SA1003 // Symbols should be spaced correctly
2016-05-27 11:34:03 +02:00
}
[Test]
2023-09-12 14:16:27 +02:00
[LongRunning]
2016-05-27 11:34:03 +02:00
public void PublishContentBranchWithAllChildren ( )
{
// rule?
2020-12-23 11:35:49 +01:00
IContent content1 = CreateBranch ( ) ;
2020-10-14 11:08:55 +02:00
ContentService . Unpublish ( content1 ) ;
2016-05-27 11:34:03 +02:00
ResetEvents ( ) ;
2023-11-22 12:52:08 +01:00
ContentService . PublishBranch ( content1 , force : true , cultures : content1 . AvailableCultures . ToArray ( ) ) ; // force = true, also publish unpublished items
2016-05-27 11:34:03 +02:00
2020-12-23 11:35:49 +01:00
foreach ( EventInstance e in _events )
{
2018-06-22 21:03:47 +02:00
Console . WriteLine ( e ) ;
2020-12-23 11:35:49 +01:00
}
2018-06-22 21:03:47 +02:00
Assert . AreEqual ( 10 , _msgCount ) ;
Assert . AreEqual ( 10 , _events . Count ) ;
2020-12-23 11:35:49 +01:00
int i = 0 ;
int m = 0 ;
IContent [ ] content1C = Children ( content1 ) . ToArray ( ) ;
IContent [ ] content2C = Children ( content1C [ 0 ] ) . ToArray ( ) ;
IContent [ ] content3C = Children ( content1C [ 1 ] ) . ToArray ( ) ;
IContent [ ] content4C = Children ( content1C [ 2 ] ) . ToArray ( ) ;
IContent [ ] content5C = Children ( content1C [ 3 ] ) . ToArray ( ) ;
2020-12-27 09:50:56 +01:00
#pragma warning disable SA1003 // Symbols should be spaced correctly (justification: suppression necessary here as it's used in an interpolated string format.
2018-06-22 21:03:47 +02:00
// force:true => all nodes are republished, refreshing all nodes - but only with changes - published w/out changes are not repub
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content1.Id}.u+p" , _events [ i + + ] . ToString ( ) ) ;
2020-12-27 09:50:56 +01:00
////Assert.AreEqual($"{m++:000}: ContentRepository/Refresh/{content1C[0].Id}.p+p", _events[i++].ToString());
////Assert.AreEqual($"{m++:000}: ContentRepository/Refresh/{content2C[0].Id}.p+p", _events[i++].ToString());
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content2C[1].Id}.u+p" , _events [ i + + ] . ToString ( ) ) ;
2018-10-31 22:38:58 +11:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content1C[1].Id}.u+p" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content3C[0].Id}.u+p" , _events [ i + + ] . ToString ( ) ) ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content3C[1].Id}.u+p" , _events [ i + + ] . ToString ( ) ) ;
2018-10-31 22:38:58 +11:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content1C[2].Id}.p+p" , _events [ i + + ] . ToString ( ) ) ;
2020-12-27 09:50:56 +01:00
////Assert.AreEqual($"{m++:000}: ContentRepository/Refresh/{content4C[0].Id}.p+p", _events[i++].ToString());
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content4C[1].Id}.u+p" , _events [ i + + ] . ToString ( ) ) ;
2018-10-31 22:38:58 +11:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content1C[3].Id}.u+p" , _events [ i + + ] . ToString ( ) ) ;
2020-12-27 09:50:56 +01:00
////Assert.AreEqual($"{m++:000}: ContentRepository/Refresh/{content5C[0].Id}.p+p", _events[i++].ToString());
2018-06-22 21:03:47 +02:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content5C[1].Id}.u+p" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m:000}: ContentCacheRefresher/RefreshBranch/{content1.Id}" , _events [ i + + ] . ToString ( ) ) ; // repub content1
2020-12-23 11:35:49 +01:00
#pragma warning restore SA1003 // Symbols should be spaced correctly
2016-05-27 11:34:03 +02:00
}
2020-12-27 09:50:56 +01:00
#endregion
#region Sort
2016-05-27 11:34:03 +02:00
[Test]
2023-09-12 14:16:27 +02:00
[LongRunning]
2016-05-27 11:34:03 +02:00
public void SortAll ( )
{
// rule: ?
2020-12-23 11:35:49 +01:00
IContent content1 = CreateBranch ( ) ;
IContent [ ] content1C = Children ( content1 ) . ToArray ( ) ;
2016-05-27 11:34:03 +02:00
Assert . AreEqual ( 4 , content1C . Length ) ;
2020-12-23 11:35:49 +01:00
IContent [ ] content1Csorted = new [ ] { content1C [ 3 ] , content1C [ 0 ] , content1C [ 1 ] , content1C [ 2 ] } ;
2016-05-27 11:34:03 +02:00
ResetEvents ( ) ;
2020-10-14 11:08:55 +02:00
ContentService . Sort ( content1Csorted ) ;
2016-05-27 11:34:03 +02:00
2020-12-23 11:35:49 +01:00
IContent [ ] content1Cagain = Children ( content1 ) . ToArray ( ) ;
2016-05-27 11:34:03 +02:00
Assert . AreEqual ( 4 , content1Cagain . Length ) ;
Assert . AreEqual ( content1C [ 0 ] . Id , content1Cagain [ 1 ] . Id ) ;
Assert . AreEqual ( content1C [ 1 ] . Id , content1Cagain [ 2 ] . Id ) ;
Assert . AreEqual ( content1C [ 2 ] . Id , content1Cagain [ 3 ] . Id ) ;
Assert . AreEqual ( content1C [ 3 ] . Id , content1Cagain [ 0 ] . Id ) ;
Assert . AreEqual ( 5 , _msgCount ) ;
Assert . AreEqual ( 8 , _events . Count ) ;
2020-12-23 11:35:49 +01:00
int i = 0 ;
int m = 0 ;
2020-12-27 09:50:56 +01:00
#pragma warning disable SA1003 // Symbols should be spaced correctly (justification: suppression necessary here as it's used in an interpolated string format.
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content1C[3].Id}.u=u" , _events [ i + + ] . ToString ( ) ) ; // content5 is not published
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content1C[0].Id}.p=p" , _events [ i + + ] . ToString ( ) ) ; // content2 is published
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content1C[1].Id}.u=u" , _events [ i + + ] . ToString ( ) ) ; // content3 is not published
Assert . AreEqual ( $"{m:000}: ContentRepository/Refresh/{content1C[2].Id}.p=p" , _events [ i + + ] . ToString ( ) ) ; // content4 is published + changes
2016-05-27 11:34:03 +02:00
m + + ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentCacheRefresher/RefreshNode/{content1C[3].Id}" , _events [ i + + ] . ToString ( ) ) ; // content5 is not published
Assert . AreEqual ( $"{m:000}: ContentCacheRefresher/RefreshNode/{content1C[0].Id}" , _events [ i + + ] . ToString ( ) ) ; // content2 is published
Assert . AreEqual ( $"{m:000}: ContentCacheRefresher/RefreshNode/{content1C[1].Id}" , _events [ i + + ] . ToString ( ) ) ; // content3 is not published
Assert . AreEqual ( $"{m:000}: ContentCacheRefresher/RefreshNode/{content1C[2].Id}" , _events [ i ] . ToString ( ) ) ; // content4 is published
2020-12-23 11:35:49 +01:00
#pragma warning restore SA1003 // Symbols should be spaced correctly
2016-05-27 11:34:03 +02:00
}
[Test]
2023-09-12 14:16:27 +02:00
[LongRunning]
2016-05-27 11:34:03 +02:00
public void SortSome ( )
{
// rule: ?
2020-12-23 11:35:49 +01:00
IContent content1 = CreateBranch ( ) ;
IContent [ ] content1C = Children ( content1 ) . ToArray ( ) ;
2016-05-27 11:34:03 +02:00
Assert . AreEqual ( 4 , content1C . Length ) ;
2020-12-23 11:35:49 +01:00
IContent [ ] content1Csorted = new [ ] { content1C [ 0 ] , content1C [ 1 ] , content1C [ 3 ] , content1C [ 2 ] } ;
2016-05-27 11:34:03 +02:00
ResetEvents ( ) ;
2020-10-14 11:08:55 +02:00
ContentService . Sort ( content1Csorted ) ;
2016-05-27 11:34:03 +02:00
2020-12-23 11:35:49 +01:00
IContent [ ] content1Cagain = Children ( content1 ) . ToArray ( ) ;
2016-05-27 11:34:03 +02:00
Assert . AreEqual ( 4 , content1Cagain . Length ) ;
Assert . AreEqual ( content1C [ 0 ] . Id , content1Cagain [ 0 ] . Id ) ;
Assert . AreEqual ( content1C [ 1 ] . Id , content1Cagain [ 1 ] . Id ) ;
Assert . AreEqual ( content1C [ 2 ] . Id , content1Cagain [ 3 ] . Id ) ;
Assert . AreEqual ( content1C [ 3 ] . Id , content1Cagain [ 2 ] . Id ) ;
Assert . AreEqual ( 3 , _msgCount ) ;
Assert . AreEqual ( 4 , _events . Count ) ;
2020-12-23 11:35:49 +01:00
int i = 0 ;
int m = 0 ;
2020-12-27 09:50:56 +01:00
#pragma warning disable SA1003 // Symbols should be spaced correctly (justification: suppression necessary here as it's used in an interpolated string format.
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content1C[3].Id}.u=u" , _events [ i + + ] . ToString ( ) ) ; // content5 is not published
Assert . AreEqual ( $"{m:000}: ContentRepository/Refresh/{content1C[2].Id}.p=p" , _events [ i + + ] . ToString ( ) ) ; // content4 is published + changes
2016-05-27 11:34:03 +02:00
m + + ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentCacheRefresher/RefreshNode/{content1C[3].Id}" , _events [ i + + ] . ToString ( ) ) ; // content5 is not published
Assert . AreEqual ( $"{m:000}: ContentCacheRefresher/RefreshNode/{content1C[2].Id}" , _events [ i ] . ToString ( ) ) ; // content4 is published
2020-12-23 11:35:49 +01:00
#pragma warning restore SA1003 // Symbols should be spaced correctly
2016-05-27 11:34:03 +02:00
}
2020-12-27 09:50:56 +01:00
#endregion
#region Trash
2016-05-27 11:34:03 +02:00
// incl. trashing a published, unpublished content, w/changes
// incl. trashing a branch, untrashing a single masked content
// including emptying the recycle bin
[Test]
2023-09-12 14:16:27 +02:00
[LongRunning]
2016-05-27 11:34:03 +02:00
public void TrashUnpublishedContent ( )
{
2020-12-23 11:35:49 +01:00
IContent content = CreateContent ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content ) ;
ResetEvents ( ) ;
2020-10-14 11:08:55 +02:00
ContentService . MoveToRecycleBin ( content ) ;
2016-05-27 11:34:03 +02:00
Assert . AreEqual ( 2 , _msgCount ) ;
Assert . AreEqual ( 2 , _events . Count ) ;
2020-12-23 11:35:49 +01:00
int i = 0 ;
int m = 0 ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentRepository/Refresh/{content.Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
m + + ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentCacheRefresher/RefreshBranch/{content.Id}" , _events [ i ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
}
[Test]
2023-09-12 14:16:27 +02:00
[LongRunning]
2016-05-27 11:34:03 +02:00
public void UntrashUnpublishedContent ( )
{
2020-12-23 11:35:49 +01:00
IContent content = CreateContent ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content ) ;
2020-10-14 11:08:55 +02:00
ContentService . MoveToRecycleBin ( content ) ;
2016-05-27 11:34:03 +02:00
ResetEvents ( ) ;
2020-10-14 11:08:55 +02:00
ContentService . Move ( content , - 1 ) ;
2016-05-27 11:34:03 +02:00
Assert . AreEqual ( 2 , _msgCount ) ;
Assert . AreEqual ( 2 , _events . Count ) ;
2020-12-23 11:35:49 +01:00
int i = 0 ;
int m = 0 ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentRepository/Refresh/{content.Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
m + + ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentCacheRefresher/RefreshBranch/{content.Id}" , _events [ i ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
}
[Test]
2023-09-12 14:16:27 +02:00
[LongRunning]
2016-05-27 11:34:03 +02:00
public void TrashPublishedContent ( )
{
// does 1) unpublish and 2) trash
2020-12-23 11:35:49 +01:00
IContent content = CreateContent ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content ) ;
2023-11-22 12:52:08 +01:00
ContentService . Publish ( content , content . AvailableCultures . ToArray ( ) ) ;
2016-05-27 11:34:03 +02:00
ResetEvents ( ) ;
2020-10-14 11:08:55 +02:00
ContentService . MoveToRecycleBin ( content ) ;
2016-05-27 11:34:03 +02:00
Assert . AreEqual ( 2 , _msgCount ) ;
Assert . AreEqual ( 2 , _events . Count ) ;
2020-12-23 11:35:49 +01:00
int i = 0 ;
int m = 0 ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentRepository/Refresh/{content.Id}.p=m" , _events [ i + + ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
m + + ;
2020-12-27 09:50:56 +01:00
////Assert.AreEqual(string.Format("{0:000}: ContentCacheRefresher/RemovePublished,Refresh/{1}", m, content.Id), _events[i++].ToString());
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentCacheRefresher/RefreshBranch/{content.Id}" , _events [ i ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
}
[Test]
2023-09-12 14:16:27 +02:00
[LongRunning]
2016-05-27 11:34:03 +02:00
public void UntrashPublishedContent ( )
{
// same as unpublished as it's been unpublished
2020-12-23 11:35:49 +01:00
IContent content = CreateContent ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content ) ;
2023-11-22 12:52:08 +01:00
ContentService . Publish ( content , content . AvailableCultures . ToArray ( ) ) ;
2020-10-14 11:08:55 +02:00
ContentService . MoveToRecycleBin ( content ) ;
2016-05-27 11:34:03 +02:00
ResetEvents ( ) ;
2020-10-14 11:08:55 +02:00
ContentService . Move ( content , - 1 ) ;
2016-05-27 11:34:03 +02:00
Assert . AreEqual ( 2 , _msgCount ) ;
Assert . AreEqual ( 2 , _events . Count ) ;
2020-12-23 11:35:49 +01:00
int i = 0 ;
int m = 0 ;
2016-05-27 11:34:03 +02:00
// trashing did /pm- (published, masked)
// un-trashing cannot re-publish so /u?- (not-published, unchanged)
// but because we *have* to change state to unpublished, it's /ux- and not /uu-
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentRepository/Refresh/{content.Id}.p-u" , _events [ i + + ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
m + + ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentCacheRefresher/RefreshBranch/{content.Id}" , _events [ i ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
}
[Test]
2023-09-12 14:16:27 +02:00
[LongRunning]
2016-05-27 11:34:03 +02:00
public void TrashPublishedContentWithChanges ( )
{
2020-12-23 11:35:49 +01:00
IContent content = CreateContent ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content ) ;
2023-11-22 12:52:08 +01:00
ContentService . Publish ( content , content . AvailableCultures . ToArray ( ) ) ;
2017-11-07 19:49:14 +01:00
content . Properties . First ( ) . SetValue ( "changed" ) ;
2020-10-14 11:08:55 +02:00
ContentService . Save ( content ) ;
2016-05-27 11:34:03 +02:00
ResetEvents ( ) ;
2020-10-14 11:08:55 +02:00
ContentService . MoveToRecycleBin ( content ) ;
2016-05-27 11:34:03 +02:00
Assert . AreEqual ( 2 , _msgCount ) ;
Assert . AreEqual ( 2 , _events . Count ) ;
2020-12-23 11:35:49 +01:00
int i = 0 ;
int m = 0 ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentRepository/Refresh/{content.Id}.p=m" , _events [ i + + ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
m + + ;
2020-12-27 09:50:56 +01:00
////Assert.AreEqual(string.Format("{0:000}: ContentCacheRefresher/RemovePublished,Refresh/{1}", m, content.Id), _events[i++].ToString());
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentCacheRefresher/RefreshBranch/{content.Id}" , _events [ i ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
}
[Test]
2023-09-12 14:16:27 +02:00
[LongRunning]
2016-05-27 11:34:03 +02:00
public void TrashContentBranch ( )
{
2020-12-23 11:35:49 +01:00
IContent content1 = CreateBranch ( ) ;
2016-05-27 11:34:03 +02:00
ResetEvents ( ) ;
2020-10-14 11:08:55 +02:00
ContentService . MoveToRecycleBin ( content1 ) ;
2016-05-27 11:34:03 +02:00
Assert . AreEqual ( 14 , _msgCount ) ;
Assert . AreEqual ( 14 , _events . Count ) ;
2020-12-23 11:35:49 +01:00
int i = 0 ;
int m = 0 ;
IContent [ ] content1C = Children ( content1 ) . ToArray ( ) ;
IContent [ ] content2C = Children ( content1C [ 0 ] ) . ToArray ( ) ;
IContent [ ] content3C = Children ( content1C [ 1 ] ) . ToArray ( ) ;
IContent [ ] content4C = Children ( content1C [ 2 ] ) . ToArray ( ) ;
IContent [ ] content5C = Children ( content1C [ 3 ] ) . ToArray ( ) ;
2020-12-27 09:50:56 +01:00
#pragma warning disable SA1003 // Symbols should be spaced correctly (justification: suppression necessary here as it's used in an interpolated string format.
2017-12-06 09:58:50 +01:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content1.Id}.p=m" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content1C[0].Id}.p=m" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content2C[0].Id}.p=m" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content2C[1].Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
2018-10-31 22:38:58 +11:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content1C[1].Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content3C[0].Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
2017-12-06 09:58:50 +01:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content3C[1].Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
2018-10-31 22:38:58 +11:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content1C[2].Id}.p=m" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content4C[0].Id}.p=m" , _events [ i + + ] . ToString ( ) ) ;
2017-12-06 09:58:50 +01:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content4C[1].Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
2018-10-31 22:38:58 +11:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content1C[3].Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content5C[0].Id}.p=m" , _events [ i + + ] . ToString ( ) ) ;
2017-12-06 09:58:50 +01:00
Assert . AreEqual ( $"{m:000}: ContentRepository/Refresh/{content5C[1].Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
2020-12-27 09:50:56 +01:00
2016-05-27 11:34:03 +02:00
m + + ;
2017-12-06 09:58:50 +01:00
Assert . AreEqual ( $"{m:000}: ContentCacheRefresher/RefreshBranch/{content1.Id}" , _events [ i ] . ToString ( ) ) ;
2020-12-23 11:35:49 +01:00
#pragma warning restore SA1003 // Symbols should be spaced correctly
2016-05-27 11:34:03 +02:00
}
[Test]
2023-09-12 14:16:27 +02:00
[LongRunning]
2016-05-27 11:34:03 +02:00
public void EmptyRecycleBinContent ( )
{
2022-06-21 08:09:38 +02:00
ContentService . EmptyRecycleBin ( ) ;
2016-05-27 11:34:03 +02:00
2020-12-23 11:35:49 +01:00
IContent content = CreateContent ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content ) ;
2020-10-14 11:08:55 +02:00
ContentService . MoveToRecycleBin ( content ) ;
2016-05-27 11:34:03 +02:00
ResetEvents ( ) ;
2022-06-21 08:09:38 +02:00
ContentService . EmptyRecycleBin ( ) ;
2016-05-27 11:34:03 +02:00
Assert . AreEqual ( 2 , _msgCount ) ;
Assert . AreEqual ( 2 , _events . Count ) ;
var i = 0 ;
var m = 0 ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentRepository/Remove/{content.Id}" , _events [ i + + ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
m + + ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentCacheRefresher/Remove/{content.Id}" , _events [ i ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
}
[Test]
2023-09-12 14:16:27 +02:00
[LongRunning]
2016-05-27 11:34:03 +02:00
public void EmptyRecycleBinContents ( )
{
2020-10-14 11:08:55 +02:00
ContentService . EmptyRecycleBin ( Constants . Security . SuperUserId ) ;
2016-05-27 11:34:03 +02:00
2020-12-23 11:35:49 +01:00
IContent content1 = CreateContent ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content1 ) ;
2020-10-14 11:08:55 +02:00
ContentService . MoveToRecycleBin ( content1 ) ;
2016-05-27 11:34:03 +02:00
2020-12-23 11:35:49 +01:00
IContent content2 = CreateContent ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content2 ) ;
2020-10-14 11:08:55 +02:00
ContentService . MoveToRecycleBin ( content2 ) ;
2016-05-27 11:34:03 +02:00
ResetEvents ( ) ;
2020-10-14 11:08:55 +02:00
ContentService . EmptyRecycleBin ( Constants . Security . SuperUserId ) ;
2016-05-27 11:34:03 +02:00
Assert . AreEqual ( 3 , _msgCount ) ;
Assert . AreEqual ( 4 , _events . Count ) ;
var i = 0 ;
var m = 0 ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Remove/{content1.Id}" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m:000}: ContentRepository/Remove/{content2.Id}" , _events [ i + + ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
m + + ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentCacheRefresher/Remove/{content1.Id}" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m:000}: ContentCacheRefresher/Remove/{content2.Id}" , _events [ i ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
}
[Test]
2023-09-12 14:16:27 +02:00
[LongRunning]
2016-05-27 11:34:03 +02:00
public void EmptyRecycleBinBranch ( )
{
2020-10-14 11:08:55 +02:00
ContentService . EmptyRecycleBin ( Constants . Security . SuperUserId ) ;
2016-05-27 11:34:03 +02:00
2020-12-23 11:35:49 +01:00
IContent content1 = CreateBranch ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content1 ) ;
2020-10-14 11:08:55 +02:00
ContentService . MoveToRecycleBin ( content1 ) ;
2016-05-27 11:34:03 +02:00
ResetEvents ( ) ;
2020-12-23 11:35:49 +01:00
IContent [ ] content1C = Children ( content1 ) . ToArray ( ) ;
IContent [ ] content2C = Children ( content1C [ 0 ] ) . ToArray ( ) ;
IContent [ ] content3C = Children ( content1C [ 1 ] ) . ToArray ( ) ;
IContent [ ] content4C = Children ( content1C [ 2 ] ) . ToArray ( ) ;
IContent [ ] content5C = Children ( content1C [ 3 ] ) . ToArray ( ) ;
2016-05-27 11:34:03 +02:00
2020-10-14 11:08:55 +02:00
ContentService . EmptyRecycleBin ( Constants . Security . SuperUserId ) ;
2016-05-27 11:34:03 +02:00
Assert . AreEqual ( 14 , _msgCount ) ;
Assert . AreEqual ( 14 , _events . Count ) ;
var i = 0 ;
var m = 0 ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Remove/{content5C[1].Id}" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Remove/{content5C[0].Id}" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Remove/{content1C[3].Id}" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Remove/{content4C[1].Id}" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Remove/{content4C[0].Id}" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Remove/{content1C[2].Id}" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Remove/{content3C[1].Id}" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Remove/{content3C[0].Id}" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Remove/{content1C[1].Id}" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Remove/{content2C[1].Id}" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Remove/{content2C[0].Id}" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Remove/{content1C[0].Id}" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m:000}: ContentRepository/Remove/{content1.Id}" , _events [ i + + ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
m + + ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentCacheRefresher/Remove/{content1.Id}" , _events [ i ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
}
2020-12-27 09:50:56 +01:00
#endregion
#region Delete
2016-05-27 11:34:03 +02:00
[Test]
2023-09-12 14:16:27 +02:00
[LongRunning]
2016-05-27 11:34:03 +02:00
public void DeleteUnpublishedContent ( )
{
2020-12-23 11:35:49 +01:00
IContent content = CreateContent ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content ) ;
ResetEvents ( ) ;
2020-10-14 11:08:55 +02:00
ContentService . Delete ( content ) ;
2016-05-27 11:34:03 +02:00
Assert . AreEqual ( 2 , _msgCount ) ;
Assert . AreEqual ( 2 , _events . Count ) ;
2020-12-23 11:35:49 +01:00
int i = 0 ;
int m = 0 ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentRepository/Remove/{content.Id}" , _events [ i + + ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
m + + ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentCacheRefresher/Remove/{content.Id}" , _events [ i ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
}
[Test]
2023-09-12 14:16:27 +02:00
[LongRunning]
2016-05-27 11:34:03 +02:00
public void DeletePublishedContent ( )
{
2020-12-23 11:35:49 +01:00
IContent content = CreateContent ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content ) ;
2023-11-22 12:52:08 +01:00
ContentService . Publish ( content , content . AvailableCultures . ToArray ( ) ) ;
2016-05-27 11:34:03 +02:00
ResetEvents ( ) ;
2020-10-14 11:08:55 +02:00
ContentService . Delete ( content ) ;
2016-05-27 11:34:03 +02:00
Assert . AreEqual ( 2 , _msgCount ) ;
Assert . AreEqual ( 2 , _events . Count ) ;
2020-12-23 11:35:49 +01:00
int i = 0 ;
int m = 0 ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentRepository/Remove/{content.Id}" , _events [ i + + ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
m + + ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentCacheRefresher/Remove/{content.Id}" , _events [ i ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
}
[Test]
2023-09-12 14:16:27 +02:00
[LongRunning]
2016-05-27 11:34:03 +02:00
public void DeletePublishedContentWithChanges ( )
{
2020-12-23 11:35:49 +01:00
IContent content = CreateContent ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content ) ;
2023-11-22 12:52:08 +01:00
ContentService . Publish ( content , content . AvailableCultures . ToArray ( ) ) ;
2017-11-07 19:49:14 +01:00
content . Properties . First ( ) . SetValue ( "changed" ) ;
2020-10-14 11:08:55 +02:00
ContentService . Save ( content ) ;
2016-05-27 11:34:03 +02:00
ResetEvents ( ) ;
2020-10-14 11:08:55 +02:00
ContentService . Delete ( content ) ;
2016-05-27 11:34:03 +02:00
Assert . AreEqual ( 2 , _msgCount ) ;
Assert . AreEqual ( 2 , _events . Count ) ;
2020-12-23 11:35:49 +01:00
int i = 0 ;
int m = 0 ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentRepository/Remove/{content.Id}" , _events [ i + + ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
m + + ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentCacheRefresher/Remove/{content.Id}" , _events [ i ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
}
[Test]
2023-09-12 14:16:27 +02:00
[LongRunning]
2016-05-27 11:34:03 +02:00
public void DeleteMaskedPublishedContent ( )
{
2020-12-23 11:35:49 +01:00
IContent content1 = CreateContent ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content1 ) ;
2023-11-22 12:52:08 +01:00
ContentService . Publish ( content1 , content1 . AvailableCultures . ToArray ( ) ) ;
2020-12-23 11:35:49 +01:00
IContent content2 = CreateContent ( content1 . Id ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content2 ) ;
2023-11-22 12:52:08 +01:00
ContentService . Publish ( content2 , content2 . AvailableCultures . ToArray ( ) ) ;
2020-10-14 11:08:55 +02:00
ContentService . Unpublish ( content1 ) ;
2016-05-27 11:34:03 +02:00
ResetEvents ( ) ;
2020-10-14 11:08:55 +02:00
ContentService . Delete ( content2 ) ;
2016-05-27 11:34:03 +02:00
Assert . AreEqual ( 2 , _msgCount ) ;
Assert . AreEqual ( 2 , _events . Count ) ;
2020-12-23 11:35:49 +01:00
int i = 0 ;
int m = 0 ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentRepository/Remove/{content2.Id}" , _events [ i + + ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
m + + ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentCacheRefresher/Remove/{content2.Id}" , _events [ i ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
}
[Test]
2023-09-12 14:16:27 +02:00
[LongRunning]
2016-05-27 11:34:03 +02:00
public void DeleteBranch ( )
{
2020-12-23 11:35:49 +01:00
IContent content1 = CreateBranch ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content1 ) ;
// get them before they are deleted!
2020-12-23 11:35:49 +01:00
IContent [ ] content1C = Children ( content1 ) . ToArray ( ) ;
IContent [ ] content2C = Children ( content1C [ 0 ] ) . ToArray ( ) ;
IContent [ ] content3C = Children ( content1C [ 1 ] ) . ToArray ( ) ;
IContent [ ] content4C = Children ( content1C [ 2 ] ) . ToArray ( ) ;
IContent [ ] content5C = Children ( content1C [ 3 ] ) . ToArray ( ) ;
2016-05-27 11:34:03 +02:00
ResetEvents ( ) ;
2020-10-14 11:08:55 +02:00
ContentService . Delete ( content1 ) ;
2016-05-27 11:34:03 +02:00
Assert . AreEqual ( 14 , _msgCount ) ;
Assert . AreEqual ( 14 , _events . Count ) ;
2020-12-23 11:35:49 +01:00
int i = 0 ;
int m = 0 ;
2020-12-27 09:50:56 +01:00
#pragma warning disable SA1003 // Symbols should be spaced correctly (justification: suppression necessary here as it's used in an interpolated string format.
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Remove/{content5C[1].Id}" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Remove/{content5C[0].Id}" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Remove/{content1C[3].Id}" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Remove/{content4C[1].Id}" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Remove/{content4C[0].Id}" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Remove/{content1C[2].Id}" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Remove/{content3C[1].Id}" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Remove/{content3C[0].Id}" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Remove/{content1C[1].Id}" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Remove/{content2C[1].Id}" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Remove/{content2C[0].Id}" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Remove/{content1C[0].Id}" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m:000}: ContentRepository/Remove/{content1.Id}" , _events [ i + + ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
m + + ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentCacheRefresher/Remove/{content1.Id}" , _events [ i ] . ToString ( ) ) ;
2020-12-23 11:35:49 +01:00
#pragma warning restore SA1003 // Symbols should be spaced correctly
2016-05-27 11:34:03 +02:00
}
2020-12-27 09:50:56 +01:00
#endregion
#region Move
2016-05-27 11:34:03 +02:00
[Test]
2023-09-12 14:16:27 +02:00
[LongRunning]
2016-05-27 11:34:03 +02:00
public void MoveUnpublishedContentUnderUnpublished ( )
{
2020-12-23 11:35:49 +01:00
IContent content1 = CreateContent ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content1 ) ;
2020-12-23 11:35:49 +01:00
IContent content2 = CreateContent ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content2 ) ;
ResetEvents ( ) ;
2020-10-14 11:08:55 +02:00
ContentService . Move ( content1 , content2 . Id ) ;
2016-05-27 11:34:03 +02:00
Assert . AreEqual ( 2 , _msgCount ) ;
Assert . AreEqual ( 2 , _events . Count ) ;
2020-12-23 11:35:49 +01:00
int i = 0 ;
int m = 0 ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentRepository/Refresh/{content1.Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
m + + ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentCacheRefresher/RefreshBranch/{content1.Id}" , _events [ i ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
}
[Test]
public void MovePublishedContentUnderUnpublished ( )
{
2020-12-23 11:35:49 +01:00
IContent content1 = CreateContent ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content1 ) ;
2023-11-22 12:52:08 +01:00
ContentService . Publish ( content1 , content1 . AvailableCultures . ToArray ( ) ) ;
2020-12-23 11:35:49 +01:00
IContent content2 = CreateContent ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content2 ) ;
ResetEvents ( ) ;
2020-10-14 11:08:55 +02:00
ContentService . Move ( content1 , content2 . Id ) ;
2016-05-27 11:34:03 +02:00
Assert . AreEqual ( 2 , _msgCount ) ;
Assert . AreEqual ( 2 , _events . Count ) ;
2020-12-23 11:35:49 +01:00
int i = 0 ;
int m = 0 ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentRepository/Refresh/{content1.Id}.p=m" , _events [ i + + ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
m + + ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentCacheRefresher/RefreshBranch/{content1.Id}" , _events [ i + + ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
}
[Test]
2023-09-12 14:16:27 +02:00
[LongRunning]
2016-05-27 11:34:03 +02:00
public void MovePublishedContentWithChangesUnderUnpublished ( )
{
2020-12-23 11:35:49 +01:00
IContent content1 = CreateContent ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content1 ) ;
2023-11-22 12:52:08 +01:00
ContentService . Publish ( content1 , content1 . AvailableCultures . ToArray ( ) ) ;
2017-11-07 19:49:14 +01:00
content1 . Properties . First ( ) . SetValue ( "changed" ) ;
2020-10-14 11:08:55 +02:00
ContentService . Save ( content1 ) ;
2020-12-23 11:35:49 +01:00
IContent content2 = CreateContent ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content2 ) ;
ResetEvents ( ) ;
2020-10-14 11:08:55 +02:00
ContentService . Move ( content1 , content2 . Id ) ;
2016-05-27 11:34:03 +02:00
Assert . AreEqual ( 2 , _msgCount ) ;
Assert . AreEqual ( 2 , _events . Count ) ;
2020-12-23 11:35:49 +01:00
int i = 0 ;
int m = 0 ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentRepository/Refresh/{content1.Id}.p=m" , _events [ i + + ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
m + + ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentCacheRefresher/RefreshBranch/{content1.Id}" , _events [ i + + ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
}
[Test]
2023-09-12 14:16:27 +02:00
[LongRunning]
2016-05-27 11:34:03 +02:00
public void MoveUnpublishedContentUnderPublished ( )
{
2020-12-23 11:35:49 +01:00
IContent content1 = CreateContent ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content1 ) ;
2020-12-23 11:35:49 +01:00
IContent content2 = CreateContent ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content2 ) ;
2023-11-22 12:52:08 +01:00
ContentService . Publish ( content2 , content2 . AvailableCultures . ToArray ( ) ) ;
2016-05-27 11:34:03 +02:00
ResetEvents ( ) ;
2020-10-14 11:08:55 +02:00
ContentService . Move ( content1 , content2 . Id ) ;
2016-05-27 11:34:03 +02:00
Assert . AreEqual ( 2 , _msgCount ) ;
Assert . AreEqual ( 2 , _events . Count ) ;
2020-12-23 11:35:49 +01:00
int i = 0 ;
int m = 0 ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentRepository/Refresh/{content1.Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
m + + ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentCacheRefresher/RefreshBranch/{content1.Id}" , _events [ i ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
}
[Test]
2023-09-12 14:16:27 +02:00
[LongRunning]
2016-05-27 11:34:03 +02:00
public void MoveUnpublishedContentUnderMasked ( )
{
2020-12-23 11:35:49 +01:00
IContent content1 = CreateContent ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content1 ) ;
2020-12-23 11:35:49 +01:00
IContent content2 = CreateContent ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content2 ) ;
2023-11-22 12:52:08 +01:00
ContentService . Publish ( content2 , content2 . AvailableCultures . ToArray ( ) ) ;
2020-12-23 11:35:49 +01:00
IContent content3 = CreateContent ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content3 ) ;
2023-11-22 12:52:08 +01:00
ContentService . Publish ( content3 , content3 . AvailableCultures . ToArray ( ) ) ;
2020-10-14 11:08:55 +02:00
ContentService . Unpublish ( content2 ) ;
2016-05-27 11:34:03 +02:00
ResetEvents ( ) ;
2020-10-14 11:08:55 +02:00
ContentService . Move ( content1 , content3 . Id ) ;
2016-05-27 11:34:03 +02:00
Assert . AreEqual ( 2 , _msgCount ) ;
Assert . AreEqual ( 2 , _events . Count ) ;
2020-12-23 11:35:49 +01:00
int i = 0 ;
int m = 0 ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentRepository/Refresh/{content1.Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
m + + ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentCacheRefresher/RefreshBranch/{content1.Id}" , _events [ i ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
}
[Test]
public void MovePublishedContentUnderPublished ( )
{
2020-12-23 11:35:49 +01:00
IContent content1 = CreateContent ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content1 ) ;
2023-11-22 12:52:08 +01:00
ContentService . Publish ( content1 , content1 . AvailableCultures . ToArray ( ) ) ;
2020-12-23 11:35:49 +01:00
IContent content2 = CreateContent ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content2 ) ;
2023-11-22 12:52:08 +01:00
ContentService . Publish ( content2 , content2 . AvailableCultures . ToArray ( ) ) ;
2016-05-27 11:34:03 +02:00
ResetEvents ( ) ;
2020-10-14 11:08:55 +02:00
ContentService . Move ( content1 , content2 . Id ) ;
2016-05-27 11:34:03 +02:00
Assert . AreEqual ( 2 , _msgCount ) ;
Assert . AreEqual ( 2 , _events . Count ) ;
2020-12-23 11:35:49 +01:00
int i = 0 ;
int m = 0 ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentRepository/Refresh/{content1.Id}.p=p" , _events [ i + + ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
m + + ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentCacheRefresher/RefreshBranch/{content1.Id}" , _events [ i ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
}
[Test]
public void MovePublishedContentUnderMasked ( )
{
2020-12-23 11:35:49 +01:00
IContent content1 = CreateContent ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content1 ) ;
2023-11-22 12:52:08 +01:00
ContentService . Publish ( content1 , content1 . AvailableCultures . ToArray ( ) ) ;
2020-12-23 11:35:49 +01:00
IContent content2 = CreateContent ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content2 ) ;
2023-11-22 12:52:08 +01:00
ContentService . Publish ( content2 , content2 . AvailableCultures . ToArray ( ) ) ;
2020-12-23 11:35:49 +01:00
IContent content3 = CreateContent ( content2 . Id ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content3 ) ;
2023-11-22 12:52:08 +01:00
ContentService . Publish ( content3 , content3 . AvailableCultures . ToArray ( ) ) ;
2020-10-14 11:08:55 +02:00
ContentService . Unpublish ( content2 ) ;
2016-05-27 11:34:03 +02:00
ResetEvents ( ) ;
2020-10-14 11:08:55 +02:00
ContentService . Move ( content1 , content3 . Id ) ;
2016-05-27 11:34:03 +02:00
Assert . AreEqual ( 2 , _msgCount ) ;
Assert . AreEqual ( 2 , _events . Count ) ;
2020-12-23 11:35:49 +01:00
int i = 0 ;
int m = 0 ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentRepository/Refresh/{content1.Id}.p=m" , _events [ i + + ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
m + + ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentCacheRefresher/RefreshBranch/{content1.Id}" , _events [ i ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
}
[Test]
2023-09-12 14:16:27 +02:00
[LongRunning]
2016-05-27 11:34:03 +02:00
public void MovePublishedContentWithChangesUnderPublished ( )
{
2020-12-23 11:35:49 +01:00
IContent content1 = CreateContent ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content1 ) ;
2023-11-22 12:52:08 +01:00
ContentService . Publish ( content1 , content1 . AvailableCultures . ToArray ( ) ) ;
2017-11-07 19:49:14 +01:00
content1 . Properties . First ( ) . SetValue ( "changed" ) ;
2020-10-14 11:08:55 +02:00
ContentService . Save ( content1 ) ;
2020-12-23 11:35:49 +01:00
IContent content2 = CreateContent ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content2 ) ;
2023-11-22 12:52:08 +01:00
ContentService . Publish ( content2 , content2 . AvailableCultures . ToArray ( ) ) ;
2016-05-27 11:34:03 +02:00
ResetEvents ( ) ;
2020-10-14 11:08:55 +02:00
ContentService . Move ( content1 , content2 . Id ) ;
2016-05-27 11:34:03 +02:00
Assert . AreEqual ( 2 , _msgCount ) ;
Assert . AreEqual ( 2 , _events . Count ) ;
2020-12-23 11:35:49 +01:00
int i = 0 ;
int m = 0 ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentRepository/Refresh/{content1.Id}.p=p" , _events [ i + + ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
m + + ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentCacheRefresher/RefreshBranch/{content1.Id}" , _events [ i ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
}
[Test]
public void MovePublishedContentWithChangesUnderMasked ( )
{
2020-12-23 11:35:49 +01:00
IContent content1 = CreateContent ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content1 ) ;
2023-11-22 12:52:08 +01:00
ContentService . Publish ( content1 , content1 . AvailableCultures . ToArray ( ) ) ;
2017-11-07 19:49:14 +01:00
content1 . Properties . First ( ) . SetValue ( "changed" ) ;
2020-10-14 11:08:55 +02:00
ContentService . Save ( content1 ) ;
2020-12-23 11:35:49 +01:00
IContent content2 = CreateContent ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content2 ) ;
2023-11-22 12:52:08 +01:00
ContentService . Publish ( content2 , content2 . AvailableCultures . ToArray ( ) ) ;
2020-12-23 11:35:49 +01:00
IContent content3 = CreateContent ( content2 . Id ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content3 ) ;
2023-11-22 12:52:08 +01:00
ContentService . Publish ( content3 , content3 . AvailableCultures . ToArray ( ) ) ;
2020-10-14 11:08:55 +02:00
ContentService . Unpublish ( content2 ) ;
2016-05-27 11:34:03 +02:00
ResetEvents ( ) ;
2020-10-14 11:08:55 +02:00
ContentService . Move ( content1 , content3 . Id ) ;
2016-05-27 11:34:03 +02:00
Assert . AreEqual ( 2 , _msgCount ) ;
Assert . AreEqual ( 2 , _events . Count ) ;
2020-12-23 11:35:49 +01:00
int i = 0 ;
int m = 0 ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentRepository/Refresh/{content1.Id}.p=m" , _events [ i + + ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
m + + ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentCacheRefresher/RefreshBranch/{content1.Id}" , _events [ i ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
}
[Test]
2023-09-12 14:16:27 +02:00
[LongRunning]
2016-05-27 11:34:03 +02:00
public void MoveMaskedPublishedContentUnderPublished ( )
{
2020-12-23 11:35:49 +01:00
IContent content1 = CreateContent ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content1 ) ;
2023-11-22 12:52:08 +01:00
ContentService . Publish ( content1 , content1 . AvailableCultures . ToArray ( ) ) ;
2020-12-23 11:35:49 +01:00
IContent content2 = CreateContent ( content1 . Id ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content2 ) ;
2023-11-22 12:52:08 +01:00
ContentService . Publish ( content2 , content2 . AvailableCultures . ToArray ( ) ) ;
2020-10-14 11:08:55 +02:00
ContentService . Unpublish ( content1 ) ;
2020-12-23 11:35:49 +01:00
IContent content3 = CreateContent ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content3 ) ;
2023-11-22 12:52:08 +01:00
ContentService . Publish ( content3 , content3 . AvailableCultures . ToArray ( ) ) ;
2016-05-27 11:34:03 +02:00
ResetEvents ( ) ;
2020-10-14 11:08:55 +02:00
ContentService . Move ( content2 , content3 . Id ) ;
2016-05-27 11:34:03 +02:00
Assert . AreEqual ( 2 , _msgCount ) ;
Assert . AreEqual ( 2 , _events . Count ) ;
2020-12-23 11:35:49 +01:00
int i = 0 ;
int m = 0 ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentRepository/Refresh/{content2.Id}.p=p" , _events [ i + + ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
m + + ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentCacheRefresher/RefreshBranch/{content2.Id}" , _events [ i ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
}
[Test]
2023-09-12 14:16:27 +02:00
[LongRunning]
2016-05-27 11:34:03 +02:00
public void MoveMaskedPublishedContentUnderMasked ( )
{
2020-12-23 11:35:49 +01:00
IContent content1 = CreateContent ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content1 ) ;
2023-11-22 12:52:08 +01:00
ContentService . Publish ( content1 , content1 . AvailableCultures . ToArray ( ) ) ;
2020-12-23 11:35:49 +01:00
IContent content2 = CreateContent ( content1 . Id ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content2 ) ;
2023-11-22 12:52:08 +01:00
ContentService . Publish ( content2 , content2 . AvailableCultures . ToArray ( ) ) ;
2020-10-14 11:08:55 +02:00
ContentService . Unpublish ( content1 ) ;
2020-12-23 11:35:49 +01:00
IContent content3 = CreateContent ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content3 ) ;
2023-11-22 12:52:08 +01:00
ContentService . Publish ( content3 , content3 . AvailableCultures . ToArray ( ) ) ;
2020-12-23 11:35:49 +01:00
IContent content4 = CreateContent ( content3 . Id ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content4 ) ;
2023-11-22 12:52:08 +01:00
ContentService . Publish ( content4 , content4 . AvailableCultures . ToArray ( ) ) ;
2020-10-14 11:08:55 +02:00
ContentService . Unpublish ( content3 ) ;
2016-05-27 11:34:03 +02:00
ResetEvents ( ) ;
2020-10-14 11:08:55 +02:00
ContentService . Move ( content2 , content4 . Id ) ;
2016-05-27 11:34:03 +02:00
Assert . AreEqual ( 2 , _msgCount ) ;
Assert . AreEqual ( 2 , _events . Count ) ;
2020-12-23 11:35:49 +01:00
int i = 0 ;
int m = 0 ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentRepository/Refresh/{content2.Id}.p=m" , _events [ i + + ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
m + + ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentCacheRefresher/RefreshBranch/{content2.Id}" , _events [ i ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
}
[Test]
public void MoveMaskedPublishedContentWithChangesUnderPublished ( )
{
2020-12-23 11:35:49 +01:00
IContent content1 = CreateContent ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content1 ) ;
2023-11-22 12:52:08 +01:00
ContentService . Publish ( content1 , content1 . AvailableCultures . ToArray ( ) ) ;
2020-12-23 11:35:49 +01:00
IContent content2 = CreateContent ( content1 . Id ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content2 ) ;
2023-11-22 12:52:08 +01:00
ContentService . Publish ( content2 , content2 . AvailableCultures . ToArray ( ) ) ;
2017-11-07 19:49:14 +01:00
content2 . Properties . First ( ) . SetValue ( "changed" ) ;
2020-10-14 11:08:55 +02:00
ContentService . Save ( content2 ) ;
ContentService . Unpublish ( content1 ) ;
2020-12-23 11:35:49 +01:00
IContent content3 = CreateContent ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content3 ) ;
2023-11-22 12:52:08 +01:00
ContentService . Publish ( content3 , content3 . AvailableCultures . ToArray ( ) ) ;
2016-05-27 11:34:03 +02:00
ResetEvents ( ) ;
2020-10-14 11:08:55 +02:00
ContentService . Move ( content2 , content3 . Id ) ;
2016-05-27 11:34:03 +02:00
Assert . AreEqual ( 2 , _msgCount ) ;
Assert . AreEqual ( 2 , _events . Count ) ;
2020-12-23 11:35:49 +01:00
int i = 0 ;
int m = 0 ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentRepository/Refresh/{content2.Id}.p=p" , _events [ i + + ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
m + + ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentCacheRefresher/RefreshBranch/{content2.Id}" , _events [ i ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
}
[Test]
2023-09-12 14:16:27 +02:00
[LongRunning]
2016-05-27 11:34:03 +02:00
public void MoveMaskedPublishedContentWithChangesUnderMasked ( )
{
2020-12-23 11:35:49 +01:00
IContent content1 = CreateContent ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content1 ) ;
2023-11-22 12:52:08 +01:00
ContentService . Publish ( content1 , content1 . AvailableCultures . ToArray ( ) ) ;
2020-12-23 11:35:49 +01:00
IContent content2 = CreateContent ( content1 . Id ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content2 ) ;
2023-11-22 12:52:08 +01:00
ContentService . Publish ( content2 , content2 . AvailableCultures . ToArray ( ) ) ;
2017-11-07 19:49:14 +01:00
content2 . Properties . First ( ) . SetValue ( "changed" ) ;
2020-10-14 11:08:55 +02:00
ContentService . Save ( content2 ) ;
ContentService . Unpublish ( content1 ) ;
2020-12-23 11:35:49 +01:00
IContent content3 = CreateContent ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content3 ) ;
2023-11-22 12:52:08 +01:00
ContentService . Publish ( content3 , content3 . AvailableCultures . ToArray ( ) ) ;
2020-12-23 11:35:49 +01:00
IContent content4 = CreateContent ( content3 . Id ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content4 ) ;
2023-11-22 12:52:08 +01:00
ContentService . Publish ( content4 , content4 . AvailableCultures . ToArray ( ) ) ;
2020-10-14 11:08:55 +02:00
ContentService . Unpublish ( content3 ) ;
2016-05-27 11:34:03 +02:00
ResetEvents ( ) ;
2020-10-14 11:08:55 +02:00
ContentService . Move ( content2 , content4 . Id ) ;
2016-05-27 11:34:03 +02:00
Assert . AreEqual ( 2 , _msgCount ) ;
Assert . AreEqual ( 2 , _events . Count ) ;
2020-12-23 11:35:49 +01:00
int i = 0 ;
int m = 0 ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentRepository/Refresh/{content2.Id}.p=m" , _events [ i + + ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
m + + ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentCacheRefresher/RefreshBranch/{content2.Id}" , _events [ i ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
}
[Test]
2023-09-12 14:16:27 +02:00
[LongRunning]
2016-05-27 11:34:03 +02:00
public void MoveMaskedPublishedContentUnderUnpublished ( )
{
2020-12-23 11:35:49 +01:00
IContent content1 = CreateContent ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content1 ) ;
2023-11-22 12:52:08 +01:00
ContentService . Publish ( content1 , content1 . AvailableCultures . ToArray ( ) ) ;
2020-12-23 11:35:49 +01:00
IContent content2 = CreateContent ( content1 . Id ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content2 ) ;
2023-11-22 12:52:08 +01:00
ContentService . Publish ( content2 , content2 . AvailableCultures . ToArray ( ) ) ;
2020-10-14 11:08:55 +02:00
ContentService . Unpublish ( content1 ) ;
2020-12-23 11:35:49 +01:00
IContent content3 = CreateContent ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content3 ) ;
ResetEvents ( ) ;
2020-10-14 11:08:55 +02:00
ContentService . Move ( content2 , content3 . Id ) ;
2016-05-27 11:34:03 +02:00
Assert . AreEqual ( 2 , _msgCount ) ;
Assert . AreEqual ( 2 , _events . Count ) ;
2020-12-23 11:35:49 +01:00
int i = 0 ;
int m = 0 ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentRepository/Refresh/{content2.Id}.p=m" , _events [ i + + ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
m + + ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentCacheRefresher/RefreshBranch/{content2.Id}" , _events [ i ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
}
[Test]
public void MoveMaskedPublishedContentWithChangesUnderUnpublished ( )
{
2020-12-23 11:35:49 +01:00
IContent content1 = CreateContent ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content1 ) ;
2023-11-22 12:52:08 +01:00
ContentService . Publish ( content1 , content1 . AvailableCultures . ToArray ( ) ) ;
2020-12-23 11:35:49 +01:00
IContent content2 = CreateContent ( content1 . Id ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content2 ) ;
2023-11-22 12:52:08 +01:00
ContentService . Publish ( content2 , content2 . AvailableCultures . ToArray ( ) ) ;
2017-11-07 19:49:14 +01:00
content2 . Properties . First ( ) . SetValue ( "changed" ) ;
2020-10-14 11:08:55 +02:00
ContentService . Save ( content2 ) ;
ContentService . Unpublish ( content1 ) ;
2020-12-23 11:35:49 +01:00
IContent content3 = CreateContent ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content3 ) ;
ResetEvents ( ) ;
2020-10-14 11:08:55 +02:00
ContentService . Move ( content2 , content3 . Id ) ;
2016-05-27 11:34:03 +02:00
Assert . AreEqual ( 2 , _msgCount ) ;
Assert . AreEqual ( 2 , _events . Count ) ;
2020-12-23 11:35:49 +01:00
int i = 0 ;
int m = 0 ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentRepository/Refresh/{content2.Id}.p=m" , _events [ i + + ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
m + + ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentCacheRefresher/RefreshBranch/{content2.Id}" , _events [ i ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
}
[Test]
2023-09-12 14:16:27 +02:00
[LongRunning]
2016-05-27 11:34:03 +02:00
public void MoveContentBranchUnderUnpublished ( )
{
2020-12-23 11:35:49 +01:00
IContent content1 = CreateBranch ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content1 ) ;
2020-12-23 11:35:49 +01:00
IContent content2 = CreateContent ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content2 ) ;
ResetEvents ( ) ;
2020-10-14 11:08:55 +02:00
ContentService . Move ( content1 , content2 . Id ) ;
2016-05-27 11:34:03 +02:00
Assert . AreEqual ( 14 , _msgCount ) ;
Assert . AreEqual ( 14 , _events . Count ) ;
2020-12-23 11:35:49 +01:00
int i = 0 ;
int m = 0 ;
IContent [ ] content1C = Children ( content1 ) . ToArray ( ) ;
IContent [ ] content2C = Children ( content1C [ 0 ] ) . ToArray ( ) ;
IContent [ ] content3C = Children ( content1C [ 1 ] ) . ToArray ( ) ;
IContent [ ] content4C = Children ( content1C [ 2 ] ) . ToArray ( ) ;
IContent [ ] content5C = Children ( content1C [ 3 ] ) . ToArray ( ) ;
2020-12-27 09:50:56 +01:00
#pragma warning disable SA1003 // Symbols should be spaced correctly (justification: suppression necessary here as it's used in an interpolated string format.
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content1.Id}.p=m" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content1C[0].Id}.p=m" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content2C[0].Id}.p=m" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content2C[1].Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
2018-10-31 22:38:58 +11:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content1C[1].Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content3C[0].Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content3C[1].Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
2018-10-31 22:38:58 +11:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content1C[2].Id}.p=m" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content4C[0].Id}.p=m" , _events [ i + + ] . ToString ( ) ) ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content4C[1].Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
2018-10-31 22:38:58 +11:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content1C[3].Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content5C[0].Id}.p=m" , _events [ i + + ] . ToString ( ) ) ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentRepository/Refresh/{content5C[1].Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
m + + ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentCacheRefresher/RefreshBranch/{content1.Id}" , _events [ i + + ] . ToString ( ) ) ;
2020-12-23 11:35:49 +01:00
#pragma warning restore SA1003 // Symbols should be spaced correctly
2016-05-27 11:34:03 +02:00
}
[Test]
2023-09-12 14:16:27 +02:00
[LongRunning]
2016-05-27 11:34:03 +02:00
public void MoveContentBranchUnderPublished ( )
{
2020-12-23 11:35:49 +01:00
IContent content1 = CreateBranch ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content1 ) ;
2020-12-23 11:35:49 +01:00
IContent content2 = CreateContent ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content2 ) ;
2023-11-22 12:52:08 +01:00
ContentService . Publish ( content2 , content2 . AvailableCultures . ToArray ( ) ) ;
2016-05-27 11:34:03 +02:00
ResetEvents ( ) ;
2020-10-14 11:08:55 +02:00
ContentService . Move ( content1 , content2 . Id ) ;
2016-05-27 11:34:03 +02:00
Assert . AreEqual ( 14 , _msgCount ) ;
Assert . AreEqual ( 14 , _events . Count ) ;
2020-12-23 11:35:49 +01:00
int i = 0 ;
int m = 0 ;
IContent [ ] content1C = Children ( content1 ) . ToArray ( ) ;
IContent [ ] content2C = Children ( content1C [ 0 ] ) . ToArray ( ) ;
IContent [ ] content3C = Children ( content1C [ 1 ] ) . ToArray ( ) ;
IContent [ ] content4C = Children ( content1C [ 2 ] ) . ToArray ( ) ;
IContent [ ] content5C = Children ( content1C [ 3 ] ) . ToArray ( ) ;
2020-12-27 09:50:56 +01:00
#pragma warning disable SA1003 // Symbols should be spaced correctly (justification: suppression necessary here as it's used in an interpolated string format.
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content1.Id}.p=p" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content1C[0].Id}.p=p" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content2C[0].Id}.p=p" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content2C[1].Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
2018-10-31 22:38:58 +11:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content1C[1].Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content3C[0].Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content3C[1].Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
2018-10-31 22:38:58 +11:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content1C[2].Id}.p=p" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content4C[0].Id}.p=p" , _events [ i + + ] . ToString ( ) ) ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content4C[1].Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
2018-10-31 22:38:58 +11:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content1C[3].Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content5C[0].Id}.p=m" , _events [ i + + ] . ToString ( ) ) ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentRepository/Refresh/{content5C[1].Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
m + + ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentCacheRefresher/RefreshBranch/{content1.Id}" , _events [ i + + ] . ToString ( ) ) ;
2020-12-23 11:35:49 +01:00
#pragma warning restore SA1003 // Symbols should be spaced correctly
2016-05-27 11:34:03 +02:00
}
[Test]
2023-09-12 14:16:27 +02:00
[LongRunning]
2016-05-27 11:34:03 +02:00
public void MoveContentBranchUnderMasked ( )
{
2020-12-23 11:35:49 +01:00
IContent content1 = CreateBranch ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content1 ) ;
2020-12-23 11:35:49 +01:00
IContent content2 = CreateContent ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content2 ) ;
2023-11-22 12:52:08 +01:00
ContentService . Publish ( content2 , content2 . AvailableCultures . ToArray ( ) ) ;
2020-12-23 11:35:49 +01:00
IContent content3 = CreateContent ( content2 . Id ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content3 ) ;
2023-11-22 12:52:08 +01:00
ContentService . Publish ( content3 , content3 . AvailableCultures . ToArray ( ) ) ;
2020-10-14 11:08:55 +02:00
ContentService . Unpublish ( content2 ) ;
2016-05-27 11:34:03 +02:00
ResetEvents ( ) ;
2020-10-14 11:08:55 +02:00
ContentService . Move ( content1 , content3 . Id ) ;
2016-05-27 11:34:03 +02:00
Assert . AreEqual ( 14 , _msgCount ) ;
Assert . AreEqual ( 14 , _events . Count ) ;
2020-12-23 11:35:49 +01:00
int i = 0 ;
int m = 0 ;
IContent [ ] content1C = Children ( content1 ) . ToArray ( ) ;
IContent [ ] content2C = Children ( content1C [ 0 ] ) . ToArray ( ) ;
IContent [ ] content3C = Children ( content1C [ 1 ] ) . ToArray ( ) ;
IContent [ ] content4C = Children ( content1C [ 2 ] ) . ToArray ( ) ;
IContent [ ] content5C = Children ( content1C [ 3 ] ) . ToArray ( ) ;
2020-12-27 09:50:56 +01:00
#pragma warning disable SA1003 // Symbols should be spaced correctly (justification: suppression necessary here as it's used in an interpolated string format.
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content1.Id}.p=m" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content1C[0].Id}.p=m" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content2C[0].Id}.p=m" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content2C[1].Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
2018-10-31 22:38:58 +11:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content1C[1].Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content3C[0].Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content3C[1].Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
2018-10-31 22:38:58 +11:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content1C[2].Id}.p=m" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content4C[0].Id}.p=m" , _events [ i + + ] . ToString ( ) ) ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content4C[1].Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
2018-10-31 22:38:58 +11:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content1C[3].Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content5C[0].Id}.p=m" , _events [ i + + ] . ToString ( ) ) ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentRepository/Refresh/{content5C[1].Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
m + + ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentCacheRefresher/RefreshBranch/{content1.Id}" , _events [ i + + ] . ToString ( ) ) ;
2020-12-23 11:35:49 +01:00
#pragma warning restore SA1003 // Symbols should be spaced correctly
2016-05-27 11:34:03 +02:00
}
[Test]
2023-09-12 14:16:27 +02:00
[LongRunning]
2016-05-27 11:34:03 +02:00
public void MoveContentBranchBackFromPublished ( )
{
2020-12-23 11:35:49 +01:00
IContent content1 = CreateBranch ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content1 ) ;
2020-12-23 11:35:49 +01:00
IContent content2 = CreateContent ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content2 ) ;
2023-11-22 12:52:08 +01:00
ContentService . Publish ( content2 , content2 . AvailableCultures . ToArray ( ) ) ;
2016-05-27 11:34:03 +02:00
2020-10-14 11:08:55 +02:00
ContentService . Move ( content1 , content2 . Id ) ;
2016-05-27 11:34:03 +02:00
ResetEvents ( ) ;
2020-10-14 11:08:55 +02:00
ContentService . Move ( content1 , - 1 ) ;
2016-05-27 11:34:03 +02:00
Assert . AreEqual ( 14 , _msgCount ) ;
Assert . AreEqual ( 14 , _events . Count ) ;
2020-12-23 11:35:49 +01:00
int i = 0 ;
int m = 0 ;
IContent [ ] content1C = Children ( content1 ) . ToArray ( ) ;
IContent [ ] content2C = Children ( content1C [ 0 ] ) . ToArray ( ) ;
IContent [ ] content3C = Children ( content1C [ 1 ] ) . ToArray ( ) ;
IContent [ ] content4C = Children ( content1C [ 2 ] ) . ToArray ( ) ;
IContent [ ] content5C = Children ( content1C [ 3 ] ) . ToArray ( ) ;
2020-12-27 09:50:56 +01:00
#pragma warning disable SA1003 // Symbols should be spaced correctly (justification: suppression necessary here as it's used in an interpolated string format.
2017-12-06 09:58:50 +01:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content1.Id}.p=p" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content1C[0].Id}.p=p" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content2C[0].Id}.p=p" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content2C[1].Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
2018-10-31 22:38:58 +11:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content1C[1].Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content3C[0].Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
2017-12-06 09:58:50 +01:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content3C[1].Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
2018-10-31 22:38:58 +11:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content1C[2].Id}.p=p" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content4C[0].Id}.p=p" , _events [ i + + ] . ToString ( ) ) ;
2017-12-06 09:58:50 +01:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content4C[1].Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
2018-10-31 22:38:58 +11:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content1C[3].Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content5C[0].Id}.p=m" , _events [ i + + ] . ToString ( ) ) ;
2017-12-06 09:58:50 +01:00
Assert . AreEqual ( $"{m:000}: ContentRepository/Refresh/{content5C[1].Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
m + + ;
2017-12-06 09:58:50 +01:00
Assert . AreEqual ( $"{m:000}: ContentCacheRefresher/RefreshBranch/{content1.Id}" , _events [ i + + ] . ToString ( ) ) ;
2020-12-23 11:35:49 +01:00
#pragma warning restore SA1003 // Symbols should be spaced correctly
2016-05-27 11:34:03 +02:00
}
[Test]
2023-09-12 14:16:27 +02:00
[LongRunning]
2016-05-27 11:34:03 +02:00
public void MoveContentBranchBackFromUnpublished ( )
{
2020-12-23 11:35:49 +01:00
IContent content1 = CreateBranch ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content1 ) ;
2020-12-23 11:35:49 +01:00
IContent content2 = CreateContent ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content2 ) ;
2020-10-14 11:08:55 +02:00
ContentService . Move ( content1 , content2 . Id ) ;
2016-05-27 11:34:03 +02:00
ResetEvents ( ) ;
2020-10-14 11:08:55 +02:00
ContentService . Move ( content1 , - 1 ) ;
2016-05-27 11:34:03 +02:00
Assert . AreEqual ( 14 , _msgCount ) ;
Assert . AreEqual ( 14 , _events . Count ) ;
2020-12-23 11:35:49 +01:00
int i = 0 ;
int m = 0 ;
IContent [ ] content1C = Children ( content1 ) . ToArray ( ) ;
IContent [ ] content2C = Children ( content1C [ 0 ] ) . ToArray ( ) ;
IContent [ ] content3C = Children ( content1C [ 1 ] ) . ToArray ( ) ;
IContent [ ] content4C = Children ( content1C [ 2 ] ) . ToArray ( ) ;
IContent [ ] content5C = Children ( content1C [ 3 ] ) . ToArray ( ) ;
2020-12-27 09:50:56 +01:00
#pragma warning disable SA1003 // Symbols should be spaced correctly (justification: suppression necessary here as it's used in an interpolated string format.
2017-12-06 09:58:50 +01:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content1.Id}.p=p" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content1C[0].Id}.p=p" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content2C[0].Id}.p=p" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content2C[1].Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
2018-10-31 22:38:58 +11:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content1C[1].Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content3C[0].Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
2017-12-06 09:58:50 +01:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content3C[1].Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
2018-10-31 22:38:58 +11:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content1C[2].Id}.p=p" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content4C[0].Id}.p=p" , _events [ i + + ] . ToString ( ) ) ;
2017-12-06 09:58:50 +01:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content4C[1].Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
2018-10-31 22:38:58 +11:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content1C[3].Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content5C[0].Id}.p=m" , _events [ i + + ] . ToString ( ) ) ;
2017-12-06 09:58:50 +01:00
Assert . AreEqual ( $"{m:000}: ContentRepository/Refresh/{content5C[1].Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
m + + ;
2017-12-06 09:58:50 +01:00
Assert . AreEqual ( $"{m:000}: ContentCacheRefresher/RefreshBranch/{content1.Id}" , _events [ i + + ] . ToString ( ) ) ;
2020-12-23 11:35:49 +01:00
#pragma warning restore SA1003 // Symbols should be spaced correctly
2016-05-27 11:34:03 +02:00
}
[Test]
2023-09-12 14:16:27 +02:00
[LongRunning]
2016-05-27 11:34:03 +02:00
public void MoveContentBranchBackFromMasked ( )
{
2020-12-23 11:35:49 +01:00
IContent content1 = CreateBranch ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content1 ) ;
2020-12-23 11:35:49 +01:00
IContent content2 = CreateContent ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content2 ) ;
2023-11-22 12:52:08 +01:00
ContentService . Publish ( content2 , content2 . AvailableCultures . ToArray ( ) ) ;
2020-12-23 11:35:49 +01:00
IContent content3 = CreateContent ( content2 . Id ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content3 ) ;
2023-11-22 12:52:08 +01:00
ContentService . Publish ( content3 , content3 . AvailableCultures . ToArray ( ) ) ;
2020-10-14 11:08:55 +02:00
ContentService . Unpublish ( content2 ) ;
2016-05-27 11:34:03 +02:00
2020-10-14 11:08:55 +02:00
ContentService . Move ( content1 , content3 . Id ) ;
2016-05-27 11:34:03 +02:00
ResetEvents ( ) ;
2020-10-14 11:08:55 +02:00
ContentService . Move ( content1 , - 1 ) ;
2016-05-27 11:34:03 +02:00
Assert . AreEqual ( 14 , _msgCount ) ;
Assert . AreEqual ( 14 , _events . Count ) ;
2020-12-23 11:35:49 +01:00
int i = 0 ;
int m = 0 ;
IContent [ ] content1C = Children ( content1 ) . ToArray ( ) ;
IContent [ ] content2C = Children ( content1C [ 0 ] ) . ToArray ( ) ;
IContent [ ] content3C = Children ( content1C [ 1 ] ) . ToArray ( ) ;
IContent [ ] content4C = Children ( content1C [ 2 ] ) . ToArray ( ) ;
IContent [ ] content5C = Children ( content1C [ 3 ] ) . ToArray ( ) ;
2020-12-27 09:50:56 +01:00
#pragma warning disable SA1003 // Symbols should be spaced correctly (justification: suppression necessary here as it's used in an interpolated string format.
2017-12-06 09:58:50 +01:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content1.Id}.p=p" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content1C[0].Id}.p=p" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content2C[0].Id}.p=p" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content2C[1].Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
2018-10-31 22:38:58 +11:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content1C[1].Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content3C[0].Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
2017-12-06 09:58:50 +01:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content3C[1].Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
2018-10-31 22:38:58 +11:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content1C[2].Id}.p=p" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content4C[0].Id}.p=p" , _events [ i + + ] . ToString ( ) ) ;
2017-12-06 09:58:50 +01:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content4C[1].Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
2018-10-31 22:38:58 +11:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content1C[3].Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content5C[0].Id}.p=m" , _events [ i + + ] . ToString ( ) ) ;
2017-12-06 09:58:50 +01:00
Assert . AreEqual ( $"{m:000}: ContentRepository/Refresh/{content5C[1].Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
m + + ;
2017-12-06 09:58:50 +01:00
Assert . AreEqual ( $"{m:000}: ContentCacheRefresher/RefreshBranch/{content1.Id}" , _events [ i + + ] . ToString ( ) ) ;
2020-12-23 11:35:49 +01:00
#pragma warning restore SA1003 // Symbols should be spaced correctly
2016-05-27 11:34:03 +02:00
}
2020-12-27 09:50:56 +01:00
#endregion
#region Copy
2016-05-27 11:34:03 +02:00
[Test]
2023-09-12 14:16:27 +02:00
[LongRunning]
2016-05-27 11:34:03 +02:00
public void CopyUnpublishedContent ( )
{
2020-12-23 11:35:49 +01:00
IContent content = CreateContent ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content ) ;
ResetEvents ( ) ;
2020-12-23 11:35:49 +01:00
IContent copy = ContentService . Copy ( content , Constants . System . Root , false ) ;
2016-05-27 11:34:03 +02:00
Assert . AreEqual ( 2 , _msgCount ) ;
Assert . AreEqual ( 2 , _events . Count ) ;
2020-12-23 11:35:49 +01:00
int i = 0 ;
int m = 0 ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentRepository/Refresh/{copy.Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
m + + ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentCacheRefresher/RefreshBranch/{copy.Id}" , _events [ i ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
}
[Test]
2023-09-12 14:16:27 +02:00
[LongRunning]
2016-05-27 11:34:03 +02:00
public void CopyPublishedContent ( )
{
2020-12-23 11:35:49 +01:00
IContent content = CreateContent ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content ) ;
2023-11-22 12:52:08 +01:00
ContentService . Publish ( content , content . AvailableCultures . ToArray ( ) ) ;
2016-05-27 11:34:03 +02:00
ResetEvents ( ) ;
2020-12-23 11:35:49 +01:00
IContent copy = ContentService . Copy ( content , Constants . System . Root , false ) ;
2016-05-27 11:34:03 +02:00
Assert . AreEqual ( 2 , _msgCount ) ;
Assert . AreEqual ( 2 , _events . Count ) ;
2020-12-23 11:35:49 +01:00
int i = 0 ;
int m = 0 ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentRepository/Refresh/{copy.Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
m + + ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentCacheRefresher/RefreshBranch/{copy.Id}" , _events [ i ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
}
[Test]
2023-09-12 14:16:27 +02:00
[LongRunning]
2016-05-27 11:34:03 +02:00
public void CopyMaskedContent ( )
{
2020-12-23 11:35:49 +01:00
IContent content = CreateContent ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content ) ;
2023-11-22 12:52:08 +01:00
ContentService . Publish ( content , content . AvailableCultures . ToArray ( ) ) ;
2020-12-23 11:35:49 +01:00
IContent content2 = CreateContent ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content2 ) ;
2020-10-14 11:08:55 +02:00
ContentService . Move ( content , content2 . Id ) ;
2016-05-27 11:34:03 +02:00
ResetEvents ( ) ;
2020-12-23 11:35:49 +01:00
IContent copy = ContentService . Copy ( content , Constants . System . Root , false ) ;
2016-05-27 11:34:03 +02:00
Assert . AreEqual ( 2 , _msgCount ) ;
Assert . AreEqual ( 2 , _events . Count ) ;
2020-12-23 11:35:49 +01:00
int i = 0 ;
int m = 0 ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentRepository/Refresh/{copy.Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
m + + ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentCacheRefresher/RefreshBranch/{copy.Id}" , _events [ i ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
}
[Test]
2023-09-12 14:16:27 +02:00
[LongRunning]
2016-05-27 11:34:03 +02:00
public void CopyBranch ( )
{
2020-12-23 11:35:49 +01:00
IContent content = CreateBranch ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content ) ;
2023-11-22 12:52:08 +01:00
ContentService . Publish ( content , content . AvailableCultures . ToArray ( ) ) ;
2016-05-27 11:34:03 +02:00
ResetEvents ( ) ;
2020-12-23 11:35:49 +01:00
IContent copy = ContentService . Copy ( content , Constants . System . Root , false ) ;
2016-05-27 11:34:03 +02:00
2020-12-23 11:35:49 +01:00
IContent [ ] copyC = Children ( copy ) . ToArray ( ) ;
IContent [ ] copy2C = Children ( copyC [ 0 ] ) . ToArray ( ) ;
IContent [ ] copy3C = Children ( copyC [ 1 ] ) . ToArray ( ) ;
IContent [ ] copy4C = Children ( copyC [ 2 ] ) . ToArray ( ) ;
IContent [ ] copy5C = Children ( copyC [ 3 ] ) . ToArray ( ) ;
2016-05-27 11:34:03 +02:00
Assert . AreEqual ( 14 , _msgCount ) ;
Assert . AreEqual ( 14 , _events . Count ) ;
2020-12-23 11:35:49 +01:00
int i = 0 ;
int m = 0 ;
2020-12-27 09:50:56 +01:00
#pragma warning disable SA1003 // Symbols should be spaced correctly (justification: suppression necessary here as it's used in an interpolated string format.
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{copy.Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{copyC[0].Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{copy2C[0].Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{copy2C[1].Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
2018-10-31 22:38:58 +11:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{copyC[1].Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{copy3C[0].Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{copy3C[1].Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
2018-10-31 22:38:58 +11:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{copyC[2].Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{copy4C[0].Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{copy4C[1].Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
2018-10-31 22:38:58 +11:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{copyC[3].Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{copy5C[0].Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentRepository/Refresh/{copy5C[1].Id}.u=u" , _events [ i + + ] . ToString ( ) ) ;
2016-05-27 11:34:03 +02:00
m + + ;
2017-12-02 16:14:21 +01:00
Assert . AreEqual ( $"{m:000}: ContentCacheRefresher/RefreshBranch/{copy.Id}" , _events [ i ] . ToString ( ) ) ;
2020-12-23 11:35:49 +01:00
#pragma warning restore SA1003 // Symbols should be spaced correctly
2016-05-27 11:34:03 +02:00
}
2020-12-27 09:50:56 +01:00
#endregion
#region Rollback
2016-05-27 11:34:03 +02:00
[Test]
2023-09-12 14:16:27 +02:00
[LongRunning]
2016-05-27 11:34:03 +02:00
public void Rollback ( )
{
2020-12-23 11:35:49 +01:00
IContent content = CreateContent ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content ) ;
2023-11-22 12:52:08 +01:00
ContentService . Publish ( content , Array . Empty < string > ( ) ) ;
2020-12-23 11:35:49 +01:00
int v1 = content . VersionId ;
2016-05-27 11:34:03 +02:00
2017-11-07 19:49:14 +01:00
content . Properties . First ( ) . SetValue ( "changed" ) ;
2023-11-22 12:52:08 +01:00
ContentService . Save ( content ) ;
ContentService . Publish ( content , Array . Empty < string > ( ) ) ;
2020-12-23 11:35:49 +01:00
int v2 = content . VersionId ;
2016-05-27 11:34:03 +02:00
2017-11-07 19:49:14 +01:00
content . Properties . First ( ) . SetValue ( "again" ) ;
2023-11-22 12:52:08 +01:00
ContentService . Save ( content ) ;
ContentService . Publish ( content , Array . Empty < string > ( ) ) ;
2020-12-23 11:35:49 +01:00
int v3 = content . VersionId ;
2016-05-27 11:34:03 +02:00
Console . WriteLine ( v1 ) ;
Console . WriteLine ( v2 ) ;
Console . WriteLine ( v3 ) ;
ResetEvents ( ) ;
2020-10-14 11:08:55 +02:00
content . CopyFrom ( ContentService . GetVersion ( v2 ) ) ;
ContentService . Save ( content ) ;
2016-05-27 11:34:03 +02:00
Assert . AreEqual ( 2 , _msgCount ) ;
Assert . AreEqual ( 2 , _events . Count ) ;
2020-12-23 11:35:49 +01:00
int i = 0 ;
int m = 0 ;
2020-12-27 09:50:56 +01:00
#pragma warning disable SA1003 // Symbols should be spaced correctly (justification: suppression necessary here as it's used in an interpolated string format.
2017-12-06 09:58:50 +01:00
Assert . AreEqual ( $"{m++:000}: ContentRepository/Refresh/{content.Id}.p=p" , _events [ i + + ] . ToString ( ) ) ;
Assert . AreEqual ( $"{m:000}: ContentCacheRefresher/RefreshNode/{content.Id}" , _events [ i ] . ToString ( ) ) ;
2020-12-23 11:35:49 +01:00
#pragma warning restore SA1003 // Symbols should be spaced correctly
2016-05-27 11:34:03 +02:00
}
2020-12-27 09:50:56 +01:00
#endregion
#region Misc
2016-05-27 11:34:03 +02:00
[Test]
2023-09-12 14:16:27 +02:00
[LongRunning]
2016-05-27 11:34:03 +02:00
public void ContentRemembers ( )
{
2020-12-23 11:35:49 +01:00
IContent content = ContentService . GetRootContent ( ) . FirstOrDefault ( ) ;
2016-05-27 11:34:03 +02:00
Assert . IsNotNull ( content ) ;
2020-10-14 11:08:55 +02:00
ContentService . Save ( content ) ;
2016-05-27 11:34:03 +02:00
Assert . IsFalse ( content . IsPropertyDirty ( "Published" ) ) ;
Assert . IsFalse ( content . WasPropertyDirty ( "Published" ) ) ;
2023-11-22 12:52:08 +01:00
ContentService . Publish ( content , Array . Empty < string > ( ) ) ;
2016-05-27 11:34:03 +02:00
Assert . IsFalse ( content . IsPropertyDirty ( "Published" ) ) ;
Assert . IsTrue ( content . WasPropertyDirty ( "Published" ) ) ; // has just been published
2023-11-22 12:52:08 +01:00
ContentService . Publish ( content , Array . Empty < string > ( ) ) ;
2016-05-27 11:34:03 +02:00
Assert . IsFalse ( content . IsPropertyDirty ( "Published" ) ) ;
Assert . IsFalse ( content . WasPropertyDirty ( "Published" ) ) ; // was published already
}
2017-12-02 16:14:21 +01:00
[Test]
2021-01-20 16:45:19 +01:00
public void HasInitialContent ( ) = > Assert . AreEqual ( 5 , ContentService . Count ( ) ) ;
2018-05-01 10:39:04 +10:00
2020-12-27 09:50:56 +01:00
#endregion
#region TODO
// all content type events
#endregion
2018-05-01 10:39:04 +10:00
public class LocalServerMessenger : ServerMessengerBase
{
2020-12-23 11:35:49 +01:00
public LocalServerMessenger ( )
2024-03-01 12:51:21 +01:00
: base ( false , new SystemTextJsonSerializer ( ) )
2020-12-23 11:35:49 +01:00
{
}
2018-05-01 10:39:04 +10:00
2020-12-24 14:44:42 +11:00
public override void SendMessages ( ) { }
2020-12-24 09:50:05 +11:00
public override void Sync ( ) { }
2018-05-01 10:39:04 +10:00
protected override void DeliverRemote ( ICacheRefresher refresher , MessageType messageType , IEnumerable < object > ids = null , string json = null )
{
}
}
2016-05-27 11:34:03 +02:00
}
}
2020-12-27 09:50:56 +01:00
#pragma warning restore SA1124 // Do not use regions