예제 #1
0
        private PropertyInfo[] GetAllNonVirtualPropertiesFromSelection()
        {
            var query =
                from property in SubjectProperties
                where PropertyInfoAssertions.IsGetterNonVirtual(property)
                select property;

            return(query.ToArray());
        }
예제 #2
0
        /// <summary>
        /// Asserts that the current type does not have a property named <paramref name="name"/>.
        /// </summary>
        /// <param name="name">The name of the property.</param>
        /// <param name="because">A formatted phrase as is supported by <see cref="M:System.String.Format(System.String,System.Object[])"/> explaining why the assertion
        ///             is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically.</param>
        /// <param name="becauseArgs">Zero or more objects to format using the placeholders in <see cref="!:because"/>.</param>
        public AndConstraint <TypeAssertions> NotHaveProperty(string name, string because = "", params object[] becauseArgs)
        {
            PropertyInfo propertyInfo = Subject.GetPropertyByName(name);

            string propertyInfoDescription = "";

            if (propertyInfo != null)
            {
                propertyInfoDescription = PropertyInfoAssertions.GetDescriptionFor(propertyInfo);
            }

            Execute.Assertion.ForCondition(propertyInfo == null)
            .BecauseOf(because, becauseArgs)
            .FailWith(string.Format("Expected {0} to not exist{{reason}}, but it does.", propertyInfoDescription));

            return(new AndConstraint <TypeAssertions>(this));
        }
예제 #3
0
        /// <summary>
        /// Asserts that the current type has a property of type <paramref name="propertyType"/> named <paramref name="name"/>.
        /// </summary>
        /// <param name="because">A formatted phrase as is supported by <see cref="M:System.String.Format(System.String,System.Object[])"/> explaining why the assertion
        ///             is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically.</param>
        /// <param name="becauseArgs">Zero or more objects to format using the placeholders in <see cref="!:because"/>.</param>
        /// <param name="propertyType">The type of the property.</param>
        /// <param name="name">The name of the property.</param>
        public AndWhichConstraint <TypeAssertions, PropertyInfo> HaveProperty(Type propertyType, string name, string because = "", params object[] becauseArgs)
        {
            PropertyInfo propertyInfo = Subject.GetPropertyByName(name);

            string propertyInfoDescription = "";

            if (propertyInfo != null)
            {
                propertyInfoDescription = PropertyInfoAssertions.GetDescriptionFor(propertyInfo);
            }

            Execute.Assertion.ForCondition(propertyInfo != null)
            .BecauseOf(because, becauseArgs)
            .FailWith(String.Format("Expected {0} {1}.{2} to exist{{reason}}, but it does not.",
                                    propertyType.Name, Subject.FullName, name));

            Execute.Assertion.ForCondition(propertyInfo.PropertyType == propertyType)
            .BecauseOf(because, becauseArgs)
            .FailWith(String.Format("Expected {0} to be of type {1}{{reason}}, but it is not.",
                                    propertyInfoDescription, propertyType));

            return(new AndWhichConstraint <TypeAssertions, PropertyInfo>(this, propertyInfo));
        }
예제 #4
0
        /// <summary>
        /// Asserts that the current type has an indexer of type <paramref name="indexerType"/>.
        /// with parameter types <paramref name="parameterTypes"/>.
        /// </summary>
        /// <param name="indexerType">The type of the indexer.</param>
        /// <param name="parameterTypes">The parameter types for the indexer.</param>
        /// <param name="because">A formatted phrase as is supported by <see cref="M:System.String.Format(System.String,System.Object[])"/> explaining why the assertion
        ///             is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically.</param>
        /// <param name="becauseArgs">Zero or more objects to format using the placeholders in <see cref="!:because"/>.</param>
        public AndWhichConstraint <TypeAssertions, PropertyInfo> HaveIndexer(Type indexerType, IEnumerable <Type> parameterTypes, string because = "", params object[] becauseArgs)
        {
            PropertyInfo propertyInfo = Subject.GetIndexerByParameterTypes(parameterTypes);

            string propertyInfoDescription = "";

            if (propertyInfo != null)
            {
                propertyInfoDescription = PropertyInfoAssertions.GetDescriptionFor(propertyInfo);
            }

            Execute.Assertion.ForCondition(propertyInfo != null)
            .BecauseOf(because, becauseArgs)
            .FailWith(String.Format("Expected {0} {1}[{2}] to exist{{reason}}, but it does not.",
                                    indexerType.Name, Subject.FullName,
                                    GetParameterString(parameterTypes)));

            Execute.Assertion.ForCondition(propertyInfo.PropertyType == indexerType)
            .BecauseOf(because, becauseArgs)
            .FailWith(String.Format("Expected {0} to be of type {1}{{reason}}, but it is not.",
                                    propertyInfoDescription, indexerType));

            return(new AndWhichConstraint <TypeAssertions, PropertyInfo>(this, propertyInfo));
        }
        private static string GetDescriptionsFor(IEnumerable <PropertyInfo> properties)
        {
            IEnumerable <string> descriptions = properties.Select(property => PropertyInfoAssertions.GetDescriptionFor(property));

            return(string.Join(Environment.NewLine, descriptions));
        }