Exemplo n.º 1
0
        public void LinksHypermediaObjectReferenceWithRouteKeyTest()
        {
            var routeNameLinking = typeof(LinkingHypermediaObject).Name + "_Route";

            RouteRegister.AddHypermediaObjectRoute(typeof(LinkingHypermediaObject), routeNameLinking, HttpMethod.GET);

            var routeNameLinked1 = typeof(LinkedHypermediaObjectWithKey).Name + "_Route";

            RouteRegister.AddHypermediaObjectRoute(typeof(LinkedHypermediaObjectWithKey), routeNameLinked1, HttpMethod.GET);
            var hoLink1 = new LinkedHypermediaObjectWithKey {
                Id = 42
            };
            var link1Rel = "Link1";

            RouteRegister.AddRouteKeyProducer(typeof(LinkedHypermediaObjectWithKey), new LinkedHypermediaObjectWithKeyRouteKeyProvider());

            var ho = new LinkingHypermediaObject();

            ho.Links.Add(link1Rel, new HypermediaObjectReference(hoLink1));

            var siren = SirenConverter.ConvertToJson(ho);

            AssertDefaultClassName(siren, typeof(LinkingHypermediaObject));
            AssertEmptyProperties(siren);
            AssertEmptyEntities(siren);
            AssertEmptyActions(siren);

            Assert.IsTrue(siren["links"].Type == JTokenType.Array);
            var linksArray = (JArray)siren["links"];

            Assert.AreEqual(linksArray.Count, ho.Links.Count);

            AssertHasLink(linksArray, DefaultHypermediaRelations.Self, routeNameLinking);
            AssertHasLinkWithKey(linksArray, link1Rel, routeNameLinked1, "{ key = 42 }");
        }
Exemplo n.º 2
0
        public void LinksMultipleRelationTest()
        {
            var routeNameLinking = typeof(LinkingHypermediaObject).Name + "_Route";

            RouteRegister.AddHypermediaObjectRoute(typeof(LinkingHypermediaObject), routeNameLinking, HttpMethod.GET);

            var routeNameLinked1 = typeof(Linked1HypermediaObject).Name + "_Route";

            RouteRegister.AddHypermediaObjectRoute(typeof(Linked1HypermediaObject), routeNameLinked1, HttpMethod.GET);
            var hoLink1  = new Linked1HypermediaObject();
            var multiRel = new List <string> {
                "RelA", "RelB"
            };

            var ho = new LinkingHypermediaObject();

            ho.Links.Add(multiRel, new HypermediaObjectReference(hoLink1));

            var siren = SirenConverter.ConvertToJson(ho);

            AssertDefaultClassName(siren, typeof(LinkingHypermediaObject));
            AssertEmptyProperties(siren);
            AssertEmptyEntities(siren);
            AssertEmptyActions(siren);

            Assert.IsTrue(siren["links"].Type == JTokenType.Array);
            var linksArray = (JArray)siren["links"];

            Assert.AreEqual(linksArray.Count, ho.Links.Count);

            AssertHasLink(linksArray, multiRel, routeNameLinked1);
        }
Exemplo n.º 3
0
        public void LinksHypermediaObjectQueryReferenceTest()
        {
            var routeNameLinking = typeof(LinkingHypermediaObject).Name + "_Route";

            RouteRegister.AddHypermediaObjectRoute(typeof(LinkingHypermediaObject), routeNameLinking, HttpMethod.GET);

            var routeNameLinked1 = typeof(Linked1HypermediaObject).Name + "_Route";

            RouteRegister.AddHypermediaObjectRoute(typeof(Linked1HypermediaObject), routeNameLinked1, HttpMethod.GET);
            var link1Rel     = "Link1";
            var queryObject1 = new QueryObject {
                ABool = true, AInt = 3
            };


            var routeNameLinked2 = typeof(LinkedHypermediaObjectWithKey).Name + "_Route";

            RouteRegister.AddHypermediaObjectRoute(typeof(LinkedHypermediaObjectWithKey), routeNameLinked2, HttpMethod.GET);
            RouteRegister.AddRouteKeyProducer(typeof(LinkedHypermediaObjectWithKey), new LinkedHypermediaObjectWithKeyRouteKeyProvider());
            var link2Rel     = "Link2";
            var queryObject2 = new QueryObject {
                ABool = false, AInt = 5
            };

            var ho = new LinkingHypermediaObject();

            ho.Links.Add(link1Rel, new HypermediaObjectQueryReference(typeof(Linked1HypermediaObject), queryObject1));
            ho.Links.Add(link2Rel, new HypermediaObjectQueryReference(typeof(LinkedHypermediaObjectWithKey), queryObject2, 3));

            var siren = SirenConverter.ConvertToJson(ho);

            AssertDefaultClassName(siren, typeof(LinkingHypermediaObject));
            AssertEmptyProperties(siren);
            AssertEmptyEntities(siren);
            AssertEmptyActions(siren);

            Assert.IsTrue(siren["links"].Type == JTokenType.Array);
            var linksArray = (JArray)siren["links"];

            Assert.AreEqual(linksArray.Count, ho.Links.Count);

            AssertHasLink(linksArray, DefaultHypermediaRelations.Self, routeNameLinking);
            AssertHasLinkWithQuery(linksArray, link1Rel, routeNameLinked1, QueryStringBuilder.CreateQueryString(queryObject1));
            AssertHasLinkWithKeyAndQuery(linksArray, link2Rel, routeNameLinked2, "{ key = 3 }", QueryStringBuilder.CreateQueryString(queryObject2));
        }
Exemplo n.º 4
0
        public void LinksHypermediaObjectReferenceTest()
        {
            var routeNameLinking = typeof(LinkingHypermediaObject).Name + "_Route";

            RouteRegister.AddHypermediaObjectRoute(typeof(LinkingHypermediaObject), routeNameLinking);

            var routeNameLinked1 = typeof(Linked1HypermediaObject).Name + "_Route";

            RouteRegister.AddHypermediaObjectRoute(typeof(Linked1HypermediaObject), routeNameLinked1);
            var hoLink1  = new Linked1HypermediaObject();
            var link1Rel = "Link1";

            var routeNameLinked2 = typeof(Linked2HypermediaObject).Name + "_Route";

            RouteRegister.AddHypermediaObjectRoute(typeof(Linked2HypermediaObject), routeNameLinked2);
            var hoLink2  = new Linked2HypermediaObject();
            var link2Rel = "Link2";

            var ho = new LinkingHypermediaObject();

            ho.Links.Add(link1Rel, new HypermediaObjectReference(hoLink1));
            ho.Links.Add(link2Rel, new HypermediaObjectReference(hoLink2));


            var siren = SirenConverter.ConvertToJson(ho);

            AssertDefaultClassName(siren, typeof(LinkingHypermediaObject));
            AssertEmptyProperties(siren);
            AssertEmptyEntities(siren);
            AssertEmptyActions(siren);

            Assert.IsTrue(siren["links"].Type == JTokenType.Array);
            var linksArray = (JArray)siren["links"];

            Assert.AreEqual(linksArray.Count, ho.Links.Count);

            AssertHasLink(linksArray, DefaultHypermediaRelations.Self, routeNameLinking);
            AssertHasLink(linksArray, link1Rel, routeNameLinked1);
            AssertHasLink(linksArray, link2Rel, routeNameLinked2);
        }