Exemplo 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>());
        }
Exemplo n.º 2
0
        public void SerializeListProperties()
        {
            var routeName = typeof(HypermediaObjectWithListProperties).Name + "_Route";

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

            var ho = new HypermediaObjectWithListProperties();

            ho.AValueList = new List <int> {
                3, 5, 7
            };
            ho.ANullableList = new List <int?> {
                2, null, 4
            };
            ho.AReferenceList = new List <string> {
                "a", "xyz"
            };
            ho.AValueArray = new[] { 6, 9, 2, 7 };
            ho.AObjectList = new List <Nested>
            {
                new Nested(3),
                new Nested(5)
            };

            ho.ListOfLists = new List <IEnumerable <int> >
            {
                new List <int> {
                    3, 4, 5
                },
                new List <int> {
                    6, 7, 8
                }
            };

            var siren = SirenConverter.ConvertToJson(ho);

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

            var propertiesObject = PropertyHelpers.GetPropertiesJObject(siren);

            PropertyHelpers.CompareHypermediaListPropertiesAndJson(propertiesObject, ho);

            AssertObjectList(ho, siren);
            AssertListOfLists(ho, siren);
        }
Exemplo n.º 3
0
        public void AttributedPropertyTest()
        {
            var routeName = typeof(AttributedPropertyHypermediaObject).Name + "_Route";

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

            var ho    = new AttributedPropertyHypermediaObject();
            var siren = SirenConverter.ConvertToJson(ho);

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

            var propertiesObject = PropertyHelpers.GetPropertiesJObject(siren);

            var propertyInfos = typeof(AttributedPropertyHypermediaObject).GetProperties()
                                .Where(p =>
                                       p.Name != "IgnoredProperty" &&
                                       p.Name != "Entities" &&
                                       p.Name != "Links")
                                .ToList();

            Assert.AreEqual(propertiesObject.Properties().Count(), propertyInfos.Count);

            foreach (var property in propertyInfos)
            {
                string lookupName;
                switch (property.Name)
                {
                case "Property1":
                    lookupName = "Property1Renamed";
                    break;

                case "Property2":
                    lookupName = "Property2Renamed";
                    break;

                default:
                    lookupName = property.Name;
                    break;
                }
                Assert.IsTrue(propertiesObject[lookupName] != null);
            }
        }
Exemplo n.º 4
0
        public void SerializeNullListPropertyNoNullPropertiesTest()
        {
            var routeName = typeof(HypermediaObjectWithListProperties).Name + "_Route";

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

            var ho    = new HypermediaObjectWithListProperties();
            var siren = SirenConverterNoNullProperties.ConvertToJson(ho);

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

            var propertiesObject = PropertyHelpers.GetPropertiesJObject(siren);

            Assert.AreEqual(propertiesObject.Properties().Count(), 0);
        }
Exemplo n.º 5
0
        public void PropertyDefaultsObjectWriteNoNullPropertiesTest()
        {
            var routeName = typeof(PropertyHypermediaObject).Name + "_Route";

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

            var ho    = new PropertyHypermediaObject();
            var siren = SirenConverterNoNullProperties.ConvertToJson(ho);

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

            var propertiesObject = PropertyHelpers.GetPropertiesJObject(siren);

            PropertyHelpers.CompareHypermediaPropertiesAndJsonNoNullProperties(propertiesObject, ho);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
        public void SerializeEmptyListProperties()
        {
            var routeName = typeof(HypermediaObjectWithListProperties).Name + "_Route";

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

            var ho = new HypermediaObjectWithListProperties();

            ho.AValueList     = new List <int>();
            ho.ANullableList  = new List <int?>();
            ho.AReferenceList = new List <string>();

            var siren = SirenConverter.ConvertToJson(ho);

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

            var propertiesObject = PropertyHelpers.GetPropertiesJObject(siren);

            PropertyHelpers.CompareHypermediaListPropertiesAndJson(propertiesObject, ho);
        }
Exemplo n.º 8
0
        public void PropertyObjectTest()
        {
            var routeName = typeof(PropertyHypermediaObject).Name + "_Route";

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

            var ho = new PropertyHypermediaObject
            {
                ABool   = true,
                AString = "My String",
                AnInt   = 1,
                ALong   = 2,
                AFloat  = 3.1f,
                ADouble = 4.1,

                AnEnum          = TestEnum.Value1,
                ANullableEnum   = TestEnum.Value1,
                AnEnumWithNames = TestEnumWithNames.Value2,

                ADateTime       = new DateTime(2000, 11, 22, 18, 5, 32, 999),
                ADateTimeOffset = new DateTimeOffset(2000, 11, 22, 18, 5, 32, 999, new TimeSpan(0, 2, 0, 0)),
                ATimeSpan       = new TimeSpan(1, 2, 3, 4),
                AnUri           = new Uri("http://localhost/myuri"),
                ADecimal        = 12345,
                ANullableInt    = 10,
            };
            var siren = SirenConverter.ConvertToJson(ho);

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

            var propertiesObject = PropertyHelpers.GetPropertiesJObject(siren);

            PropertyHelpers.CompareHypermediaPropertiesAndJson(propertiesObject, ho);
        }