/// <summary>
        /// Gets for native node and property alias.
        /// </summary>
        /// <param name="id">The node id.</param>
        /// <param name="propertyTypeAlias">The property alias.</param>
        /// <returns></returns>
        public virtual UmbracoPropertyType GetForNativeDocumentTypePropertyAlias(int id, string propertyTypeAlias)
        {
            var documentType = new DocumentType(id);
            var nativePropertyType = documentType.getPropertyType(propertyTypeAlias);

            var umbracoPropertyType = new UmbracoPropertyType
                                          {
                                              Name = propertyTypeAlias,
                                              DataTypeName = nativePropertyType.DataTypeDefinition.DataType.DataTypeName,
                                              DatabaseType =
                                                  GetDatabaseType(
                                                      nativePropertyType.DataTypeDefinition.DataType.
                                                          DataTypeDefinitionId)
                                          };

            return umbracoPropertyType;
        }
        public void GenerateForDocumentTypeIdAlias()
        {
            var titleDt = new UmbracoPropertyType { DatabaseType = "nvarchar", Name = "title" };
            var contentDt = new UmbracoPropertyType { DatabaseType = "nvarchar", Name = "content" };

            var mockPropTypeRepo = new Mock<IUmbracoPropertyTypeRepository>();
            mockPropTypeRepo.Setup(x => x.GetForNativeDocumentTypePropertyAlias(9, "title"))
                .Returns(titleDt);
            mockPropTypeRepo.Setup(x => x.GetForNativeDocumentTypePropertyAlias(9, "content"))
                .Returns(contentDt);

            var factory = new PropertyTypeFactory(mockPropTypeRepo.Object);

            var prop1 = factory.GenerateForDocumentTypeIdAlias(9, "title");
            Assert.AreEqual("http://localhost/rdf/ontology#hasTitle", prop1.Iri);
            Assert.AreEqual("nvarchar", prop1.DatabaseType);

            var prop2 = factory.GenerateForDocumentTypeIdAlias(9, "content");
            Assert.AreEqual("http://localhost/rdf/ontology#hasContent", prop2.Iri);
            Assert.AreEqual("nvarchar", prop2.DatabaseType);
        }
Пример #3
0
        public void GenerateNode()
        {
            var focusedNode = new UmbracoNode
                                  {
                                      Name = "FocusedNode",
                                      ChildrenIds = new int[] { 2 },
                                      DocumentTypeId = 15,
                                      ParentId = 3
                                  };
            focusedNode.Properties.Add(new UmbracoProperty() { Name = "title", Value = "Focused node" });
            focusedNode.Properties.Add(new UmbracoProperty() { Name = "content4testing", Value = "Test content" });

            var childNode = new UmbracoNode
            {
                Name = "ChildNode"
            };

            var parentNode = new UmbracoNode
                                 {
                                     Name = "ParentNode"
                                 };

            var mockNodeRepo = new Mock<IUmbracoNodeRepository>();
            mockNodeRepo.Setup(x => x.GetByNodeId(1)).Returns(focusedNode);
            mockNodeRepo.Setup(x => x.GetByNodeId(2)).Returns(childNode);
            mockNodeRepo.Setup(x => x.GetByNodeId(3)).Returns(parentNode);

            var titleDt = new UmbracoPropertyType { DatabaseType = "nvarchar", Name = "title" };
            var contentDt = new UmbracoPropertyType { DatabaseType = "nvarchar", Name = "content" };
            var contentTestNameDt = new UmbracoPropertyType { DatabaseType = "nvarchar", Name = "content4testing" };

            var mockPropTypeRepo = new Mock<IUmbracoPropertyTypeRepository>();
            mockPropTypeRepo.Setup(x => x.GetForNativeDocumentTypePropertyAlias(15, "title"))
                .Returns(titleDt);
            mockPropTypeRepo.Setup(x => x.GetForNativeDocumentTypePropertyAlias(15, "content"))
                .Returns(contentDt);
            mockPropTypeRepo.Setup(x => x.GetForNativeDocumentTypePropertyAlias(15, "content4testing"))
               .Returns(contentTestNameDt);

            var dt15 = new UmbracoDocumentType()
            {
                AllowedContentTypeChildrenIds = new int[] { },
                InherritanceParentId = -1,
                Name = "TestDocumentType",
                PropertyTypes = new List<UmbracoPropertyType>()
                                                {
                                                    new UmbracoPropertyType()
                                                        {DatabaseType = "nvarchar", Name = "title"},
                                                    new UmbracoPropertyType()
                                                        {DatabaseType = "nvarchar", Name = "content"}
                                                }

            };

            var mockDocTypeRepo = new Mock<IUmbracoDocumentTypeRepository>();
            mockDocTypeRepo.Setup(x => x.GetById(15))
                .Returns(dt15);

            var resourceFactory = new ResourceFactory(mockNodeRepo.Object, mockPropTypeRepo.Object, mockDocTypeRepo.Object);

            var node = resourceFactory.GenerateNode(1);

            Assert.AreEqual("http://localhost/rdf/resource/FocusedNode", node.Iri);
            Assert.AreEqual("http://localhost/rdf/resource/ParentNode", node.ParentIri);
            Assert.AreEqual("http://localhost/rdf/resource/ChildNode", node.ChildrenIris.First());

            Assert.IsTrue(node.Properties.Any(x => x.PropertyType.Iri == "http://localhost/rdf/ontology#hasTitle" &&
                x.PropertyType.DatabaseType == "nvarchar" && x.Value == "Focused node"));

            Assert.IsTrue(node.Properties.Any(x => x.PropertyType.Iri == "http://localhost/rdf/ontology#hasTestedContent" &&
                x.PropertyType.DatabaseType == "nvarchar" && x.Value == "Test content"));
        }
