Esempio n. 1
0
        public void PropertyNestedClass()
        {
            var routeName = typeof(PropertyNestedClassHypermediaObject).Name + "_Route";

            RouteRegister.AddHypermediaObjectRoute(typeof(PropertyNestedClassHypermediaObject), routeName, HttpMethod.GET);

            var ho = new PropertyNestedClassHypermediaObject
            {
                AChild = new AttributedPropertyHypermediaObject
                {
                    Property1       = true,
                    Property2       = true,
                    NotRenamed      = true,
                    IgnoredProperty = true
                }
            };

            var siren = SirenConverter.ConvertToJson(ho);

            AssertDefaultClassName(siren, typeof(PropertyNestedClassHypermediaObject));
            AssertEmptyEntities(siren);
            AssertEmptyActions(siren);
            AssertHasOnlySelfLink(siren, routeName);

            var propertiesObject = PropertyHelpers.GetPropertiesJObject(siren);

            Assert.AreEqual(1, propertiesObject.Properties().Count());
            var nestedJObject = (JObject)siren["properties"][nameof(PropertyNestedClassHypermediaObject.AChild)];

            // one property is ignored
            Assert.AreEqual(3, nestedJObject.Properties().Count());
            Assert.AreEqual(ho.AChild.Property1, nestedJObject["Property1Renamed"].Value <bool>());
            Assert.AreEqual(ho.AChild.Property2, nestedJObject["Property2Renamed"].Value <bool>());
            Assert.AreEqual(ho.AChild.NotRenamed, nestedJObject[nameof(AttributedPropertyHypermediaObject.NotRenamed)].Value <bool>());
        }
Esempio n. 2
0
        public void PropertyNestedClassNullNoNullProperties()
        {
            var routeName = typeof(PropertyNestedClassHypermediaObject).Name + "_Route";

            RouteRegister.AddHypermediaObjectRoute(typeof(PropertyNestedClassHypermediaObject), routeName, HttpMethod.GET);

            var ho = new PropertyNestedClassHypermediaObject
            {
                AChild = null
            };

            var siren = SirenConverterNoNullProperties.ConvertToJson(ho);

            AssertDefaultClassName(siren, typeof(PropertyNestedClassHypermediaObject));
            AssertEmptyEntities(siren);
            AssertEmptyActions(siren);
            AssertHasOnlySelfLink(siren, routeName);

            var propertiesObject = PropertyHelpers.GetPropertiesJObject(siren);

            Assert.AreEqual(propertiesObject.Properties().Count(), 0);
        }