示例#1
0
        public void Constructors()
        {
            CoralLink link;

            link = new CoralLink("http://test.augustcellars.com/relation", CBORObject.FromObject(1));
            Assert.AreEqual(link.RelationTypeText, "http://test.augustcellars.com/relation");
            Assert.AreEqual(1, link.Value.AsInt32());

            link = new CoralLink("http://test.augustcellars.com/relation", "value");
            Assert.AreEqual("http://test.augustcellars.com/relation", link.RelationTypeText);
            Assert.AreEqual(CBORType.TextString, link.Value.Type);
            Assert.AreEqual("value", link.Value.AsString());

            link = new CoralLink("http://test.augustcellars.com/relation", new Cori("coap://host:5/root/path"));
            Assert.AreEqual("http://test.augustcellars.com/relation", link.RelationTypeText);
            Assert.IsNull(link.Value);
            Assert.AreEqual("coap://host:5/root/path", link.Target.ToString());


            Assert.ThrowsException <ArgumentException>(() => link = new CoralLink("relation", CBORObject.FromObject(DateTime.UtcNow)));
            Assert.ThrowsException <ArgumentException>(() => link = new CoralLink("http://test.augustcellars.com/relation", CBORObject.FromObject(DateTime.UtcNow)));
            Assert.ThrowsException <ArgumentException>(() => link = new CoralLink("http://test.augustcellars.com/relation", CBORObject.NewArray()));
            Assert.ThrowsException <ArgumentException>(() => link = new CoralLink("http://test.augustcellars.com/relation", CBORObject.NewMap()));
            Assert.ThrowsException <ArgumentException>(() => link = new CoralLink("http://test.augustcellars.com/relation", CBORObject.FromSimpleValue(99)));
            // Assert.ThrowsException<ArgumentException>(() => link = new CoralLink("relation", new Cori(CBORObject.DecodeFromBytes(Hex.Decode("8102")))));
        }