Пример #4
0
        public void GenerateDocumentType()
        {
            var dt9 = new UmbracoDocumentType()
                        {
                            AllowedContentTypeChildrenIds = new int[] {10},

                            InherritanceParentId = 16,
                            InherritanceChildrenIds = new List<int>(){13},
                            Name = "TestDocumentType",
                            PropertyTypes = new List<UmbracoPropertyType>()
                                                {
                                                    new UmbracoPropertyType()
                                                        {DatabaseType = "nvarchar", Name = "title"},
                                                    new UmbracoPropertyType()
                                                        {DatabaseType = "nvarchar", Name = "content"}
                                                }

                        };

            var dt16 = new UmbracoDocumentType()
            {
                AllowedContentTypeChildrenIds = new int[] { 9 },

                Name = "TestParentDocumentType",
                PropertyTypes = new List<UmbracoPropertyType>()
                                                {
                                                    new UmbracoPropertyType()
                                                        {DatabaseType = "nvarchar", Name = "title"},
                                                    new UmbracoPropertyType()
                                                        {DatabaseType = "nvarchar", Name = "content"}
                                                }

            };

            var dt13 = new UmbracoDocumentType()
            {

                Name = "TestInherritanceChildType",
                PropertyTypes = new List<UmbracoPropertyType>()
                                                {
                                                    new UmbracoPropertyType()
                                                        {DatabaseType = "nvarchar", Name = "title"},
                                                    new UmbracoPropertyType()
                                                        {DatabaseType = "nvarchar", Name = "content"}
                                                }

            };

            var dt10 = new UmbracoDocumentType()
            {

                Name = "TestAllowedContentChild",
                PropertyTypes = new List<UmbracoPropertyType>()
                                                {
                                                    new UmbracoPropertyType()
                                                        {DatabaseType = "nvarchar", Name = "title"},
                                                    new UmbracoPropertyType()
                                                        {DatabaseType = "nvarchar", Name = "content"}
                                                }

            };
            var mockDocTypeRepo = new Mock<IUmbracoDocumentTypeRepository>();
            mockDocTypeRepo.Setup(x => x.GetById(9))
                .Returns(dt9);
            mockDocTypeRepo.Setup(x => x.GetById(16))
                .Returns(dt16);
            mockDocTypeRepo.Setup(x => x.GetById(13))
                .Returns(dt13);
            mockDocTypeRepo.Setup(x => x.GetById(10))
                .Returns(dt10);

            var titleDt = new UmbracoPropertyType {DatabaseType = "nvarchar", Name = "title"};
            var contentDt = new UmbracoPropertyType { DatabaseType = "nvarchar", Name = "content" };

            var mockPropTypeRepo = new Mock<IUmbracoPropertyTypeRepository>();
            mockPropTypeRepo.Setup(x => x.GetForNativeDocumentTypePropertyAlias(9, "title"))
                .Returns(titleDt);
            mockPropTypeRepo.Setup(x => x.GetForNativeDocumentTypePropertyAlias(9, "content"))
                .Returns(contentDt);

            var factory = new OntologyFactory(mockDocTypeRepo.Object, mockPropTypeRepo.Object);

            var docType = factory.GenerateDocumentType(9);

            Debug.WriteLine("Created document type with IRI: " + docType.Iri);

            Assert.AreEqual("http://localhost/rdf/ontology#TestDocumentType", docType.Iri);
            Assert.AreEqual("http://localhost/rdf/ontology#TestParentDocumentType", docType.ParentIri);
            Assert.AreEqual(2, docType.PropertyTypes.Count);
            Assert.IsTrue(docType.PropertyTypes.Any(x => x.Iri == "http://localhost/rdf/ontology#hasTitle" &&
                x.DatabaseType == "nvarchar"));
            Assert.IsTrue(docType.PropertyTypes.Single(x => x.Iri == "http://localhost/rdf/ontology#hasTitle").EquivalentIris.Count == 3);
            Assert.IsTrue(docType.PropertyTypes.Any(x => x.Iri == "http://localhost/rdf/ontology#hasContent" &&
                x.DatabaseType == "nvarchar"));
            Assert.AreEqual(1, docType.AllowedContentTypeChildrenIris.Count);
            Assert.AreEqual("http://localhost/rdf/ontology#TestAllowedContentChild", docType.AllowedContentTypeChildrenIris[0]);
            Assert.AreEqual(1, docType.ChildrenIris.Count);
            Assert.IsTrue(docType.ChildrenIris.Any(x => x == "http://localhost/rdf/ontology#TestInherritanceChildType"));
        }