/// <summary> /// Checks that the actual value is equal to another expected value. /// </summary> /// <typeparam name="T"> /// Type of the checked value. /// </typeparam> /// <param name="check"> /// The fluent check to be extended. /// </param> /// <param name="expected"> /// The expected value. /// </param> /// <returns> /// A check link. /// </returns> /// <exception cref="FluentCheckException"> /// The actual value is not equal to the expected value. /// </exception> public static ICheckLink <ICheck <T> > IsEqualTo <T>(this ICheck <T> check, object expected) { var checker = ExtensibilityHelper.ExtractChecker(check); return(checker.ExecuteCheck( () => EqualityHelper.IsEqualTo(checker, expected), EqualityHelper.BuildErrorMessage(checker, expected, true))); }
/// <summary> /// Checks that the actual value is equal to another expected value. /// </summary> /// <typeparam name="T">Type of the struct or the enum to assert on.</typeparam> /// <param name="check">The fluent fluent check.</param> /// <param name="expected">The expected value.</param> /// <returns> /// A check link. /// </returns> /// <exception cref="FluentCheckException">The actual value is not equal to the expected value.</exception> public static ICheckLink <IStructCheck <T> > IsEqualTo <T>(this IStructCheck <T> check, T expected) where T : struct { var runnableStructCheck = ExtensibilityHelper.ExtractStructChecker(check); return(runnableStructCheck.ExecuteCheck( () => EqualityHelper.IsEqualTo(runnableStructCheck, expected), EqualityHelper.BuildErrorMessage(runnableStructCheck, expected, true))); }
/// <summary> /// Checks that the actual value is equal to another expected value. /// </summary> /// <typeparam name="T">Type of the struct or the enum to assert on.</typeparam> /// <param name="fluentAssertion">The fluent fluent assertion.</param> /// <param name="expected">The expected value.</param> /// <returns> /// A chainable assertion. /// </returns> /// <exception cref="FluentAssertionException">The actual value is not equal to the expected value.</exception> public static IChainableFluentAssertion <IStructFluentAssertion <T> > IsEqualTo <T>(this IStructFluentAssertion <T> fluentAssertion, T expected) where T : struct { var assertionRunner = fluentAssertion as IStructFluentAssertionRunner <T>; var runnableAssertion = fluentAssertion as IRunnableAssertion <T>; return(assertionRunner.ExecuteAssertion( () => { EqualityHelper.IsEqualTo(runnableAssertion.Value, expected); }, EqualityHelper.BuildErrorMessage(runnableAssertion.Value, expected, true))); }
/// <summary> /// Checks that the actual value is equal to another expected value. /// </summary> /// <returns>A chainable assertion.</returns> /// <param name="expected">The expected value.</param> /// <exception cref="FluentAssertionException">The actual value is not equal to the expected value.</exception> public IChainableFluentAssertion <IFluentAssertion <N> > IsEqualTo(object expected) { var assertionRunner = this.fluentAssertion as IFluentAssertionRunner <N>; IRunnableAssertion <N> runnableAssertion = this; return(assertionRunner.ExecuteAssertion( () => { EqualityHelper.IsEqualTo(runnableAssertion.Value, expected); }, EqualityHelper.BuildErrorMessage(runnableAssertion.Value, expected, true))); }
// TODO: add IsNull() /// <summary> /// Checks that the actual value is equal to another expected value. /// </summary> /// <param name="fluentAssertion">The fluent assertion to be extended.</param> /// <param name="expected">The expected value.</param> /// <returns> /// A chainable assertion. /// </returns> /// <exception cref="FluentAssertionException">The actual value is not equal to the expected value.</exception> public static IChainableFluentAssertion <IFluentAssertion <object> > IsEqualTo(this IFluentAssertion <object> fluentAssertion, object expected) { var assertionRunner = fluentAssertion as IFluentAssertionRunner <object>; var runnableAssertion = fluentAssertion as IRunnableAssertion <object>; return(assertionRunner.ExecuteAssertion( () => { EqualityHelper.IsEqualTo(runnableAssertion.Value, expected); }, EqualityHelper.BuildErrorMessage(runnableAssertion.Value, expected, true))); }
/// <summary> /// Checks that the actual value is equal to another expected value. /// </summary> /// <param name="fluentAssertion">The fluent assertion to be extended.</param> /// <param name="expected">The expected value.</param> /// <returns> /// A chainable assertion. /// </returns> /// <exception cref="FluentAssertionException">The actual value is not equal to the expected value.</exception> public static IChainableFluentAssertion <IFluentAssertion <DateTime> > IsEqualTo(this IFluentAssertion <DateTime> fluentAssertion, object expected) { var assertionRunner = fluentAssertion as IFluentAssertionRunner <DateTime>; var runnableAssertion = fluentAssertion as IRunnableAssertion <DateTime>; return(assertionRunner.ExecuteAssertion( () => { EqualityHelper.IsEqualTo(runnableAssertion.Value, expected); }, string.Format("\nThe actual value is unexpectedly equal to the given one, i.e.:\n\t[{0}]{1}.", runnableAssertion.Value.ToStringProperlyFormated(), EqualityHelper.BuildTypeDescriptionMessage(expected, false)))); }
/// <summary> /// Checks whether the specified <see cref="System.Object"/> is equal to this instance or not. /// </summary> /// <param name="obj"> /// The <see cref="System.Object"/> to compare with this instance. /// </param> /// <returns> /// <c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; throws a <see cref="FluentCheckException"/> otherwise. /// </returns> /// <exception cref="FluentCheckException"> /// The specified <see cref="System.Object"/> is not equal to this instance. /// </exception> public new bool Equals(object obj) { this.checker.ExecuteCheck(() => EqualityHelper.IsEqualTo(this.checker, obj), EqualityHelper.BuildErrorMessage(this.checker, obj, true)); return(true); }