/// <summary> /// Checks whether if the checked value is different from the given type. /// </summary> /// <typeparam name="U">The given type to check the checked value against.</typeparam> /// <returns>A chainable check.</returns> /// <exception cref="FluentCheckException">The specified value is of the given type.</exception> public ICheckLink <IStructCheck <T> > IsNotInstanceOf <U>() where U : struct { this.structChecker.ExecuteCheck( () => IsInstanceHelper.IsNotInstanceOf(this.Value, typeof(U)), IsInstanceHelper.BuildErrorMessage(this.Value, typeof(U), false)); return(new CheckLink <IStructCheck <T> >(this)); }
/// <summary> /// Checks whether if the checked value is of the given type. /// </summary> /// <typeparam name="TU">The given type to check the checked value against.</typeparam> /// <returns>A chainable check.</returns> /// <exception cref="FluentCheckException">The specified value is null (and not of the same nullable type) or not of the given type.</exception> public ICheckLink <ICheck <T> > IsInstanceOf <TU>() { if (typeof(T).IsNullable()) { return(this.checker.ExecuteCheck( () => IsInstanceHelper.IsSameType(typeof(T), typeof(TU), this.Value), IsInstanceHelper.BuildErrorMessageForNullable(typeof(T), typeof(TU), this.Value, true))); } return(this.checker.ExecuteCheck(() => IsInstanceHelper.IsInstanceOf(this.Value, typeof(TU)), IsInstanceHelper.BuildErrorMessage(this.Value, typeof(TU), true))); }
/// <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())); }
/// <summary> /// Checks that the actual instance is not an instance of the given type. /// </summary> /// <typeparam name="T">The type not expected for this instance.</typeparam> /// <param name="fluentAssertion">The fluent assertion to be extended.</param> /// <returns> /// A chainable fluent assertion. /// </returns> /// <exception cref="FluentAssertionException">The actual instance is of the provided type.</exception> public static IChainableFluentAssertion <IFluentAssertion <TimeSpan> > IsNotInstanceOf <T>(this IFluentAssertion <TimeSpan> fluentAssertion) { var assertionRunner = fluentAssertion as IFluentAssertionRunner <TimeSpan>; var runnableAssertion = fluentAssertion as IRunnableAssertion <TimeSpan>; return(assertionRunner.ExecuteAssertion( () => { IsInstanceHelper.IsNotInstanceOf(runnableAssertion.Value, typeof(T)); }, IsInstanceHelper.BuildErrorMessage(runnableAssertion.Value, typeof(T), false))); }
/// <summary> /// Checks that the actual instance is not an instance of the given type. /// </summary> /// <typeparam name="T">The type not expected for this instance.</typeparam> /// <returns> /// A chainable fluent assertion. /// </returns> /// <exception cref="FluentAssertionException">The actual instance is of the provided type.</exception> public IChainableFluentAssertion <IFluentAssertion <N> > IsNotInstanceOf <T>() { var assertionRunner = this.fluentAssertion as IFluentAssertionRunner <N>; var runnableAssertion = this; return(assertionRunner.ExecuteAssertion( () => { IsInstanceHelper.IsNotInstanceOf(runnableAssertion.Value, typeof(T)); }, IsInstanceHelper.BuildErrorMessage(runnableAssertion, typeof(T), false))); }
/// <summary> /// Checks that the actual instance is an instance of the given type. /// </summary> /// <typeparam name="T">The expected Type of the instance.</typeparam> /// <param name="fluentAssertion">The fluent assertion to be extended.</param> /// <returns> /// A chainable fluent assertion. /// </returns> /// <exception cref="FluentAssertionException">The actual instance is not of the provided type.</exception> public static IChainableFluentAssertion <IFluentAssertion <object> > IsNotInstanceOf <T>(this IFluentAssertion <object> fluentAssertion) { var assertionRunner = fluentAssertion as IFluentAssertionRunner <object>; var runnableAssertion = fluentAssertion as IRunnableAssertion <object>; return(assertionRunner.ExecuteAssertion( () => { IsInstanceHelper.IsNotInstanceOf(runnableAssertion.Value, typeof(T)); }, string.Format("\nThe actual value:\n\t[{0}]\nis not an instance of:\n\t[{1}]\nbut an instance of:\n\t[{2}]\ninstead.", runnableAssertion.Value.ToStringProperlyFormated(), typeof(T), runnableAssertion.Value.GetType()))); }
/// <summary> /// Checks that the actual instance is an instance of the given type. /// </summary> /// <typeparam name="T">The expected Type of the instance.</typeparam> /// <param name="fluentAssertion">The fluent assertion to be extended.</param> /// <returns> /// A chainable fluent assertion. /// </returns> /// <exception cref="FluentAssertionException">The actual instance is not of the provided type.</exception> public static IChainableFluentAssertion <IFluentAssertion <int?> > IsInstanceOf <T>(this IFluentAssertion <int?> fluentAssertion) { var assertionRunner = fluentAssertion as IFluentAssertionRunner <int?>; IRunnableAssertion <int?> runnableAssertion = fluentAssertion as IRunnableAssertion <int?>; assertionRunner.ExecuteAssertion( () => { IsInstanceHelper.IsSameType(typeof(Nullable <int>), typeof(T), runnableAssertion.Value); }, IsInstanceHelper.BuildErrorMessageForNullable(typeof(Nullable <int>), typeof(T), runnableAssertion.Value, true)); return(new ChainableFluentAssertion <IFluentAssertion <int?> >(fluentAssertion)); }
/// <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()))); }
/// <summary> /// Checks whether if the checked value is different from the given type. /// </summary> /// <typeparam name="U">The given type to check the checked value against.</typeparam> /// <returns>A chainable check.</returns> /// <exception cref="FluentCheckException">The specified value is of the given type.</exception> public ICheckLink <ICheck <T> > IsNotInstanceOf <U>() { if (typeof(T).IsNullable()) { this.checker.ExecuteCheck( () => { if (typeof(T) == typeof(U)) { throw new FluentCheckException(IsInstanceHelper.BuildErrorMessageForNullable(typeof(T), typeof(U), this.Value, true)); } }, IsInstanceHelper.BuildErrorMessageForNullable(typeof(T), typeof(U), this.Value, false)); return(new CheckLink <ICheck <T> >(this)); } return(this.checker.ExecuteCheck( () => IsInstanceHelper.IsNotInstanceOf(this.Value, typeof(U)), IsInstanceHelper.BuildErrorMessage(this.Value, typeof(U), false))); }
/// <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)); }
/// <summary> /// Checks whether if the checked value is of the given type. /// </summary> /// <typeparam name="TU">The given type to check the checked value against.</typeparam> /// <returns>A chainable check.</returns> /// <exception cref="FluentCheckException">The specified value is not of the given type.</exception> public ICheckLink <IStructCheck <T> > IsInstanceOf <TU>() where TU : struct { return(this.structChecker.ExecuteCheck( () => IsInstanceHelper.IsInstanceOf(this.Value, typeof(TU)), IsInstanceHelper.BuildErrorMessage(this.Value, typeof(TU), true))); }