Esempio n. 1
0
        public static SingleTestMIA CreateSingleMIA(string table, Cardinality cardinality, bool createStringAttribute, bool createIntegerAttribute)
        {
            SingleTestMIA mia = new SingleTestMIA();

            mia.ASPECT_ID = Guid.NewGuid();

            IList <MediaItemAspectMetadata.SingleAttributeSpecification> attributes = new List <MediaItemAspectMetadata.SingleAttributeSpecification>();

            if (createStringAttribute)
            {
                attributes.Add(mia.ATTR_STRING = MediaItemAspectMetadata.CreateSingleStringAttributeSpecification("ATTR_STRING", 10, cardinality, false));
            }
            if (createIntegerAttribute)
            {
                attributes.Add(mia.ATTR_INTEGER = MediaItemAspectMetadata.CreateSingleAttributeSpecification("ATTR_INTEGER", typeof(Int32), cardinality, true));
            }

            mia.Metadata = new SingleMediaItemAspectMetadata(mia.ASPECT_ID, table, attributes.ToArray());

            return(mia);
        }
        public void TestSingleMIAM()
        {
            SingleTestMIA src = TestCommonUtils.CreateSingleMIA("Single", Cardinality.Inline, true, false);

            TextWriter writer     = new StringWriter();
            XmlWriter  serialiser = new XmlTextWriter(writer);

            serialiser.WriteStartElement("Test"); // Wrapper around the albums
            src.Metadata.Serialize(serialiser);
            serialiser.WriteEndElement();

            Console.WriteLine("XML: {0}", writer);

            XmlReader reader = XmlReader.Create(new StringReader(writer.ToString()));

            reader.Read(); // Test tag

            reader.Read(); // MIAM tag
            SingleMediaItemAspectMetadata dest = MediaItemAspectMetadata.Deserialize(reader) as SingleMediaItemAspectMetadata;

            Assert.IsNotNull(dest);
            Assert.AreEqual(src.Metadata.AspectId, dest.AspectId);
            Assert.AreEqual(src.Metadata.AttributeSpecifications.Count, dest.AttributeSpecifications.Count);

            MediaItemAspectMetadata.SingleAttributeSpecification srcSpec = src.Metadata.AttributeSpecifications[src.ATTR_STRING.AttributeName] as MediaItemAspectMetadata.SingleAttributeSpecification;
            Assert.IsNotNull(srcSpec);

            MediaItemAspectMetadata.SingleAttributeSpecification destSpec = dest.AttributeSpecifications[src.ATTR_STRING.AttributeName] as MediaItemAspectMetadata.SingleAttributeSpecification;
            Assert.IsNotNull(destSpec);

            Assert.AreEqual(srcSpec.AttributeName, destSpec.AttributeName);
            Assert.AreEqual(srcSpec.AttributeType, destSpec.AttributeType);
            Assert.AreEqual(srcSpec.Cardinality, destSpec.Cardinality);
            Assert.AreEqual(srcSpec.IsCollectionAttribute, destSpec.IsCollectionAttribute);
            Assert.AreEqual(srcSpec.IsIndexed, destSpec.IsIndexed);
            Assert.AreEqual(srcSpec.MaxNumChars, destSpec.MaxNumChars);
        }