/// <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 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 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))); }