Example #1
0
        public async Task DraftDiscarded_PublishEventsDisabled_NoEventPublished()
        {
            await EventGridPublishingHandler.DraftDiscarded(OrchestrationContext);

            A.CallTo(() => EventGridContentClient.Publish(A <ContentEvent> ._, A <CancellationToken> ._))
            .MustNotHaveHappened();
        }
Example #2
0
        public async Task DeleteDraft_EventGridPublishingHandlerCalled()
        {
            await DeleteOrchestrator.Unpublish(ContentItem);

            A.CallTo(() => EventGridPublishingHandler.Unpublished(
                         A <IOrchestrationContext> .That.Matches(ctx => Equals(ctx.ContentItem, ContentItem))))
            .MustHaveHappened();
        }
Example #3
0
        public async Task Unpublished_PublishEventsEnabled_EventPublished()
        {
            EventGridConfiguration.PublishEvents = true;

            await EventGridPublishingHandler.Unpublished(OrchestrationContext);

            A.CallTo(() => EventGridContentClient.Publish(A <ContentEvent> ._, A <CancellationToken> ._))
            .MustHaveHappened();
        }
        public async Task Publish_EventGridPublishingHandlerCalled()
        {
            bool success = await DeleteOrchestrator.Delete(ContentItem);

            Assert.True(success);

            A.CallTo(() => EventGridPublishingHandler.Deleted(
                         A <IOrchestrationContext> .That.Matches(ctx => Equals(ctx.ContentItem, ContentItem))))
            .MustHaveHappened();
        }
        public async Task Clone_EventGridPublishingHandlerCalled(AllowSyncResult previewAllowSyncResult, int draftSavedCalled)
        {
            A.CallTo(() => PreviewAllowSync.Result)
            .Returns(previewAllowSyncResult);

            await SyncOrchestrator.Clone(ContentItem);

            A.CallTo(() => EventGridPublishingHandler.Cloned(
                         A <IOrchestrationContext> .That.Matches(ctx => Equals(ctx.ContentItem, ContentItem))))
            .MustHaveHappened(draftSavedCalled, Times.Exactly);
        }
