Esempio n. 1
0
        /// <summary>
        /// Asserts that a type does not have the specified property
        /// by name, and optionally by name and type
        /// </summary>
        /// <param name="type"></param>
        /// <param name="name"></param>
        /// <param name="withType"></param>
        public static void ShouldNotHaveProperty(this Type type, string name, Type withType = null)
        {
            Assert.IsNotNull(type, "Cannot interrogate properties on NULL type");
            var propertyInfo = FindPropertyInfoForPath(type, name);

            if (withType == null)
            {
                Assert.IsNull(propertyInfo, $"Expected not to find property {name} on type {type.Name}");
            }
            if (propertyInfo != null && propertyInfo.PropertyType == withType)
            {
                Assert.Fail($"Expected not to find property {name} with type {withType} on type {type.Name}");
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Asserts that a read-only property specified by
        /// name and property type exists on the type
        /// being operated on
        /// </summary>
        /// <param name="type"></param>
        /// <param name="name"></param>
        /// <param name="withType"></param>
        public static void ShouldHaveReadOnlyProperty(
            this Type type,
            string name,
            Type withType = null
            )
        {
            var propInfo = FindPropertyInfoForPath(type, name, Assert.Fail);

            if (withType != null)
            {
                Assert.AreEqual(withType, propInfo.PropertyType,
                                $"Expected {type.Name}.{name} to have type {withType}, but found {propInfo.PropertyType}");
            }
            Assert.IsNull(propInfo.GetSetMethod(), $"Expected {type.Name}.{name} to be read-only");
        }