public async Task <bool> FindAndUpdateAsync(ContentItemModel contentItemModel, Uri url)
        {
            _ = contentItemModel ?? throw new ArgumentNullException(nameof(contentItemModel));

            var cmsApiModel = await cmsApiService.GetContentItemAsync <T>(url).ConfigureAwait(false);

            if (cmsApiModel != null)
            {
                switch (contentItemModel.ContentType.ToLower())
                {
                case Constants.ContentTypeHtml:
                    if (cmsApiModel is CmsApiHtmlModel cmsApiHtmlModel)
                    {
                        contentItemModel.Title    = cmsApiHtmlModel.Title;
                        contentItemModel.Content  = cmsApiHtmlModel.Content;
                        contentItemModel.HtmlBody = cmsApiHtmlModel.HtmlBody;
                    }

                    break;

                case Constants.ContentTypeHtmlShared:
                    if (cmsApiModel is CmsApiHtmlSharedModel cmsApiHtmlSharedModel)
                    {
                        contentItemModel.Title    = cmsApiHtmlSharedModel.Title;
                        contentItemModel.Content  = cmsApiHtmlSharedModel.Content;
                        contentItemModel.HtmlBody = cmsApiHtmlSharedModel.HtmlBody;
                    }

                    break;

                case Constants.ContentTypeSharedContent:
                    if (cmsApiModel is CmsApiSharedContentModel cmsApiSharedContentModel)
                    {
                        contentItemModel.Title    = cmsApiSharedContentModel.Title;
                        contentItemModel.Content  = cmsApiSharedContentModel.Content;
                        contentItemModel.HtmlBody = cmsApiSharedContentModel.HtmlBody;
                    }

                    break;

                case Constants.ContentTypeForm:
                    if (cmsApiModel is CmsApiFormModel cmsApiFormModel)
                    {
                        contentItemModel.Action = cmsApiFormModel.Action;
                        contentItemModel.EnableAntiForgeryToken = cmsApiFormModel.EnableAntiForgeryToken;
                        contentItemModel.Method  = cmsApiFormModel.Method;
                        contentItemModel.EncType = cmsApiFormModel.EncType;
                    }

                    break;
                }

                contentItemModel.LastCached = DateTime.UtcNow;

                return(true);
            }

            return(false);
        }
        public async Task ContentItemUpdaterFindAndUpdateAsyncReturnsSuccess()
        {
            // Arrange
            const bool expectedResult        = true;
            var        dummyCmsApiHtmlModel  = A.Dummy <CmsApiHtmlModel>();
            var        dummyContentItemModel = A.Dummy <ContentItemModel>();
            var        url     = new Uri("https://www.somewhere.com", UriKind.Absolute);
            var        service = new MarkupContentItemUpdater <CmsApiHtmlModel>(fakeCmsApiService);

            A.CallTo(() => fakeCmsApiService.GetContentItemAsync <CmsApiHtmlModel>(A <Uri> .Ignored)).Returns(dummyCmsApiHtmlModel);

            // Act
            var result = await service.FindAndUpdateAsync(dummyContentItemModel, url).ConfigureAwait(false);

            // Assert
            A.CallTo(() => fakeCmsApiService.GetContentItemAsync <CmsApiHtmlModel>(A <Uri> .Ignored)).MustHaveHappenedOnceExactly();

            Assert.Equal(expectedResult, result !);
        }
        public async Task PageLocatonUpdaterFindAndUpdateAsyncReturnsSuccess()
        {
            // Arrange
            const bool expectedResult               = true;
            var        url                          = new Uri("https://www.somewhere.com", UriKind.Absolute);
            var        contentItemId                = Guid.NewGuid();
            var        validPageLocatons            = BuildValidPageLocations(contentItemId);
            var        dummyCmsApiPageLocationModel = A.Dummy <CmsApiPageLocationModel>();
            var        service                      = new PageLocatonUpdater(fakeCmsApiService);

            A.CallTo(() => fakeCmsApiService.GetContentItemAsync <CmsApiPageLocationModel>(A <Uri> .Ignored)).Returns(dummyCmsApiPageLocationModel);

            // Act
            var result = await service.FindAndUpdateAsync(url, contentItemId, validPageLocatons).ConfigureAwait(false);

            // Assert
            A.CallTo(() => fakeCmsApiService.GetContentItemAsync <CmsApiPageLocationModel>(A <Uri> .Ignored)).MustHaveHappenedOnceExactly();

            Assert.Equal(expectedResult, result);
        }
Example #4
0
        public async Task <bool> FindAndUpdateAsync(ContentItemModel contentItemModel, Uri url)
        {
            _ = contentItemModel ?? throw new ArgumentNullException(nameof(contentItemModel));

            var cmsApiHtmlModel = await cmsApiService.GetContentItemAsync <T>(url).ConfigureAwait(false);

            if (cmsApiHtmlModel != null)
            {
                contentItemModel.Title      = cmsApiHtmlModel.Title;
                contentItemModel.Content    = cmsApiHtmlModel.Content;
                contentItemModel.HtmlBody   = cmsApiHtmlModel.HtmlBody;
                contentItemModel.LastCached = DateTime.UtcNow;

                return(true);
            }

            return(false);
        }
Example #5
0
        public async Task <bool> FindAndUpdateAsync(Uri url, Guid contentItemId, List <PageLocationModel>?pageLocations)
        {
            var pageLocationModel = FindItem(contentItemId, pageLocations);

            if (pageLocationModel != null)
            {
                var cmsApiPageLocationModel = await cmsApiService.GetContentItemAsync <CmsApiPageLocationModel>(url).ConfigureAwait(false);

                if (cmsApiPageLocationModel != null)
                {
                    pageLocationModel.BreadcrumbLinkSegment = cmsApiPageLocationModel.Title;
                    pageLocationModel.BreadcrumbText        = cmsApiPageLocationModel.BreadcrumbText;
                    pageLocationModel.LastCached            = DateTime.UtcNow;

                    return(true);
                }
            }

            return(false);
        }