Esempio n. 1
0
        public void CreateSampleHalFromSpec() {
            var hal = new HalDocument("http://example.org");
            hal.AddNamespace("td", new Uri("http://mytodoapp.com/rels/"));

            hal.AddLink("td:search", "/todo-list/search;{searchterm}");
            hal.AddLink("td:description", "/todo-list/description");
            hal.AddProperty("created_at", "2010-01-16");
            hal.AddProperty("updated_at", "2010-02-21");
            hal.AddProperty("summary", "An example list");

            hal.CreateResource("td:owner", "http://range14sux.com/mike")
                    .AddProperty("name","Mike")
                    .AddProperty("age","36")
                    .AddLink("td:friend", "http://mamund.com/")
                .End();

            hal.CreateResource("td:item", "http://home.com/tasks/126")
                .AddProperty("title", "Find Mug")
                .AddProperty("details", "Find my mug.")

                .AddTypedResource("td:attachment", "text/plain", @"
            **********************************
                PLACES MY MUG COULD BE
            **********************************
              - Garden
              - Roof
              - Zipcar
              - Shelf
			")
                .AddLink("td:next", "http://work.com/todos/make-some-tea")
            .End();

            hal.CreateResource("td:item", "http://work.com/todos/make-some-tea")
                .AddProperty("title", "Make tea")
                .AddProperty("details", "Mike nice tea that is green. (Gyokuro)")
                .AddLink("td:prev", "http://home.com/tasks/126")
            .End();


            var stringHal = new StreamReader(hal.ToStream()).ReadToEnd();
            Assert.IsNotNull(hal);
            Assert.IsNotNull(stringHal);
        }
Esempio n. 2
0
        public void CreateHalManuallyUsingBuilder()
        {
            var hal = new HalDocument("http://example.org");

            hal.CreateResource("foo", "http://example.org/foo").End()
                .CreateResource("bar", "http://example.org/bar").End();

            var stringHal = new StreamReader(hal.ToStream()).ReadToEnd();
            Assert.IsNotNull(hal);
            Assert.IsNotNull(stringHal);
        }