示例#1
0
        public void TestEncodeToCBOR()
        {
            Cori       ciri1 = new Cori("coap://host");
            Cori       ciri2 = new Cori("http://host");
            CoralForm  form  = new CoralForm("http://apps.augustcellars.com/formRef", new Cori("coap://host/form1"));
            CBORObject cbor  = form.EncodeToCBORObject(ciri2, testDictionary);

            Assert.AreEqual(3, cbor[0].AsInt32());
            Assert.AreEqual(CBORType.Array, cbor[1].Type);
            Assert.AreEqual("[3, [0, \"http\", 1, \"apps.augustcellars.com\", 5, \"formRef\"], [0, \"coap\", 1, \"host\", 5, \"form1\"]]", cbor.ToString());

            form = new CoralForm("http://coreapps.org/base#lang", new Cori("coap://host/form1"));
            cbor = form.EncodeToCBORObject(ciri1, testDictionary);
            Assert.AreEqual("[3, 9, [5, \"form1\"]]", cbor.ToString());

            form = new CoralForm("http://coreapps.org/base#lang", new Cori("coap://host/form3"));
            cbor = form.EncodeToCBORObject(ciri1, testDictionary);
            Assert.AreEqual("[3, 9, 11]", cbor.ToString());

            form.FormFields.Add(new CoralFormField("http://apps.augustcellars.com/field1", CBORObject.True));
            form.FormFields.Add(new CoralFormField("http://apps.augustcellars.com/field2", CBORObject.FromObject(39)));
            form.FormFields.Add(new CoralFormField("http://apps.augustcellars.com/field3", new Cori("http://coreapps.org/base#update")));
            form.FormFields.Add(new CoralFormField("http://apps.augustcellars.com/field4", new Cori("coap://host3/form9")));
            form.FormFields.Add(new CoralFormField("http://apps.augustcellars.com/field6", new Cori("coap://host/form6")));
            form.FormFields.Add(new CoralFormField("http://coreapps.org/coap#type", new Cori("coap://host/form3")));

            cbor = form.EncodeToCBORObject(ciri1, testDictionary);
            Assert.AreEqual("[3, 9, 11, [[0, \"http\", 1, \"apps.augustcellars.com\", 5, \"field1\"], true, [0, \"http\", 1, \"apps.augustcellars.com\", 5, \"field2\"], 39, [0, \"http\", 1, \"apps.augustcellars.com\", 5, \"field3\"], 99999(4), [0, \"http\", 1, \"apps.augustcellars.com\", 5, \"field4\"], [1, \"host3\", 5, \"form9\"], [0, \"http\", 1, \"apps.augustcellars.com\", 5, \"field6\"], [5, \"form6\"], 8, 99999(11)]]", cbor.ToString());
        }
示例#2
0
        public void TestConstructors()
        {
            CoralForm form = new CoralForm("http://apps.augustcellar.com/formRef", new Cori("coap://host:99/form"));

            Assert.AreEqual("http://apps.augustcellar.com/formRef", form.OperationTypeText);
            Assert.AreEqual("coap://host:99/form", form.Target.ToString());
            Assert.IsNull(form.TargetInt);
            Assert.AreEqual(0, form.FormFields.Count);

            form = new CoralForm(CBORObject.DecodeFromBytes(Hex.Decode("8303860064687474700176617070732E61756775737463656C6C6172732E636F6D0567666F726D5265668404000564666F726D")), new Cori("coap://host:99/form2"), testDictionary);
            Assert.AreEqual("http://apps.augustcellars.com/formRef", form.OperationTypeText);
            Assert.IsNull(form.OperationTypeInt);
            Assert.AreEqual("[0, \"coap\", 1, \"host\", 3, 99, 5, \"form\"]", form.Target.Data.ToString());
            Assert.IsNull(form.TargetInt);
            Assert.AreEqual(0, form.FormFields.Count);

            form = new CoralForm(CBORObject.DecodeFromBytes(Hex.Decode("8403068404000564666F726D88860064687474700176617070732E61756775737463656C6C6172732E636F6D05666669656C6431F5860064687474700176617070732E61756775737463656C6C6172732E636F6D05666669656C64328404000565666F726D33860064687474700176617070732E61756775737463656C6C6172732E636F6D05666669656C64330502DA0001869F04")),
                                 new Cori("coap://host:99/form2"), testDictionary);
            Assert.AreEqual("http://coreapps.org/base#search", form.OperationTypeText);
            Assert.AreEqual(6, form.OperationTypeInt);
            Assert.AreEqual("[0, \"coap\", 1, \"host\", 3, 99, 5, \"form\"]", form.Target.Data.ToString());
            Assert.IsNull(form.TargetInt);
            Assert.AreEqual(4, form.FormFields.Count);

            Assert.AreEqual("http://apps.augustcellars.com/field1", form.FormFields[0].FieldTypeText);
            Assert.IsNull(form.FormFields[0].FieldTypeInt);
            Assert.AreEqual(CBORType.Boolean, form.FormFields[0].Literal.Type);
            Assert.IsTrue(form.FormFields[0].Literal.IsTrue);
            Assert.IsNull(form.FormFields[0].LiteralInt);

            Assert.AreEqual("http://apps.augustcellars.com/field2", form.FormFields[1].FieldTypeText);
            Assert.IsNull(form.FormFields[1].FieldTypeInt);
            Assert.IsNotNull(form.FormFields[1].Url);
            Assert.AreEqual("[0, \"coap\", 1, \"host\", 3, 99, 5, \"form3\"]", form.FormFields[1].Url.Data.ToString());
            Assert.IsNull(form.FormFields[1].LiteralInt);

            Assert.AreEqual("http://apps.augustcellars.com/field3", form.FormFields[2].FieldTypeText);
            Assert.IsNull(form.FormFields[2].FieldTypeInt);
            Assert.IsNotNull(form.FormFields[2].Literal);
            Assert.AreEqual(CBORType.Integer, form.FormFields[2].Literal.Type);
            Assert.AreEqual(5, form.FormFields[2].Literal.AsInt32());
            Assert.IsNull(form.FormFields[2].LiteralInt);

            Assert.AreEqual("http://www.iana.org/assignments/relation/collection", form.FormFields[3].FieldTypeText);
            Assert.IsNotNull(form.FormFields[3].FieldTypeInt);
            Assert.AreEqual("http://www.iana.org/assignments/relation/collection", form.FormFields[3].FieldTypeText);
            Assert.IsNotNull(form.FormFields[3].LiteralInt);
            Assert.AreEqual("http://coreapps.org/base#update", form.FormFields[3].Url.ToString());
        }
