Beispiel #1
0
        public void TestStringListProps()
        {
            ResourceSerializer serializer = new ResourceSerializer();
            IResource          origin     = _storage.NewResource("Email");

            origin.SetProp(_propSize, 100);
            origin.SetProp(_propReceived, DateTime.Now);
            IStringList strLst = origin.GetStringListProp(_propValueList);

            using ( strLst )
            {
                strLst.Add("One");
                strLst.Add("Two");
                strLst.Add("Three");
            }
            origin.SetProp(_propUnread, true);
            origin.SetProp(_propSimilarity, 1.0);
            ResourceNode resNode = serializer.AddResource(origin);

            foreach (IResourceProperty prop in origin.Properties)
            {
                resNode.AddProperty(prop);
            }
            serializer.GenerateXML("SerializationResult.xml");
            origin.Delete();

            StreamReader sr  = new StreamReader("SerializationResult.xml", Encoding.Default);
            string       str = Utils.StreamReaderReadToEnd(sr);

            Console.WriteLine(str);
            sr.Close();

            ResourceDeserializer deserializer = new ResourceDeserializer("SerializationResult.xml");
            ArrayList            list         = deserializer.GetSelectedResources();

            Assert.AreEqual(1, list.Count, "List must contain only one resource. Current count is [" + list.Count + "]");
            ResourceUnpack ru = (ResourceUnpack)list[0];

            origin = ru.Resource;
            Assert.IsTrue(origin.HasProp(_propValueList),
                          "Resource must contain StringList property");
            IStringList stringsList = origin.GetStringListProp(_propValueList);

            Assert.AreEqual(3, stringsList.Count, "StringList must contain three elements. Current count is [" + stringsList.Count + "]");

            Assert.AreEqual("One", stringsList [0], "StringList[ 0 ] must be equal to [One]. Current value is [" + stringsList[0] + "]");
            Assert.AreEqual("Two", stringsList [1], "StringList[ 1 ] must be equal to [Two]. Current value is [" + stringsList[1] + "]");
            Assert.AreEqual("Three", stringsList [2], "StringList[ 2 ] must be equal to [Three]. Current value is [" + stringsList[2] + "]");
        }