Exemplo n.º 1
0
        public void TestEmptyResource()
        {
            IResource person   = _storage.NewResource("Person");
            Stream    stream   = ResourceBinarySerialization.Serialize(person);
            IResource restored = ResourceBinarySerialization.Deserialize(stream);

            Assert.AreEqual(person.Type, restored.Type, "Types of original and deserialized resources are not equal");
        }
Exemplo n.º 2
0
        public void TestComplexLinks()
        {
/*
 *          IResource e1In = _storage.NewResource( "Email" );
 *          e1In.SetProp( "Folder", "Humor" );
 *          IResource e1Out = _storage.NewResource( "Email" );
 *          e1Out.SetProp( "Folder", "Humor" );
 */
            IResource e2 = _storage.NewResource("Email");
//            e2.SetProp( "Folder", "Sergey" );
            IResource e2Reply = _storage.NewResource("Email");
//            e2Reply.SetProp( "Folder", "SentItems" );
            IResource e3 = _storage.NewResource("Email");
//            e3.SetProp( "Folder", "Sergey" );
            IResource e3Reply = _storage.NewResource("Email");
//            e3Reply.SetProp( "Folder", "SentItems" );

            IResource mySelf = _storage.NewResource("Person");
            IResource person = _storage.NewResource("Person");

            e2.AddLink(_propFrom, person);
            e2.AddLink(_propTo, mySelf);
            e2Reply.AddLink(_propFrom, mySelf);
            e2Reply.AddLink(_propTo, person);

            e3.AddLink(_propFrom, person);
            e3.AddLink(_propTo, mySelf);
            e3Reply.AddLink(_propFrom, mySelf);
            e3Reply.AddLink(_propTo, person);

            Console.WriteLine(person.GetLinksOfType(null, _propFrom).Count.ToString());
            Console.WriteLine(person.GetLinksOfType(null, _propTo).Count.ToString());
            Stream stream = ResourceBinarySerialization.Serialize(person);

            person.Delete();
            person = ResourceBinarySerialization.Deserialize(stream);
            Console.WriteLine(person.GetLinksOfType(null, _propFrom).Count.ToString());
            Console.WriteLine(person.GetLinksOfType(null, _propTo).Count.ToString());
            Assert.AreEqual(2, person.GetLinksOfType(null, _propFrom).Count, "There must be 2 links From person to MySelf");
            Assert.AreEqual(2, person.GetLinksOfType(null, _propTo).Count, "There must be 2 links To person From MySelf");
//            Assert( "There must be 2 links From MySelf to person", mySelf.GetLinksOfType( null, _propFrom ).Count == 2 );
//            Assert( "There must be 2 links To MySelf From person", mySelf.GetLinksOfType( null, _propTo ).Count == 2 );

/*
 *          reply.AddLink( _propReply, origin );
 *          origin.AddLink( _propAuthor, person );
 *          Stream stream = ResourceBinarySerialization.Serialize( origin );
 *          origin.Delete();
 *          origin = ResourceBinarySerialization.Deserialize( stream );
 *          Assert( "Reply has no link to deserialized origin", reply.HasLink( _propReply, origin ) );
 *          Assert( "Person has no link to deserialized origin", person.HasLink( _propAuthor, origin ) );
 */
        }
Exemplo n.º 3
0
        public void TestBlobProps()
        {
            IResource    origin = _storage.NewResource("Email");
            MemoryStream body   = new MemoryStream(Encoding.ASCII.GetBytes("This is a body"));

            origin.SetProp(_propBody, body);
            Stream stream = ResourceBinarySerialization.Serialize(origin);

            origin.Delete();
            origin = ResourceBinarySerialization.Deserialize(stream);
            stream = origin.GetBlobProp(_propBody);
            Assert.AreEqual("This is a body", Utils.StreamToString(stream, Encoding.ASCII),
                            "Types of original and deserialized resources are not equal");
        }
Exemplo n.º 4
0
        public void TestLinks()
        {
            IResource origin = _storage.NewResource("Email");
            IResource reply  = _storage.NewResource("Email");
            IResource person = _storage.NewResource("Person");

            reply.AddLink(_propReply, origin);
            origin.AddLink(_propAuthor, person);
            Stream stream = ResourceBinarySerialization.Serialize(origin);

            origin.Delete();
            origin = ResourceBinarySerialization.Deserialize(stream);
            Assert.IsTrue(reply.HasLink(_propReply, origin), "Reply has no link to deserialized origin");
            Assert.IsTrue(person.HasLink(_propAuthor, origin), "Person has no link to deserialized origin");
        }
Exemplo n.º 5
0
        public void DeserializeExistingAccount()
        {
            string emailAddress = "*****@*****.**";

            IContact  contact      = Core.ContactManager.FindOrCreateContact(emailAddress, "Sergey Zhulin");
            IResource emailAccount = contact.Resource.GetLinkProp("EmailAcct");

            Assert.AreEqual(emailAddress, emailAccount.GetPropText("EmailAddress"));

            Stream strm = ResourceBinarySerialization.Serialize(contact.Resource);

            //  remove the contact but not the account.
            //  deserialize the contact, there must be only one account.
            contact.Resource.Delete();
            ResourceBinarySerialization.Deserialize(strm);
            IResourceList accounts = Core.ResourceStore.GetAllResources("EmailAccount");
            int           accCount = accounts.Count;

            Assert.AreEqual(accCount, 1);
            Assert.AreEqual(emailAddress, accounts[0].GetPropText("EmailAddress"));
        }
Exemplo n.º 6
0
        public void TestMixedProps()
        {
            IResource origin = _storage.NewResource("Email");
            IResource person = _storage.NewResource("Person");

            origin.AddLink(_propAuthor, person);
            origin.SetProp(_propSize, 100);
            DateTime now = DateTime.Now;

            origin.SetProp(_propReceived, 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);
            Stream stream = ResourceBinarySerialization.Serialize(origin);

            origin.Delete();
            origin = ResourceBinarySerialization.Deserialize(stream);
            Assert.IsTrue(person.HasLink(_propAuthor, origin), "Person has no link to deserialized origin");
            Assert.AreEqual(100, origin.GetIntProp(_propSize), "Deserialized origin has invalid size");
            Assert.AreEqual(now, origin.GetDateProp(_propReceived), "Deserialized origin has invalid received date");
            strLst = origin.GetStringListProp(_propValueList);
            using ( strLst )
            {
                Assert.IsTrue(strLst.Count == 3 && strLst[0] == "One" && strLst[1] == "Two" && strLst[2] == "Three",
                              "Deserialized origin has invalid value list");
            }
            Assert.IsTrue(origin.HasProp(_propUnread), "Deserialized origin is read");
            Assert.IsTrue(origin.GetDoubleProp(_propSimilarity) == 1.0, "Deserialized origin has invalid similarity");
        }