Example #6
0
        public EventGridPublishingHandlerTests()
        {
            EventGridConfigurationOptionsMonitor = A.Fake <IOptionsMonitor <EventGridConfiguration> >();

            EventGridConfiguration = new EventGridConfiguration();
            A.CallTo(() => EventGridConfigurationOptionsMonitor.CurrentValue)
            .Returns(EventGridConfiguration);

            EventGridContentClient = A.Fake <IEventGridContentClient>();

            SyncNameProvider = A.Fake <ISyncNameProvider>();
            UserId           = "C7FE81FB-CF2B-4897-ABE9-1EB931A31371";
            A.CallTo(() => SyncNameProvider.GetEventIdPropertyValue(
                         A <JObject> ._,
                         A <IContentItemVersion> ._)).Returns(UserId);

            PublishedContentItemVersion    = A.Fake <IPublishedContentItemVersion>();
            PreviewContentItemVersion      = A.Fake <IPreviewContentItemVersion>();
            NeutralEventContentItemVersion = A.Fake <INeutralEventContentItemVersion>();
            Logger = A.Fake <ILogger <EventGridPublishingHandler> >();

            EventGridPublishingHandler = new EventGridPublishingHandler(
                EventGridConfigurationOptionsMonitor,
                EventGridContentClient,
                SyncNameProvider,
                PublishedContentItemVersion,
                PreviewContentItemVersion,
                NeutralEventContentItemVersion,
                Logger);

            OrchestrationContext = A.Fake <IOrchestrationContext>();
            ContentItem          = new ContentItem
            {
                ContentType          = "ContentType",
                ContentItemVersionId = "ContentItemVersionId",
                DisplayText          = "DisplayText",
                Author = "Author"
            };
            A.CallTo(() => OrchestrationContext.ContentItem)
            .Returns(ContentItem);
        }
        protected DeleteOrchestratorTestsBase()
        {
            ContentDefinitionManager = A.Fake <IContentDefinitionManager>();
            Notifier = A.Fake <GraphSyncNotifier>();

            PublishedContentItemVersion = A.Fake <IPublishedContentItemVersion>();
            A.CallTo(() => PublishedContentItemVersion.GraphReplicaSetName)
            .Returns(GraphReplicaSetNames.Published);

            PreviewContentItemVersion = A.Fake <IPreviewContentItemVersion>();
            A.CallTo(() => PreviewContentItemVersion.GraphReplicaSetName)
            .Returns(GraphReplicaSetNames.Preview);

            ServiceProvider = A.Fake <IServiceProvider>();
            Logger          = A.Fake <ILogger <DeleteOrchestrator> >();

            ContentItem = new ContentItem();

            ContentManager = A.Fake <IContentManager>();
            A.CallTo(() => ServiceProvider.GetService(A <Type> .That.Matches(
                                                          t => t.Name == nameof(IContentManager))))
            .Returns(ContentManager);

            PreviewDeleteGraphSyncer   = A.Fake <IDeleteGraphSyncer>();
            PublishedDeleteGraphSyncer = A.Fake <IDeleteGraphSyncer>();

            PreviewAllowSync = A.Fake <IAllowSync>();
            A.CallTo(() => PreviewDeleteGraphSyncer.DeleteAllowed(
                         A <ContentItem> ._,
                         A <IContentItemVersion> .That.Matches(v => v.GraphReplicaSetName == GraphReplicaSetNames.Preview),
                         SyncOperation,
                         null,
                         null))
            .Returns(PreviewAllowSync);

            PublishedAllowSync = A.Fake <IAllowSync>();
            A.CallTo(() => PublishedDeleteGraphSyncer.DeleteAllowed(
                         A <ContentItem> ._,
                         A <IContentItemVersion> .That.Matches(v => v.GraphReplicaSetName == GraphReplicaSetNames.Published),
                         SyncOperation,
                         null,
                         null))
            .Returns(PublishedAllowSync);

            EventGridPublishingHandler = A.Fake <IContentOrchestrationHandler>();
            A.CallTo(() => EventGridPublishingHandler.Published(A <IOrchestrationContext> .Ignored)).Returns(Task.CompletedTask);
            A.CallTo(() => EventGridPublishingHandler.DraftSaved(A <IOrchestrationContext> .Ignored)).Returns(Task.CompletedTask);
            A.CallTo(() => EventGridPublishingHandler.Cloned(A <IOrchestrationContext> .Ignored)).Returns(Task.CompletedTask);
            A.CallTo(() => EventGridPublishingHandler.Unpublished(A <IOrchestrationContext> .Ignored)).Returns(Task.CompletedTask);
            A.CallTo(() => EventGridPublishingHandler.DraftDiscarded(A <IOrchestrationContext> .Ignored)).Returns(Task.CompletedTask);
            A.CallTo(() => EventGridPublishingHandler.Deleted(A <IOrchestrationContext> .Ignored)).Returns(Task.CompletedTask);

            DeleteOrchestrator = new DeleteOrchestrator(
                ContentDefinitionManager,
                Notifier,
                ServiceProvider,
                Logger,
                PublishedContentItemVersion,
                PreviewContentItemVersion,
                new List <IContentOrchestrationHandler> {
                EventGridPublishingHandler
            });

            TestActivity = new Activity("UnitTest").Start();
        }
        public SyncOrchestratorTestsBase()
        {
            ContentDefinitionManager = A.Fake <IContentDefinitionManager>();
            Notifier = A.Fake <GraphSyncNotifier>();

            PreviewGraphReplicaSet = A.Fake <IGraphReplicaSet>();
            A.CallTo(() => PreviewGraphReplicaSet.Name)
            .Returns(GraphReplicaSetNames.Preview);

            PublishedGraphReplicaSet = A.Fake <IGraphReplicaSet>();
            A.CallTo(() => PublishedGraphReplicaSet.Name)
            .Returns(GraphReplicaSetNames.Published);

            var graphReplicaSets = new Dictionary <string, IGraphReplicaSet>
            {
                { GraphReplicaSetNames.Preview, PreviewGraphReplicaSet },
                { GraphReplicaSetNames.Published, PublishedGraphReplicaSet },
            };

            GraphCluster = A.Fake <IGraphCluster>();
            A.CallTo(() => GraphCluster.GetGraphReplicaSet(A <string> ._))
            .ReturnsLazily <IGraphReplicaSet, string>(graphReplicaSetName => graphReplicaSets[graphReplicaSetName]);

            PublishedContentItemVersion = A.Fake <IPublishedContentItemVersion>();
            A.CallTo(() => PublishedContentItemVersion.GraphReplicaSetName)
            .Returns(GraphReplicaSetNames.Published);

            ServiceProvider = A.Fake <IServiceProvider>();
            Logger          = A.Fake <ILogger <SyncOrchestrator> >();

            ContentItem = new ContentItem();

            ContentManager = A.Fake <IContentManager>();
            A.CallTo(() => ServiceProvider.GetService(A <Type> .That.Matches(
                                                          t => t.Name == nameof(IContentManager))))
            .Returns(ContentManager);

            PreviewMergeGraphSyncer   = A.Fake <IMergeGraphSyncer>();
            PublishedMergeGraphSyncer = A.Fake <IMergeGraphSyncer>();

            PreviewAllowSync = A.Fake <IAllowSync>();
            A.CallTo(() => PreviewMergeGraphSyncer.SyncAllowed(
                         A <IGraphReplicaSet> .That.Matches(s => s.Name == GraphReplicaSetNames.Preview),
                         A <ContentItem> ._, A <IContentManager> ._, A <IGraphMergeContext?> ._))
            .Returns(PreviewAllowSync);

            PublishedAllowSync = A.Fake <IAllowSync>();
            A.CallTo(() => PublishedMergeGraphSyncer.SyncAllowed(
                         A <IGraphReplicaSet> .That.Matches(s => s.Name == GraphReplicaSetNames.Published),
                         A <ContentItem> ._, A <IContentManager> ._, A <IGraphMergeContext?> ._))
            .Returns(PublishedAllowSync);

            EventGridPublishingHandler = A.Fake <IContentOrchestrationHandler>();
            A.CallTo(() => EventGridPublishingHandler.Published(A <IOrchestrationContext> .Ignored)).Returns(Task.CompletedTask);
            A.CallTo(() => EventGridPublishingHandler.DraftSaved(A <IOrchestrationContext> .Ignored)).Returns(Task.CompletedTask);
            A.CallTo(() => EventGridPublishingHandler.Cloned(A <IOrchestrationContext> .Ignored)).Returns(Task.CompletedTask);
            A.CallTo(() => EventGridPublishingHandler.Unpublished(A <IOrchestrationContext> .Ignored)).Returns(Task.CompletedTask);
            A.CallTo(() => EventGridPublishingHandler.DraftDiscarded(A <IOrchestrationContext> .Ignored)).Returns(Task.CompletedTask);
            A.CallTo(() => EventGridPublishingHandler.Deleted(A <IOrchestrationContext> .Ignored)).Returns(Task.CompletedTask);

            SyncOrchestrator = new SyncOrchestrator(
                ContentDefinitionManager,
                Notifier,
                GraphCluster,
                ServiceProvider,
                Logger,
                PublishedContentItemVersion,
                new List <IContentOrchestrationHandler> {
                EventGridPublishingHandler
            });

            TestActivity = new Activity("UnitTest").Start();
        }