Пример #1
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");
        }
Пример #2
0
        /// <summary>
        /// Asserts that a type has the specified property by name and type
        /// </summary>
        /// <param name="type"></param>
        /// <param name="name"></param>
        /// <param name="withType"></param>
        /// <param name="shouldBeVirtual"></param>
        public static void ShouldHaveProperty(this Type type, string name, Type withType = null,
                                              bool shouldBeVirtual = false)
        {
            var propertyInfo = GetPropertyForPath(type, name);

            if (withType != null && withType != propertyInfo.PropertyType)
            {
                Assert.AreEqual(withType, propertyInfo.PropertyType,
                                "Found property '" + name + "' but not with expected type '" + withType.PrettyName() + "'");
            }
            if (shouldBeVirtual)
            {
                Assert.IsTrue(propertyInfo.GetAccessors().First().IsVirtual);
            }
        }