Пример #1
0
        public void ConcreteTest()
        {
            String         link   = "</careless>;rt=\"SepararateResponseTester\";title=\"This resource will ACK anything, but never send a separate response\",</feedback>;rt=\"FeedbackMailSender\";title=\"POST feedback using mail\",</helloWorld>;rt=\"HelloWorldDisplayer\";title=\"GET a friendly greeting!\",</image>;ct=21;ct=22;ct=23;ct=24;rt=\"Image\";sz=18029;title=\"GET an image with different content-types\",</large>;rt=\"block\";title=\"Large resource\",</large_update>;rt=\"block observe\";title=\"Large resource that can be updated using PUT method\",</mirror>;rt=\"RequestMirroring\";title=\"POST request to receive it back as echo\",</obs>;obs;rt=\"observe\";title=\"Observable resource which changes every 5 seconds\",</query>;title=\"Resource accepting query parameters\",</seg1/seg2/seg3>;title=\"Long path resource\",</separate>;title=\"Resource which cannot be served immediately and which cannot be acknowledged in a piggy-backed way\",</storage>;obs;rt=\"Storage\";title=\"PUT your data here or POST new resources!\",</test>;title=\"Default test resource\",</timeResource>;rt=\"CurrentTime\";title=\"GET the current time\",</toUpper>;rt=\"UppercaseConverter\";title=\"POST text here to convert it to uppercase\",</weatherResource>;rt=\"ZurichWeather\";title=\"GET the current weather in zurich\"";
            RemoteResource res    = RemoteResource.NewRoot(link);
            String         result = LinkFormat.Serialize(res);

            Assert.AreEqual(link, result);
        }
Пример #2
0
        public void ConversionTest()
        {
            String         link1  = "</myUri/something>;ct=42;if=\"/someRef/path\";obs;rt=\"MyName\";sz=10";
            String         link2  = "</myUri>;rt=\"NonDefault\"";
            String         link3  = "</a>";
            String         format = link1 + "," + link2 + "," + link3;
            RemoteResource res    = RemoteResource.NewRoot(format);
            String         result = LinkFormat.Serialize(res);

            Assert.AreEqual(link3 + "," + link2 + "," + link1, result);
        }
Пример #3
0
        public void TestDiscoveryFiltering()
        {
            String expected = "</sensors/light>;if=\"sensor\";rt=\"light-lux\"";

            Request request = Request.NewGet();

            request.SetUri("coap://localhost/.well-known/core?rt=light-lux");

            DiscoveryResource discovery  = new DiscoveryResource(_root);
            String            serialized = LinkFormat.Serialize(_root, request.UriQueries);

            Assert.AreEqual(expected, serialized);
        }
Пример #4
0
        public void TestDiscovery()
        {
            String expected = "</sensors>;title=\"Sensor Index\"," +
                              "</sensors/light>;if=\"sensor\";rt=\"light-lux\"," +
                              "</sensors/temp>;bar=\"one\";bar=\"two\";foo;if=\"sensor\";rt=\"temperature-c\"";
            DiscoveryResource discovery  = new DiscoveryResource(_root);
            String            serialized = LinkFormat.Serialize(_root);

            Assert.AreEqual(expected, serialized);

            serialized = LinkFormat.Serialize(_root, new List <String>());
            Assert.AreEqual(expected, serialized);
        }
Пример #5
0
        public void MatchTest()
        {
            String         link1  = "</myUri/something>;ct=42;if=\"/someRef/path\";obs;rt=\"MyName\";sz=10";
            String         link2  = "</myUri>;ct=50;rt=\"MyName\"";
            String         link3  = "</a>;sz=10;rt=\"MyNope\"";
            String         format = link1 + "," + link2 + "," + link3;
            RemoteResource res    = RemoteResource.NewRoot(format);

            List <String> query = new List <string>();

            query.Add("rt=MyName");

            String queried = LinkFormat.Serialize(res, query);

            Assert.AreEqual(link2 + "," + link1, queried);
        }
Пример #6
0
        public void ConversionTestsToJson()
        {
            string link = "</sensors>;ct=40;title=\"Sensor Index\"," +
                          "</sensors/light>;if=\"sensor\";rt=\"light-lux\"," +
                          "</sensors/temp>;if=\"sensor\";obs;rt=\"temperature-c\"," +
                          "</t>;anchor=\"/sensors/temp\";rel=\"alternate\"," +
                          "<http://www.example.com/sensors/t123>;anchor=\"/sensors/temp\";ct=4711;foo=\"bar\";foo=3;rel=\"describedby\"";
            string jsonX = "[{\"href\":\"/sensors\",\"ct\":\"40\",\"title\":\"Sensor Index\"}," +
                           "{\"href\":\"/sensors/light\",\"if\":\"sensor\",\"rt\":\"light-lux\"}," +
                           "{\"href\":\"/sensors/temp\",\"if\":\"sensor\",\"obs\":true,\"rt\":\"temperature-c\"}," +
                           "{\"href\":\"/t\",\"anchor\":\"/sensors/temp\",\"rel\":\"alternate\"}," +
                           "{\"href\":\"http://www.example.com/sensors/t123\",\"anchor\":\"/sensors/temp\",\"ct\":\"4711\",\"foo\":[\"bar\",\"3\"],\"rel\":\"describedby\"}]";
            RemoteResource res = RemoteResource.NewRoot(link);

            string jsonOut = LinkFormat.SerializeJson(res, null);

            Assert.AreEqual(jsonOut, jsonX);

            res     = RemoteResource.NewRoot(jsonX, MediaType.ApplicationJson);
            jsonOut = LinkFormat.Serialize(res, null);
            Assert.AreEqual(jsonOut, link);
        }