Exemplo n.º 1
0
        public async Task <HttpStatusCode> ProcessContentAsync(bool isDraft, Guid eventId, Guid?contentId, string?apiEndpoint, MessageContentType messageContentType)
        {
            if (!Uri.TryCreate(apiEndpoint, UriKind.Absolute, out Uri? url))
            {
                throw new InvalidDataException($"Invalid Api url '{apiEndpoint}' received for Event Id: {eventId}");
            }

            switch (messageContentType)
            {
            case MessageContentType.SharedContentItem:
                logger.LogInformation($"Event Id: {eventId} - processing shared content for: {url}");
                return(await ProcessSharedContentAsync(eventId, url).ConfigureAwait(false));

            case MessageContentType.JobGroup:
                if (isDraft)
                {
                    logger.LogInformation($"Event Id: {eventId} - processing draft LMI SOC refresh for: {url}");
                    var result = await jobGroupCacheRefreshService.ReloadAsync(url).ConfigureAwait(false);

                    if (result == HttpStatusCode.OK || result == HttpStatusCode.Created)
                    {
                        await PostDraftEventAsync($"Draft all SOCs to delta-report API", eventGridClientOptions.ApiEndpoint, Guid.NewGuid()).ConfigureAwait(false);
                    }

                    return(result);
                }
                else
                {
                    logger.LogInformation($"Event Id: {eventId} - processing published LMI SOC refresh from draft for: {url}");
                    return(await jobGroupPublishedRefreshService.ReloadAsync(url).ConfigureAwait(false));
                }

            case MessageContentType.JobGroupItem:
                if (isDraft)
                {
                    logger.LogInformation($"Event Id: {eventId} - processing draft LMI SOC item for: {url}");
                    var result = await jobGroupCacheRefreshService.ReloadItemAsync(url).ConfigureAwait(false);

                    if (result == HttpStatusCode.OK || result == HttpStatusCode.Created)
                    {
                        var eventGridEndpoint = new Uri($"{eventGridClientOptions.ApiEndpoint}/{contentId}", UriKind.Absolute);
                        await PostDraftEventAsync($"Draft individual SOC to delta-report API", eventGridEndpoint, contentId).ConfigureAwait(false);
                    }

                    return(result);
                }
                else
                {
                    logger.LogInformation($"Event Id: {eventId} - processing published LMI SOC item from draft for: {url}");
                    return(await jobGroupPublishedRefreshService.ReloadItemAsync(url).ConfigureAwait(false));
                }
            }

            return(HttpStatusCode.BadRequest);
        }
Exemplo n.º 2
0
        public async Task WebhooksContentServiceProcessContentForSharedContentItemReturnsSuccess()
        {
            // Arrange
            const HttpStatusCode expectedResult = HttpStatusCode.OK;

            A.CallTo(() => fakeCmsApiService.GetItemAsync <CmsApiSharedContentModel>(A <Uri> .Ignored)).Returns(A.Dummy <CmsApiSharedContentModel>());
            A.CallTo(() => fakeMapper.Map <ContentItemModel>(A <CmsApiSharedContentModel> .Ignored)).Returns(A.Dummy <ContentItemModel>());
            A.CallTo(() => fakeContentItemDocumentService.UpsertAsync(A <ContentItemModel> .Ignored)).Returns(expectedResult);

            // Act
            var result = await webhooksContentService.ProcessContentAsync(false, Guid.NewGuid(), null, "https://somewhere.com", MessageContentType.SharedContentItem).ConfigureAwait(false);

            // Assert
            A.CallTo(() => fakeJobGroupCacheRefreshService.ReloadAsync(A <Uri> .Ignored)).MustNotHaveHappened();
            A.CallTo(() => fakeJobGroupCacheRefreshService.ReloadItemAsync(A <Uri> .Ignored)).MustNotHaveHappened();
            A.CallTo(() => fakeCmsApiService.GetItemAsync <CmsApiSharedContentModel>(A <Uri> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => fakeMapper.Map <ContentItemModel>(A <CmsApiSharedContentModel> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => fakeContentItemDocumentService.UpsertAsync(A <ContentItemModel> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => fakeJobGroupPublishedRefreshService.ReloadAsync(A <Uri> .Ignored)).MustNotHaveHappened();
            A.CallTo(() => fakeJobGroupPublishedRefreshService.ReloadItemAsync(A <Uri> .Ignored)).MustNotHaveHappened();
            A.CallTo(() => fakeEventGridService.SendEventAsync(A <EventGridEventData> .Ignored, A <string> .Ignored, A <string> .Ignored)).MustNotHaveHappened();

            Assert.Equal(expectedResult, result);
        }