private static void CompareHypermediaAndJson(JObject propertiesObject, PropertyHypermediaObject ho)
        {
            var propertyInfos = typeof(PropertyHypermediaObject).GetProperties()
                                .Where(p => p.Name != "Entities" && p.Name != "Links")
                                .ToList();

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

            CompareNotNullProperties(propertiesObject, ho);

            Assert.IsFalse(propertiesObject["AString"].HasValues);
            Assert.IsFalse(propertiesObject["ANullableInt"].HasValues);
        }
        private static void CompareNotNullProperties(JObject propertiesObject, PropertyHypermediaObject ho)
        {
            Assert.AreEqual(propertiesObject["ABool"].ToString(), ho.ABool.ToString());

            Assert.AreEqual(propertiesObject["AInt"].ToString(), ho.AInt.ToInvariantString());
            Assert.AreEqual(propertiesObject["ALong"].ToString(), ho.ALong.ToInvariantString());
            Assert.AreEqual(((float)propertiesObject["AFloat"]).ToInvariantString(), ho.AFloat.ToInvariantString());
            Assert.AreEqual(((double)propertiesObject["ADouble"]).ToInvariantString(), ho.ADouble.ToInvariantString());

            Assert.AreEqual(propertiesObject["AEnum"].ToString(), EnumHelper.GetEnumMemberValue(ho.AEnum));
            Assert.AreEqual(propertiesObject["AEnumWithNames"].ToString(), EnumHelper.GetEnumMemberValue(ho.AEnumWithNames));

            Assert.AreEqual(((IFormattable)propertiesObject["ADateTime"]).ToStringZNotation(),
                            ho.ADateTime.ToStringZNotation());
            Assert.AreEqual(((IFormattable)propertiesObject["ADateTimeOffset"]).ToStringZNotation(),
                            ho.ADateTimeOffset.ToStringZNotation());
            Assert.AreEqual(propertiesObject["ATimeSpan"].ToString(), ho.ATimeSpan.ToInvariantString());
            Assert.AreEqual(propertiesObject["ADecimal"].ToString(), ho.ADecimal.ToInvariantString());
        }
        public void PropertyDefaultsObjectTest()
        {
            var routeName = typeof(PropertyHypermediaObject).Name + "_Route";

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

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

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

            Assert.IsTrue(siren["properties"].Type == JTokenType.Object);
            var propertiesObject = (JObject)siren["properties"];

            CompareHypermediaAndJson(propertiesObject, ho);
        }
        public void PropertyDefaultsObjectWriteNoNullPropertiesTest()
        {
            var routeName = typeof(PropertyHypermediaObject).Name + "_Route";

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

            var ho = new PropertyHypermediaObject();
            var sirenBuilderWithNoNullProperties = CreateSirenConverter(new SirenConverterConfiguration {
                WriteNullProperties = false
            });
            var siren = sirenBuilderWithNoNullProperties.ConvertToJson(ho);

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

            Assert.IsTrue(siren["properties"].Type == JTokenType.Object);
            var propertiesObject = (JObject)siren["properties"];

            CompareHypermediaAndJsonNoNullProperties(propertiesObject, ho);
        }
        public void PropertyObjectTest()
        {
            var routeName = typeof(PropertyHypermediaObject).Name + "_Route";

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

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

                AEnum          = TestEnum.Value1,
                AEnumWithNames = 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),
                ADecimal        = 12345,
                ANullableInt    = 10,
            };
            var siren = SirenConverter.ConvertToJson(ho);

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

            Assert.IsTrue(siren["properties"].Type == JTokenType.Object);
            var propertiesObject = (JObject)siren["properties"];

            CompareHypermediaAndJson(propertiesObject, ho);
        }