public void DefaultValuesTest()
 {
     AtomCategoriesMetadata categories = new AtomCategoriesMetadata();
     this.Assert.IsNull(categories.Fixed, "Expected null default value for property 'Fixed'.");
     this.Assert.IsNull(categories.Scheme, "Expected null default value for property 'Scheme'.");
     this.Assert.IsNull(categories.Href, "Expected null default value for property 'HRef'.");
     this.Assert.IsNull(categories.Categories, "Expected null default value for property 'Categories'.");
 }
        public void PropertySettersNullTest()
        {
            AtomCategoriesMetadata categories = new AtomCategoriesMetadata()
            {
                Fixed = null,
                Scheme = null,
                Href = null,
                Categories = null,
            };

            this.Assert.IsNull(categories.Fixed, "Expected null value for property 'Fixed'.");
            this.Assert.IsNull(categories.Scheme, "Expected null value for property 'Scheme'.");
            this.Assert.IsNull(categories.Href, "Expected null value for property 'Href'.");
            this.Assert.IsNull(categories.Categories, "Expected null value for property 'Categories'.");
        }
        public void PropertyGettersAndSettersTest()
        {
            AtomTextConstruct title = new AtomTextConstruct();
            string accept = "mime/type";
            AtomCategoriesMetadata categories = new AtomCategoriesMetadata();

            AtomResourceCollectionMetadata resourceCollection = new AtomResourceCollectionMetadata()
            {
                Title = title,
                Accept = accept,
                Categories = categories
            };

            this.Assert.AreSame(title, resourceCollection.Title, "Expected reference equal values for property 'Title'.");
            this.Assert.AreSame(accept, resourceCollection.Accept, "Expected reference equal values for property 'Accept'.");
            this.Assert.AreSame(categories, resourceCollection.Categories, "Expected reference equal values for property 'Categories'.");
        }
        public void PropertyGettersAndSettersTest()
        {
            bool fixedValue = true;
            string scheme = "http://odatalib.org/scheme";
            Uri href = new Uri("http://odatalib.org/href");
            List<AtomCategoryMetadata> categoriesList = new List<AtomCategoryMetadata> { new AtomCategoryMetadata() };

            AtomCategoriesMetadata categories = new AtomCategoriesMetadata()
            {
                Fixed = fixedValue,
                Scheme = scheme,
                Href = href,
                Categories = categoriesList
            };

            this.Assert.AreEqual(fixedValue, categories.Fixed, "Expected equal values for property 'Fixed'.");
            this.Assert.AreSame(scheme, categories.Scheme, "Expected reference equal values for property 'Scheme'.");
            this.Assert.AreSame(href, categories.Href, "Expected reference equal values for property 'HRef'.");
            this.Assert.AreSame(categoriesList, categories.Categories, "Expected reference equal values for property 'Categories'.");
        }
 /// <summary>
 /// Visits an ATOM categories metadata.
 /// </summary>
 /// <param name="atomCategoriesMetadata">The categories metadata to visit.</param>
 protected override void VisitAtomCategoriesMetadata(AtomCategoriesMetadata atomCategoriesMetadata)
 {
     this.ValidateUri(atomCategoriesMetadata.Href);
     base.VisitAtomCategoriesMetadata(atomCategoriesMetadata);
 }
        /// <summary>
        /// Writes the ATOM metadata for a single entity set element.
        /// </summary>
        /// <param name="entitySetInfo">The entity set element to get the metadata for and write it.</param>
        internal void WriteEntitySetInfoMetadata(ODataEntitySetInfo entitySetInfo)
        {
            Debug.Assert(entitySetInfo != null, "collection != null");
            Debug.Assert(entitySetInfo.Url != null, "collection.Url should have been validated at this point");

            AtomResourceCollectionMetadata metadata = entitySetInfo.GetAnnotation <AtomResourceCollectionMetadata>();

            AtomTextConstruct title = null;

            if (metadata != null)
            {
                title = metadata.Title;
            }

            if (entitySetInfo.Name != null)
            {
                if (title == null)
                {
                    title = new AtomTextConstruct {
                        Text = entitySetInfo.Name
                    };
                }
                else if (string.CompareOrdinal(title.Text, entitySetInfo.Name) != 0)
                {
                    throw new ODataException(ODataErrorStrings.ODataAtomServiceDocumentMetadataSerializer_ResourceCollectionNameAndTitleMismatch(entitySetInfo.Name, title.Text));
                }
            }

            // The ATOMPUB specification requires a title.
            // <atom:title>title</atom:title>
            // Note that this will write an empty atom:title element even if the title is null.
            if (this.UseServerFormatBehavior && title.Kind == AtomTextConstructKind.Text)
            {
                // For WCF DS server we must not write the type attribute, just a simple <atom:title>title<atom:title>
                this.WriteElementWithTextContent(
                    AtomConstants.NonEmptyAtomNamespacePrefix,
                    AtomConstants.AtomTitleElementName,
                    AtomConstants.AtomNamespace,
                    title.Text);
            }
            else
            {
                this.WriteTextConstruct(AtomConstants.NonEmptyAtomNamespacePrefix, AtomConstants.AtomTitleElementName, AtomConstants.AtomNamespace, title);
            }

            if (metadata != null)
            {
                string accept = metadata.Accept;
                if (accept != null)
                {
                    // <app:accept>accept</app:accept>
                    this.WriteElementWithTextContent(
                        string.Empty,
                        AtomConstants.AtomPublishingAcceptElementName,
                        AtomConstants.AtomPublishingNamespace,
                        accept);
                }

                AtomCategoriesMetadata categories = metadata.Categories;
                if (categories != null)
                {
                    // <app:categories>
                    this.XmlWriter.WriteStartElement(string.Empty, AtomConstants.AtomPublishingCategoriesElementName, AtomConstants.AtomPublishingNamespace);

                    Uri    href       = categories.Href;
                    bool?  fixedValue = categories.Fixed;
                    string scheme     = categories.Scheme;
                    IEnumerable <AtomCategoryMetadata> categoriesCollection = categories.Categories;
                    if (href != null)
                    {
                        // Out of line categories document
                        if (fixedValue.HasValue || scheme != null ||
                            (categoriesCollection != null && categoriesCollection.Any()))
                        {
                            throw new ODataException(ODataErrorStrings.ODataAtomWriterMetadataUtils_CategoriesHrefWithOtherValues);
                        }

                        this.XmlWriter.WriteAttributeString(AtomConstants.AtomHRefAttributeName, this.UriToUrlAttributeValue(href));
                    }
                    else
                    {
                        // Inline categories document

                        // fixed='yes|no'
                        if (fixedValue.HasValue)
                        {
                            this.XmlWriter.WriteAttributeString(
                                AtomConstants.AtomPublishingFixedAttributeName,
                                fixedValue.Value ? AtomConstants.AtomPublishingFixedYesValue : AtomConstants.AtomPublishingFixedNoValue);
                        }

                        // scheme='scheme'
                        if (scheme != null)
                        {
                            this.XmlWriter.WriteAttributeString(AtomConstants.AtomCategorySchemeAttributeName, scheme);
                        }

                        if (categoriesCollection != null)
                        {
                            foreach (AtomCategoryMetadata category in categoriesCollection)
                            {
                                // <atom:category/>
                                this.WriteCategory(AtomConstants.NonEmptyAtomNamespacePrefix, category.Term, category.Scheme, category.Label);
                            }
                        }
                    }

                    // </app:categories>
                    this.XmlWriter.WriteEndElement();
                }
            }
        }
        /// <summary>
        /// Reads an app:categories element as well as each atom:category element contained within it, and adds the new information to <paramref name="collectionMetadata"/>.
        /// </summary>
        /// <param name="collectionMetadata">The non-null collection metadata object to augment.</param>
        /// <remarks>
        /// Pre-Condition:  XmlNodeType.Element - The start of the app:categories element.
        /// Post-Condition: Any                 - The next node after the app:categories element.
        /// </remarks>
        internal void ReadCategoriesElementInCollection(AtomResourceCollectionMetadata collectionMetadata)
        {
            Debug.Assert(collectionMetadata != null, "collectionMetadata != null");
            this.AssertXmlCondition(XmlNodeType.Element);
            Debug.Assert(this.XmlReader.LocalName == AtomConstants.AtomPublishingCategoriesElementName, "Expected element named 'categories'.");
            Debug.Assert(this.XmlReader.NamespaceURI == AtomConstants.AtomPublishingNamespace, "Element 'categories' should be in the atom publishing namespace.");

            AtomCategoriesMetadata      categoriesMetadata = new AtomCategoriesMetadata();
            List <AtomCategoryMetadata> categoryList       = new List <AtomCategoryMetadata>();

            while (this.XmlReader.MoveToNextAttribute())
            {
                string attributeValue = this.XmlReader.Value;

                if (this.XmlReader.NamespaceEquals(this.EmptyNamespace))
                {
                    if (this.XmlReader.LocalNameEquals(this.AtomHRefAttributeName))
                    {
                        categoriesMetadata.Href = this.ProcessUriFromPayload(attributeValue, this.XmlReader.XmlBaseUri);
                    }
                    else if (this.XmlReader.LocalNameEquals(this.AtomPublishingFixedAttributeName))
                    {
                        if (String.CompareOrdinal(attributeValue, AtomConstants.AtomPublishingFixedYesValue) == 0)
                        {
                            categoriesMetadata.Fixed = true;
                        }
                        else if (String.CompareOrdinal(attributeValue, AtomConstants.AtomPublishingFixedNoValue) == 0)
                        {
                            categoriesMetadata.Fixed = false;
                        }
                        else
                        {
                            throw new ODataException(Strings.ODataAtomServiceDocumentMetadataDeserializer_InvalidFixedAttributeValue(attributeValue));
                        }
                    }
                    else if (this.XmlReader.LocalNameEquals(this.AtomCategorySchemeAttributeName))
                    {
                        categoriesMetadata.Scheme = attributeValue;
                    }
                }
            }

            this.XmlReader.MoveToElement();

            if (!this.XmlReader.IsEmptyElement)
            {
                // read over the categories element
                this.XmlReader.ReadStartElement();

                do
                {
                    switch (this.XmlReader.NodeType)
                    {
                    case XmlNodeType.Element:
                        if (this.XmlReader.NamespaceEquals(this.AtomNamespace) && this.XmlReader.LocalNameEquals(this.AtomCategoryElementName))
                        {
                            categoryList.Add(this.ReadCategoryElementInCollection());
                        }

                        break;

                    case XmlNodeType.EndElement:
                        // end of 'categories' element.
                        break;

                    default:
                        // ignore all other nodes.
                        this.XmlReader.Skip();
                        break;
                    }
                }while (this.XmlReader.NodeType != XmlNodeType.EndElement);
            } // if (!this.XmlReader.IsEmptyElement)

            // read over the end tag of the categories element or the start tag if the categories element is empty.
            this.XmlReader.Read();

            categoriesMetadata.Categories = new ReadOnlyEnumerable <AtomCategoryMetadata>(categoryList);
            collectionMetadata.Categories = categoriesMetadata;
        }
 /// <summary>
 /// Visits an ATOM categories metadata.
 /// </summary>
 /// <param name="atomCategoriesMetadata">The categories metadata to visit.</param>
 protected virtual void VisitAtomCategoriesMetadata(AtomCategoriesMetadata atomCategoriesMetadata)
 {
     IEnumerable<AtomCategoryMetadata> categories = atomCategoriesMetadata.Categories;
     if (categories != null)
     {
         foreach (AtomCategoryMetadata category in categories)
         {
             this.VisitAtomMetadata(category);
         }
     }
 }
        /// <summary>
        /// Reads an app:categories element as well as each atom:category element contained within it, and adds the new information to <paramref name="collectionMetadata"/>.
        /// </summary>
        /// <param name="collectionMetadata">The non-null collection metadata object to augment.</param>
        /// <remarks>
        /// Pre-Condition:  XmlNodeType.Element - The start of the app:categories element.
        /// Post-Condition: Any                 - The next node after the app:categories element. 
        /// </remarks>
        internal void ReadCategoriesElementInCollection(AtomResourceCollectionMetadata collectionMetadata)
        {
            Debug.Assert(collectionMetadata != null, "collectionMetadata != null");
            this.AssertXmlCondition(XmlNodeType.Element);
            Debug.Assert(this.XmlReader.LocalName == AtomConstants.AtomPublishingCategoriesElementName, "Expected element named 'categories'.");
            Debug.Assert(this.XmlReader.NamespaceURI == AtomConstants.AtomPublishingNamespace, "Element 'categories' should be in the atom publishing namespace.");

            AtomCategoriesMetadata categoriesMetadata = new AtomCategoriesMetadata();
            List<AtomCategoryMetadata> categoryList = new List<AtomCategoryMetadata>();

            while (this.XmlReader.MoveToNextAttribute())
            {
                string attributeValue = this.XmlReader.Value;

                if (this.XmlReader.NamespaceEquals(this.EmptyNamespace))
                {
                    if (this.XmlReader.LocalNameEquals(this.AtomHRefAttributeName))
                    {
                        categoriesMetadata.Href = this.ProcessUriFromPayload(attributeValue, this.XmlReader.XmlBaseUri);
                    }
                    else if (this.XmlReader.LocalNameEquals(this.AtomPublishingFixedAttributeName))
                    {
                        if (String.CompareOrdinal(attributeValue, AtomConstants.AtomPublishingFixedYesValue) == 0)
                        {
                            categoriesMetadata.Fixed = true;
                        }
                        else if (String.CompareOrdinal(attributeValue, AtomConstants.AtomPublishingFixedNoValue) == 0)
                        {
                            categoriesMetadata.Fixed = false;
                        }
                        else
                        {
                            throw new ODataException(Strings.ODataAtomServiceDocumentMetadataDeserializer_InvalidFixedAttributeValue(attributeValue));
                        }
                    }
                    else if (this.XmlReader.LocalNameEquals(this.AtomCategorySchemeAttributeName))
                    {
                        categoriesMetadata.Scheme = attributeValue;
                    }
                }
            }

            this.XmlReader.MoveToElement();

            if (!this.XmlReader.IsEmptyElement)
            {
                // read over the categories element
                this.XmlReader.ReadStartElement();

                do
                {
                    switch (this.XmlReader.NodeType)
                    {
                        case XmlNodeType.Element:
                            if (this.XmlReader.NamespaceEquals(this.AtomNamespace) && this.XmlReader.LocalNameEquals(this.AtomCategoryElementName))
                            {
                                categoryList.Add(this.ReadCategoryElementInCollection());
                            }

                            break;
                        case XmlNodeType.EndElement:
                            // end of 'categories' element.
                            break;
                        default:
                            // ignore all other nodes.
                            this.XmlReader.Skip();
                            break;
                    }
                }
                while (this.XmlReader.NodeType != XmlNodeType.EndElement);
            } // if (!this.XmlReader.IsEmptyElement)

            // read over the end tag of the categories element or the start tag if the categories element is empty.
            this.XmlReader.Read();

            categoriesMetadata.Categories = new ReadOnlyEnumerable<AtomCategoryMetadata>(categoryList);
            collectionMetadata.Categories = categoriesMetadata;
        }