public static void MapDomResourceToClrAttributes(this IResourceType resourceType, object clrResource, DomReadWriteResource domResource)
        {
            Contract.Requires(resourceType != null);
            Contract.Requires(clrResource != null);
            Contract.Requires(domResource != null);

            var domAttributesNode = domResource.GetNode <DomNodeType, DomAttributes>(DomNodeType.Attributes);

            if (domAttributesNode == null)
            {
                return;
            }

            var domAttributeNodes = domAttributesNode.Nodes()
                                    .Cast <DomAttribute>()
                                    .ToList();

            foreach (var domAttributeNode in domAttributeNodes)
            {
                var clrPropertyName  = domAttributeNode.ClrPropertyName;
                var clrPropertyValue = domAttributeNode.ClrAttribute;

                var clrAttribute = resourceType.GetClrAttributeInfo(clrPropertyName);
                clrAttribute.SetClrProperty(clrResource, clrPropertyValue);
            }
        }
Beispiel #2
0
        public void TestResourceTypeGetAttributeInfo(string name, bool attributeExists, IResourceType resourceType, string apiPropertyName, string clrPropertyName, JsonApiFramework.ServiceModel.IAttributeInfo expected)
        {
            this.Output.WriteLine("Test Name: {0}", name);
            this.Output.WriteLine(String.Empty);

            // Arrange

            // Act
            if (!attributeExists)
            {
                Assert.Throws <ServiceModelException>(() => resourceType.GetApiAttributeInfo(apiPropertyName));
                Assert.Throws <ServiceModelException>(() => resourceType.GetClrAttributeInfo(clrPropertyName));
                return;
            }

            var actualApiAttributeInfo = resourceType.GetApiAttributeInfo(apiPropertyName);
            var actualClrAttributeInfo = resourceType.GetClrAttributeInfo(clrPropertyName);

            // Assert
            AttributeInfoAssert.Equal(expected, actualApiAttributeInfo);
            AttributeInfoAssert.Equal(expected, actualClrAttributeInfo);
        }
        public static void MapClrAttributeToDomAttributes(this IResourceType resourceType, DomAttributes domAttributes, string clrAttributeName, object clrAttribute)
        {
            Contract.Requires(resourceType != null);
            Contract.Requires(domAttributes != null);
            Contract.Requires(String.IsNullOrWhiteSpace(clrAttributeName) == false);

            if (clrAttribute == null)
            {
                return;
            }

            var serviceModel = domAttributes.GetServiceModel();
            var attribute    = resourceType.GetClrAttributeInfo(clrAttributeName);
            var domAttribute = DomAttribute.CreateFromClrAttribute(serviceModel, attribute, clrAttribute);

            if (domAttribute == null)
            {
                return;
            }

            domAttributes.Add(domAttribute);
        }