コード例 #1
0
        /// <summary>
        /// Checks that the actual expression is in the inheritance hierarchy of the given kind or of the same kind.
        /// </summary>
        /// <typeparam name="T">The Type which is expected to be a base Type of the actual expression.</typeparam>
        /// <param name="check">The fluent check to be extended.</param>
        /// <exception cref="FluentCheckException">The checked expression is not in the inheritance hierarchy of the given kind.</exception>
        public static void InheritsFrom <T>(this ICheck <object> check)
        {
            var checker = ExtensibilityHelper.ExtractChecker(check);

            Type instanceType     = checker.Value.GetTypeWithoutThrowingException();
            Type expectedBaseType = typeof(T);

            checker.ExecuteNotChainableCheck(
                () => IsInstanceHelper.InheritsFrom(checker, expectedBaseType),
                string.Format("\nThe checked expression is part of the inheritance hierarchy or of the same type than the specified one.\nIndeed, checked expression type:\n\t[{0}]\nis a derived type of\n\t[{1}].", instanceType.ToStringProperlyFormated(), expectedBaseType.ToStringProperlyFormated()));
        }
コード例 #2
0
        /// <summary>
        /// Checks that the actual expression is in the inheritance hierarchy of the given type or of the same type.
        /// </summary>
        /// <typeparam name="T">The Type which is expected to be a base Type of the actual expression.</typeparam>
        /// <param name="fluentAssertion">The fluent assertion to be extended.</param>
        /// <returns>
        /// A chainable fluent assertion.
        /// </returns>
        /// <exception cref="FluentAssertionException">The checked expression is not in the inheritance hierarchy of the given type.</exception>
        public static IChainableFluentAssertion <IFluentAssertion <object> > InheritsFrom <T>(this IFluentAssertion <object> fluentAssertion)
        {
            var assertionRunner   = fluentAssertion as IFluentAssertionRunner <object>;
            var runnableAssertion = fluentAssertion as IRunnableAssertion <object>;

            Type instanceType     = runnableAssertion.Value.GetTypeWithoutThrowingException();
            Type expectedBaseType = typeof(T);

            return(assertionRunner.ExecuteAssertion(
                       () =>
            {
                IsInstanceHelper.InheritsFrom(runnableAssertion.Value, expectedBaseType);
            },
                       string.Format("\nThe checked expression is part of the inheritance hierarchy or of the same type than the specified one.\nIndeed, checked expression type:\n\t[{0}]\nis a derived type of\n\t[{1}].", instanceType.ToStringProperlyFormated(), expectedBaseType.ToStringProperlyFormated())));
        }
コード例 #3
0
 /// <summary>
 /// Checks that the actual expression is in the inheritance hierarchy of the given kind or of the same kind.
 /// </summary>
 /// <typeparam name="T">Type of SUT</typeparam>
 /// <param name="check">The fluent check to be extended.</param>
 /// <param name="parentType">Expected type that should be^part of hierarchy</param>
 /// <returns>a check link object</returns>
 public static ICheckLink <ICheck <T> > InheritsFromType <T>(this ICheck <T> check, Type parentType)
 {
     IsInstanceHelper.InheritsFrom(check, parentType);
     return(ExtensibilityHelper.BuildCheckLink(check));
 }