Ejemplo n.º 1
0
        private async Task <ContentPageModel?> GetContentPageWithoutCacheAsync(string?location, string?article)
        {
            Expression <Func <ContentPageModel, bool> > where;

            if (string.IsNullOrWhiteSpace(location) && string.IsNullOrWhiteSpace(article))
            {
                where = p => p.PageLocation == "/" && p.IsDefaultForPageLocation;
            }
            else if (string.IsNullOrWhiteSpace(article))
            {
                where = p => (p.PageLocation == $"/{location}" && p.IsDefaultForPageLocation) || (p.PageLocation == "/" && p.CanonicalName == location);
            }
            else
            {
                where = p => (p.PageLocation == $"/{location}" && p.CanonicalName == article) || (p.PageLocation == $"/{location}/{article}" && p.IsDefaultForPageLocation);
            }

            var contentPageModels = await contentPageService.GetAsync(where);

            if (contentPageModels == null || !contentPageModels.Any())
            {
                var searchLocation = string.IsNullOrWhiteSpace(article) ? $"/{location}" : $"/{location}/{article}";
                where = p => p.PageLocation == searchLocation && !p.IsDefaultForPageLocation;

                contentPageModels = await contentPageService.GetAsync(where);
            }

            if (contentPageModels != null && contentPageModels.Any())
            {
                return(contentPageModels.OrderBy(o => o.CreatedDate).First());
            }

            return(default);
Ejemplo n.º 2
0
        public async Task PagesControlerHelpersTestsGetContentPageAsyncReturnsSuccess()
        {
            // Arrange
            var          expectedResults = A.CollectionOfDummy <ContentPageModel>(1);
            const string location        = "a-location";
            const string article         = "an-article";
            var          helper          = new PagesControlerHelpers(fakeContentPageService);

            A.CallTo(() => fakeContentPageService.GetAsync(A <Expression <Func <ContentPageModel, bool> > > .Ignored)).Returns(expectedResults);

            // Act
            var result = await helper.GetContentPageAsync(location, article).ConfigureAwait(false);

            // Assert
            A.CallTo(() => fakeContentPageService.GetAsync(A <Expression <Func <ContentPageModel, bool> > > .Ignored)).MustHaveHappenedOnceExactly();

            Assert.Equal(expectedResults.First(), result);
        }