A hostname entity
Inheritance: TypedEntity
Example #1
0
        private Revision<TypedEntity> SetupTestStructure(
            out Revision<TypedEntity> multiGrandChild,
            out Revision<TypedEntity> firstChild,
            out Revision<TypedEntity> firstGrandChild,
            out Revision<TypedEntity> secondChild)
        {
            var domainRoot = CreateNewPublishedEntity();
            firstChild = CreateNewPublishedEntity();
            secondChild = CreateNewPublishedEntity();
            firstGrandChild = CreateNewPublishedEntity();
            multiGrandChild = CreateNewPublishedEntity();
            using (var writer = GetHive().Create<IContentStore>())
            {
                domainRoot.Item.Attributes[NodeNameAttributeDefinition.AliasValue].Values["UrlName"] = "homepage";
                firstChild.Item.Attributes[NodeNameAttributeDefinition.AliasValue].Values["UrlName"] = "first-child";
                firstGrandChild.Item.Attributes[NodeNameAttributeDefinition.AliasValue].Values["UrlName"] = "first-grandchild";
                multiGrandChild.Item.Attributes[NodeNameAttributeDefinition.AliasValue].Values["UrlName"] = "multi-grandchild";
                secondChild.Item.Attributes[NodeNameAttributeDefinition.AliasValue].Values["UrlName"] = "second-child";
                writer.Repositories.Revisions.AddOrUpdate(domainRoot);
                writer.Repositories.Revisions.AddOrUpdate(firstChild);
                writer.Repositories.Revisions.AddOrUpdate(firstGrandChild);
                writer.Repositories.Revisions.AddOrUpdate(multiGrandChild);
                writer.Repositories.Revisions.AddOrUpdate(secondChild);
                writer.Repositories.AddRelation(
                    FixedHiveIds.ContentVirtualRoot, domainRoot.Item.Id, FixedRelationTypes.DefaultRelationType, 0);
                writer.Repositories.AddRelation(domainRoot.Item, firstChild.Item, FixedRelationTypes.DefaultRelationType, 0);
                writer.Repositories.AddRelation(firstChild.Item, firstGrandChild.Item, FixedRelationTypes.DefaultRelationType, 0);
                writer.Repositories.AddRelation(firstChild.Item, multiGrandChild.Item, FixedRelationTypes.DefaultRelationType, 0);
                writer.Repositories.AddRelation(secondChild.Item, multiGrandChild.Item, FixedRelationTypes.DefaultRelationType, 0);
                writer.Repositories.AddRelation(domainRoot.Item, secondChild.Item, FixedRelationTypes.DefaultRelationType, 0);

                var hostname = new Hostname { Name = "hello.com" };
                writer.Repositories.AddOrUpdate(hostname);
                writer.Repositories.AddRelation(domainRoot.Item.Id, hostname.Id, FixedRelationTypes.HostnameRelationType, 0);

                writer.Complete();
            }
            return domainRoot;
        }
Example #2
0
        public void RouteEngine_Get_Domain_Url_With_Hostname_On_Other_Authority()
        {
            //NOTE: We know that the mock http context we've setup is using hello.com as it's Url Authority

            //creates an entity without a domain
            var nonDomain = new Revision<TypedEntity>(CreateNewEntity());
            nonDomain.MetaData.StatusType = FixedStatusTypes.Published;

            //these will have a domain attached
            var main = new Revision<TypedEntity>(CreateNewEntity());
            main.MetaData.StatusType = FixedStatusTypes.Published;
            var sub = new Revision<TypedEntity>(CreateNewEntity());
            sub.MetaData.StatusType = FixedStatusTypes.Published;

            using (var writer = GetHive().Create<IContentStore>())
            {
                main.Item.Attributes[NodeNameAttributeDefinition.AliasValue].Values["UrlName"] = "hello";
                sub.Item.Attributes[NodeNameAttributeDefinition.AliasValue].Values["UrlName"] = "world";

                //2 root nodes, one with and one without a domain
                writer.Repositories.Revisions.AddOrUpdate(nonDomain);
                writer.Repositories.AddRelation(FixedHiveIds.ContentVirtualRoot, nonDomain.Item.Id, FixedRelationTypes.DefaultRelationType, 0);


                writer.Repositories.Revisions.AddOrUpdate(main);
                writer.Repositories.AddRelation(FixedHiveIds.ContentVirtualRoot, main.Item.Id, FixedRelationTypes.DefaultRelationType, 0);

                writer.Repositories.Revisions.AddOrUpdate(sub);
                writer.Repositories.AddRelation(main.Item.Id, sub.Item.Id, FixedRelationTypes.DefaultRelationType, 0);

                var hostname = new Hostname { Name = "adifferentauthority.com" };
                writer.Repositories.AddOrUpdate(hostname);
                writer.Repositories.AddRelation(main.Item.Id, hostname.Id, FixedRelationTypes.HostnameRelationType, 0);

                writer.Complete();
            }

            //Act

            var url1 = GetEngine(new Uri("http://hello.com/")).GetUrlForEntity(main.Item);
            var url2 = GetEngine(new Uri("http://hello.com/")).GetUrlForEntity(sub.Item);

            //Assert

            Assert.AreEqual(UrlResolutionStatus.SuccessWithHostname, url1.Status);
            Assert.AreEqual("adifferentauthority.com", url1.Url);
            Assert.AreEqual(UrlResolutionStatus.SuccessWithHostname, url2.Status);
            Assert.AreEqual("adifferentauthority.com/world", url2.Url);
        }