예제 #1
0
        public void WHEN_param_is_null_SHOULD_throw_ArgumentNullException()
        {
            //Arrange
            GetBreadcrumbParam param = null;

            //Act & Assert
            var ex = Assert.Throws <ArgumentNullException>(() => _sut.CreateBreadcrumbViewModel(param));
        }
예제 #2
0
        public void WHEN_PageId_does_not_match_any_SHOULD_throw_ArgumentException()
        {
            //Arrange
            var param = new GetBreadcrumbParam
            {
                CultureInfo   = CultureInfo.InvariantCulture,
                CurrentPageId = Guid.NewGuid().ToString()
            };

            //Act & Assert
            Expression <Func <BreadcrumbViewModel> > expression = () => _sut.CreateBreadcrumbViewModel(param);
            var exception = Assert.Throws <InvalidOperationException>(() => expression.Compile().Invoke());

            exception.Message.Should().StartWith("Could not find any page matching this ID.");
        }
예제 #3
0
        public void WHEN_PageId_does_not_match_any_SHOULD_throw_ArgumentException()
        {
            //Arrange
            var pageId = Guid.NewGuid();
            var param  = new GetBreadcrumbParam
            {
                CultureInfo   = CultureInfo.InvariantCulture,
                CurrentPageId = pageId.ToString()
            };

            //Act & Assert
            var ex = Assert.Throws <ArgumentException>(() => _sut.CreateBreadcrumbViewModel(param));

            ex.ParamName.Should().Be(nameof(param.CurrentPageId));
        }
예제 #4
0
        public void WHEN_not_generating_folder_SHOULD_all_have_url()
        {
            //Arrange
            var pageId = PageLevel2Id;
            var param  = new GetBreadcrumbParam
            {
                CurrentPageId = pageId.ToString(),
                CultureInfo   = CultureInfo.InvariantCulture
            };

            //Act
            var vm = _sut.CreateBreadcrumbViewModel(param);

            //Assert
            vm.ActivePageName.Should().Be(PageLevel2Name);
            vm.Items.All(i => i.Url != null).Should().BeTrue();
        }
예제 #5
0
        public void WHEN_creating_breadcrumb_SHOULD_have_pages_in_order()
        {
            //Arrange
            var pageId = PageLevel2Id;
            var param  = new GetBreadcrumbParam
            {
                CultureInfo   = CultureInfo.InvariantCulture,
                CurrentPageId = pageId.ToString()
            };

            //Act
            var vm = _sut.CreateBreadcrumbViewModel(param);

            //Assert
            vm.Items[0].DisplayName.Should().Be(HomePageName);
            vm.Items[1].DisplayName.Should().Be(PageLevel1Name);
            vm.ActivePageName.Should().Be(PageLevel2Name);
        }
예제 #6
0
        public void WHEN_generating_folder_SHOULD_not_generate_url_for_folder()
        {
            //Arrange
            var pageId = PageLevel2UnderFolderId;
            var param  = new GetBreadcrumbParam
            {
                CurrentPageId = pageId.ToString(),
                CultureInfo   = CultureInfo.InvariantCulture
            };

            //Act
            var vm = _sut.CreateBreadcrumbViewModel(param);

            //Assert
            vm.ActivePageName.Should().Be(PageLevel2UnderFolderName);
            var folderItem = vm.Items.First(i => i.DisplayName == FolderPageLevel1Name);

            folderItem.Url.Should().BeNull();
        }
예제 #7
0
        protected virtual List <BreadcrumbItemViewModel> CreateBreadcrumbItems(GetBreadcrumbParam param, IPage page)
        {
            var breadcrumbStack = new Stack <BreadcrumbItemViewModel>();
            var parentPageId    = _pageService.GetParentPageId(page);

            while (parentPageId != Guid.Empty)
            {
                var parentPage = _pageService.GetPage(parentPageId, param.CultureInfo);

                var itemVM = CreateParentPageItem(parentPage);
                breadcrumbStack.Push(itemVM);

                parentPageId = _pageService.GetParentPageId(parentPage);
            }

            var items = UnrollStack(breadcrumbStack).ToList();

            return(items);
        }
예제 #8
0
        public virtual BreadcrumbViewModel CreateBreadcrumbViewModel(GetBreadcrumbParam param)
        {
            if (param == null)
            {
                throw new ArgumentNullException(nameof(param));
            }

            var pageId = new Guid(param.CurrentPageId);
            var page   = _pageService.GetPage(pageId, param.CultureInfo) ??
                         throw new InvalidOperationException("Could not find any page matching this ID.");

            var breadcrumbViewModel = new BreadcrumbViewModel
            {
                ActivePageName = page.MenuTitle,
                Items          = CreateBreadcrumbItems(param, page)
            };

            return(breadcrumbViewModel);
        }