Esempio n. 1
0
        public static void CompareNotNullProperties(JObject propertiesObject, PropertyHypermediaObject ho)
        {
            Assert.AreEqual(ho.ABool.ToString(), propertiesObject[nameof(PropertyHypermediaObject.ABool)].ToString());

            Assert.AreEqual(ho.AnInt.ToInvariantString(), propertiesObject[nameof(PropertyHypermediaObject.AnInt)].ToString());
            Assert.AreEqual(ho.ALong.ToInvariantString(), propertiesObject[nameof(PropertyHypermediaObject.ALong)].ToString());
            Assert.AreEqual(ho.AFloat.ToInvariantString(), ((float)propertiesObject[nameof(PropertyHypermediaObject.AFloat)]).ToInvariantString());
            Assert.AreEqual(ho.ADouble.ToInvariantString(), ((double)propertiesObject[nameof(PropertyHypermediaObject.ADouble)]).ToInvariantString());

            Assert.AreEqual(EnumHelper.GetEnumMemberValue(ho.AnEnum), propertiesObject[nameof(PropertyHypermediaObject.AnEnum)].ToString());
            Assert.AreEqual(EnumHelper.GetEnumMemberValue(ho.AnEnumWithNames), propertiesObject[nameof(PropertyHypermediaObject.AnEnumWithNames)].ToString());

            Assert.AreEqual(ho.ADateTime.ToStringZNotation(), ((IFormattable)propertiesObject[nameof(PropertyHypermediaObject.ADateTime)]).ToStringZNotation());
            Assert.AreEqual(ho.ADateTimeOffset.ToStringZNotation(), ((IFormattable)propertiesObject[nameof(PropertyHypermediaObject.ADateTimeOffset)]).ToStringZNotation());
            Assert.AreEqual(ho.ATimeSpan.ToInvariantString(), propertiesObject[nameof(PropertyHypermediaObject.ATimeSpan)].ToString());
            Assert.AreEqual(ho.ADecimal.ToInvariantString(), propertiesObject[nameof(PropertyHypermediaObject.ADecimal)].ToString());
        }
Esempio n. 2
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);
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
        public static void CompareHypermediaPropertiesAndJsonNoNullProperties(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 - 4);

            CompareNotNullProperties(propertiesObject, ho);

            Assert.IsNull(propertiesObject[nameof(PropertyHypermediaObject.AnUri)]);
            Assert.IsNull(propertiesObject[nameof(PropertyHypermediaObject.AString)]);
            Assert.IsNull(propertiesObject[nameof(PropertyHypermediaObject.ANullableInt)]);
            Assert.IsNull(propertiesObject[nameof(PropertyHypermediaObject.ANullableEnum)]);
        }
Esempio n. 5
0
        public static void CompareHypermediaPropertiesAndJson(JObject propertiesObject, PropertyHypermediaObject ho)
        {
            var propertyInfos = ho.GetType().GetProperties()
                                .Where(p => p.Name != "Entities" && p.Name != "Links")
                                .ToList();

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

            CompareNotNullProperties(propertiesObject, ho);

            Assert.AreEqual(ho.AnUri?.ToString(), propertiesObject[nameof(PropertyHypermediaObject.AnUri)].Value <string>());
            Assert.AreEqual(ho.AString, propertiesObject[nameof(PropertyHypermediaObject.AString)].Value <string>());
            Assert.AreEqual(ho.ANullableInt, propertiesObject[nameof(PropertyHypermediaObject.ANullableInt)]);
            Assert.AreEqual(ho.ANullableEnum?.ToString(), propertiesObject[nameof(PropertyHypermediaObject.ANullableEnum)].Value <string>());
        }