public void ShouldReturnATopicFromAContentfulArticleBasedOnTheBreadcrumbs()
        {
            var subItemEntry = new List <ContentfulReference>
            {
                new ContentfulReferenceBuilder().Slug("sub-slug").Build()
            };

            var ContentfulReferences = new ContentfulReferenceBuilder()
                                       .Name("test topic")
                                       .Slug("test-topic")
                                       .SubItems(subItemEntry)
                                       .SystemContentTypeId("topic")
                                       .Build();

            var contentfulArticleEntry = new ContentfulArticleBuilder().Breadcrumbs(new List <ContentfulReference>()
            {
                ContentfulReferences
            }).Build();


            var result = _parentTopicContentfulFactory.ToModel(contentfulArticleEntry);

            result.Name.Should().Be("test topic");
            result.Slug.Should().Be("test-topic");
            result.SubItems.Should().HaveCount(1);
        }
        public void ShouldCreateACrumbWithNameIfSet()
        {
            var ContentfulReference =
                new ContentfulReferenceBuilder().Name("name").Title(string.Empty).Build();

            var crumb = new CrumbContentfulFactory().ToModel(ContentfulReference);

            crumb.Title.Should().Be(ContentfulReference.Name);
        }
        public void ShouldCreateACrumbFromAContentfulReference()
        {
            var ContentfulReference =
                new ContentfulReferenceBuilder().Build();

            var crumb = new CrumbContentfulFactory().ToModel(ContentfulReference);

            crumb.Slug.Should().Be(ContentfulReference.Slug);
            crumb.Title.Should().Be(ContentfulReference.Title);
            crumb.Type.Should().Be(ContentfulReference.Sys.ContentType.SystemProperties.Id);
        }
        public void ShouldReturnTopicWithFirstSubItemOfTheArticle()
        {
            var subItemEntry = new ContentfulReferenceBuilder()
                               .Slug("sub-slug")
                               .SystemId("same-id-as-article")
                               .Build();

            var subItemEntryOther = new ContentfulReferenceBuilder()
                                    .Slug("sub-slug")
                                    .SystemId("not-same-id-as-article")
                                    .Build();

            var subItemEntryList = new List <ContentfulReference>
            {
                subItemEntry,
                subItemEntryOther
            };

            var ContentfulReferences = new ContentfulReferenceBuilder()
                                       .Name("test topic")
                                       .Slug("test-topic")
                                       .SubItems(subItemEntryList)
                                       .SystemContentTypeId("topic")
                                       .Build();

            var contentfulArticle = new ContentfulArticleBuilder()
                                    .Breadcrumbs(new List <ContentfulReference>()
            {
                ContentfulReferences
            })
                                    .Title("title")
                                    .Slug("slug")
                                    .SystemId("same-id-as-article")
                                    .Build();

            _subitemContentfulFactory.Setup(o => o.ToModel(It.Is <ContentfulReference>(x => x.Slug == "article-slug")))
            .Returns(new SubItem("slug", "title", string.Empty, string.Empty, string.Empty, DateTime.MinValue, DateTime.MaxValue, string.Empty, new List <SubItem>()));

            var result = _parentTopicContentfulFactory.ToModel(contentfulArticle);

            result.Should().BeOfType <Topic>();
            result.SubItems.Should().HaveCount(2);
            result.SubItems.First().Title.Should().Be("title");
            result.SubItems.First().Slug.Should().Be("slug");
            result.SubItems.ToList()[1].Title.Should().Be("title");
            result.SubItems.ToList()[1].Slug.Should().Be("slug");
        }
        public void ShouldCreateSubItemWithoutSubItems()
        {
            var ContentfulReference = new ContentfulReferenceBuilder()
                                      .Name("custom name")
                                      .Title(string.Empty)
                                      .SubItems(null)
                                      .TertiaryItems(null)
                                      .SecondaryItems(null)
                                      .SystemContentTypeId("topic")
                                      .Build();

            var subItem = _subItemContentfulFactory.ToModel(ContentfulReference);

            subItem.Should().NotBeNull();
            subItem.Should().BeOfType <SubItem>();
            subItem.Title.Should().Be("custom name");
            subItem.SubItems.Should().BeEmpty();
        }
        public void ToModel_ShouldHandleGroupsHomepageSlugCorrectly()
        {
            // Arrange
            var contentfulReference = new ContentfulReferenceBuilder()
                                      .Slug("test-group-homepage")
                                      .Name("custom name")
                                      .Title(string.Empty)
                                      .SubItems(null)
                                      .TertiaryItems(null)
                                      .SecondaryItems(null)
                                      .SystemContentTypeId("groupHomepage")
                                      .Build();

            // Act
            var subItem = _subItemContentfulFactory.ToModel(contentfulReference);

            // Assert
            subItem.Slug.Should().Be("groups");
        }
        public void ToModel_ShouldSetPaymentsGroupIconCorrectly_WhenNonSet()
        {
            // Arrange
            var contentfulReference = new ContentfulReferenceBuilder()
                                      .Slug("test-payment-group")
                                      .Name("custom name")
                                      .Title("title")
                                      .SubItems(null)
                                      .TertiaryItems(null)
                                      .SecondaryItems(null)
                                      .Icon(null)
                                      .SystemContentTypeId("payment")
                                      .Build();

            // Act
            var subItem = _subItemContentfulFactory.ToModel(contentfulReference);

            // Assert
            subItem.Icon.Should().Be("si-coin");
        }
        public void ShouldReturnNullTopicIfBreadcrumbDoesNotHaveTypeOfTopic()
        {
            var subItemEntry = new List <ContentfulReference>
            {
                new ContentfulReferenceBuilder().Slug("sub-slug").Build()
            };

            var ContentfulReferences = new ContentfulReferenceBuilder()
                                       .Name("test topic")
                                       .Slug("test-topic")
                                       .SubItems(subItemEntry)
                                       .SystemContentTypeId("id")
                                       .Build();

            var contentfulArticleEntry = new ContentfulArticleBuilder().Breadcrumbs(new List <ContentfulReference>()
            {
                ContentfulReferences
            }).Build();

            var result = _parentTopicContentfulFactory.ToModel(contentfulArticleEntry);

            result.Should().BeOfType <NullTopic>();
        }
        public void ShouldCreateSubItemWithSubItems()
        {
            var ContentfulReference = new ContentfulReferenceBuilder()
                                      .SubItems(new List <ContentfulReference>()
            {
                new ContentfulReference()
                {
                    Sys =
                        new SystemProperties()
                    {
                        Type        = "Entry",
                        ContentType = new ContentType {
                            SystemProperties = new SystemProperties {
                                Id = "topic"
                            }
                        }
                    }
                },
                new ContentfulReference()
                {
                    Sys =
                        new SystemProperties()
                    {
                        Type        = "Entry",
                        ContentType = new ContentType {
                            SystemProperties = new SystemProperties {
                                Id = "topic"
                            }
                        }
                    }
                }
            })
                                      .TertiaryItems(new List <ContentfulReference>()
            {
                new ContentfulReference()
                {
                    Sys =
                        new SystemProperties()
                    {
                        Type        = "Entry",
                        ContentType = new ContentType {
                            SystemProperties = new SystemProperties {
                                Id = "topic"
                            }
                        }
                    }
                },
                new ContentfulReference()
                {
                    Sys =
                        new SystemProperties()
                    {
                        Type        = "Entry",
                        ContentType = new ContentType {
                            SystemProperties = new SystemProperties {
                                Id = "topic"
                            }
                        }
                    }
                }
            })
                                      .SecondaryItems(new List <ContentfulReference>()
            {
                new ContentfulReference()
                {
                    Sys =
                        new SystemProperties()
                    {
                        Type        = "Entry",
                        ContentType = new ContentType {
                            SystemProperties = new SystemProperties {
                                Id = "topic"
                            }
                        }
                    }
                },
                new ContentfulReference()
                {
                    Sys =
                        new SystemProperties()
                    {
                        Type        = "Entry",
                        ContentType = new ContentType {
                            SystemProperties = new SystemProperties {
                                Id = "topic"
                            }
                        }
                    }
                }
            })
                                      .Build();

            var subItem = _subItemContentfulFactory.ToModel(ContentfulReference);

            subItem.SubItems.Should().HaveCount(6);
        }