示例#3
0
        public void TestEncode()
        {
            CoralBody body = new CoralBody {
                new CoralLink("http://coreapps.org/collections#create", "yes"),
                new CoralLink("http://coreapps.org/coap#type", CBORObject.False)
            };
            CBORObject obj = body.EncodeToCBORObject(null);

            Assert.AreEqual("[[2, 3, \"yes\"], [2, 8, false]]", obj.ToString());

            //

            CoralBody body1 = new CoralBody()
            {
                new CoralLink("http://apps.augustcellars.com/link1", new Cori("coap://host/path1/path2/path3")),
                new CoralBaseDirective(new Cori("coaps://host/path1")),
                new CoralLink("http://apps.augustcellars.com/link1", new Cori("coap://host/path1/path2/path3")),
                new CoralLink("http://apps.augustcellars.com/link2", new Cori("coaps://host/path1/path2/path3"))
            };

            CoralForm form = new CoralForm("http://apps.augustcellars.com/form1", new Cori("coap://host/path1/path4"));

            form.FormFields.Add(new CoralFormField("http://apps.augustcellars.com/field1", new Cori("coap://host/path2")));
            form.FormFields.Add(new CoralFormField("http://apps.augustcellars.com/field2", new Cori("coaps://host/path2")));

            body = new CoralBody()
            {
                new CoralLink("http://apps.augustcellars.com/link1", new Cori("coap://host/path"), body1),
                new CoralBaseDirective(new Cori("http://host")),
                new CoralLink("http://apps.augustcellars.com/link1", new Cori("coap://host/path"), body1),
                new CoralLink("http://apps.augustcellars.com/link2", new Cori("http://host/path1"), body1),
            };

            obj = body.EncodeToCBORObject(new Cori("coap://host"), _testDictionary);
            Assert.AreEqual("[[2, [0, \"http\", 1, \"apps.augustcellars.com\", 5, \"link1\"], [5, \"path\"], [[2, [0, \"http\", 1, \"apps.augustcellars.com\", 5, \"link1\"], [5, \"path1\", 5, \"path2\", 5, \"path3\"]], [1, [0, \"coaps\", 1, \"host\", 5, \"path1\"]], [2, [0, \"http\", 1, \"apps.augustcellars.com\", 5, \"link1\"], [0, \"coap\", 1, \"host\", 5, \"path1\", 5, \"path2\", 5, \"path3\"]], [2, [0, \"http\", 1, \"apps.augustcellars.com\", 5, \"link2\"], [4, 2, 5, \"path2\", 5, \"path3\"]]]], [1, [0, \"http\", 1, \"host\"]], [2, [0, \"http\", 1, \"apps.augustcellars.com\", 5, \"link1\"], [0, \"coap\", 1, \"host\", 5, \"path\"], [[2, [0, \"http\", 1, \"apps.augustcellars.com\", 5, \"link1\"], [0, \"coap\", 1, \"host\", 5, \"path1\", 5, \"path2\", 5, \"path3\"]], [1, [0, \"coaps\", 1, \"host\", 5, \"path1\"]], [2, [0, \"http\", 1, \"apps.augustcellars.com\", 5, \"link1\"], [0, \"coap\", 1, \"host\", 5, \"path1\", 5, \"path2\", 5, \"path3\"]], [2, [0, \"http\", 1, \"apps.augustcellars.com\", 5, \"link2\"], [4, 2, 5, \"path2\", 5, \"path3\"]]]], [2, [0, \"http\", 1, \"apps.augustcellars.com\", 5, \"link2\"], [5, \"path1\"], [[2, [0, \"http\", 1, \"apps.augustcellars.com\", 5, \"link1\"], [0, \"coap\", 1, \"host\", 5, \"path1\", 5, \"path2\", 5, \"path3\"]], [1, [0, \"coaps\", 1, \"host\", 5, \"path1\"]], [2, [0, \"http\", 1, \"apps.augustcellars.com\", 5, \"link1\"], [0, \"coap\", 1, \"host\", 5, \"path1\", 5, \"path2\", 5, \"path3\"]], [2, [0, \"http\", 1, \"apps.augustcellars.com\", 5, \"link2\"], [4, 2, 5, \"path2\", 5, \"path3\"]]]]]", obj.ToString());
        }