/// <summary> /// Checks that the actual value is not 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 equal to the expected value.</exception> public IChainableFluentAssertion <IFluentAssertion <N> > IsNotEqualTo(object expected) { var assertionRunner = this.fluentAssertion as IFluentAssertionRunner <N>; IRunnableAssertion <N> runnableAssertion = this; return(assertionRunner.ExecuteAssertion( () => { EqualityHelper.IsNotEqualTo(runnableAssertion.Value, expected); }, EqualityHelper.BuildErrorMessage(runnableAssertion.Value, expected, 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 <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 nullable value has no value and thus, is null. /// Note: this method does not return a chainable assertion since the nullable is null. /// </summary> /// <param name="fluentAssertion">The fluent assertion to be extended.</param> /// <exception cref="FluentAssertionException">The value is not null.</exception> public static void HasNoValue(this IFluentAssertion <int?> fluentAssertion) { var assertionRunner = fluentAssertion as IFluentAssertionRunner <int?>; IRunnableAssertion <int?> runnableAssertion = fluentAssertion as IRunnableAssertion <int?>; assertionRunner.ExecuteAssertion( () => { if (runnableAssertion.Value != null) { throw new FluentAssertionException(string.Format("\nThe checked nullable value:\n\t[{0}]\nhas a value, which is unexpected.", runnableAssertion.Value)); } }, "\nThe checked nullable value has no value, which is unexpected."); }
/// <summary> /// Checks that the actual value is more than a comparand. /// </summary> /// <param name="comparand"> /// Comparand to compare the value to. /// </param> /// <returns> /// A chainable assertion. /// </returns> /// <exception cref="FluentAssertionException"> /// The value is not less than the comparand. /// </exception> public IChainableFluentAssertion <IFluentAssertion <N> > IsGreaterThan(N comparand) { var assertionRunner = this.fluentAssertion as IFluentAssertionRunner <N>; IRunnableAssertion <N> runnableAssertion = this; return(assertionRunner.ExecuteAssertion( () => { if (runnableAssertion.Value.CompareTo(comparand) <= 0) { throw new FluentAssertionException(string.Format("\nThe checked value:\n\t[{0}]\nis not greater than:\n\t[{1}].", runnableAssertion.Value, comparand)); } }, string.Format("\nThe checked value:\n\t[{0}]\nis greater than:\n\t[{1}]\nwhich is unexpected.", runnableAssertion.Value.ToStringProperlyFormated(), comparand.ToStringProperlyFormated()))); }
/// <summary> /// Checks that the actual value is strictly positive. /// </summary> /// <returns>A chainable assertion.</returns> /// <exception cref="FluentAssertionException">The value is not strictly positive.</exception> public IChainableFluentAssertion <IFluentAssertion <N> > IsPositive() { var assertionRunner = this.fluentAssertion as IFluentAssertionRunner <N>; IRunnableAssertion <N> runnableAssertion = this; return(assertionRunner.ExecuteAssertion( () => { if (Convert.ToInt32(runnableAssertion.Value) <= 0) { throw new FluentAssertionException(string.Format("\nThe actual value:\n\t[{0}]{1}\nis not a strictly positive value.", runnableAssertion.Value, EqualityHelper.BuildTypeDescriptionMessage(runnableAssertion.Value))); } }, string.Format("\nThe checked value:\n\t[{0}]{1}\nis a strictly positive value, which is unexpected.", runnableAssertion.Value, EqualityHelper.BuildTypeDescriptionMessage(runnableAssertion.Value)))); }
/// <summary> /// Checks that the actual nullable value has a value and thus, is not null. /// </summary> /// <param name="fluentAssertion">The fluent assertion to be extended.</param> /// <returns>A chainable fluent assertion.</returns> /// <exception cref="FluentAssertionException">The value is null.</exception> public static IChainableNullableFluentAssertionOrNumberFluentAssertion <int> HasAValue(this IFluentAssertion <int?> fluentAssertion) { var assertionRunner = fluentAssertion as IFluentAssertionRunner <int?>; IRunnableAssertion <int?> runnableAssertion = fluentAssertion as IRunnableAssertion <int?>; assertionRunner.ExecuteAssertion( () => { if (runnableAssertion.Value == null) { throw new FluentAssertionException(string.Format("\nThe checked nullable value has no value, which is unexpected.")); } }, string.Format("\nThe checked nullable value:\n\t[{0}]\nhas a value, which is unexpected.", runnableAssertion.Value.ToStringProperlyFormated())); return(new ChainableNullableFluentAssertionOrNumberFluentAssertion <int>(fluentAssertion)); }
/// <summary> /// Checks that the actual value is NOT equal to zero. /// </summary> /// <returns> /// <returns>A chainable assertion.</returns> /// </returns> /// <exception cref="FluentAssertionException">The value is equal to zero.</exception> public IChainableFluentAssertion <IFluentAssertion <N> > IsNotZero() { var assertionRunner = this.fluentAssertion as IFluentAssertionRunner <N>; IRunnableAssertion <N> runnableAssertion = this; return(assertionRunner.ExecuteAssertion( () => { bool res = InternalIsZero(runnableAssertion.Value); if (res) { throw new FluentAssertionException(string.Format("\nThe actual value:\n\t[{0}]{1}\nis equal to zero.", runnableAssertion.Value, EqualityHelper.BuildTypeDescriptionMessage(runnableAssertion.Value))); } }, string.Format("\nThe checked value:\n\t[{0}] of type: [{1}]\nis not equal to zero which is unexpected.", runnableAssertion.Value, runnableAssertion.Value.GetTypeWithoutThrowingException()))); }
private static void ContainsExactlyImpl(IRunnableAssertion <IEnumerable> runnableAssertion, IEnumerable otherEnumerable) { if (otherEnumerable == null) { ThrowsNotExactlyException(runnableAssertion.Value, null); } var first = runnableAssertion.Value.GetEnumerator(); var enumerable = otherEnumerable as IList <object> ?? otherEnumerable.Cast <object>().ToList(); var second = enumerable.GetEnumerator(); while (first.MoveNext()) { if (!second.MoveNext() || !object.Equals(first.Current, second.Current)) { ThrowsNotExactlyException(runnableAssertion.Value, enumerable); } } if (second.MoveNext()) { ThrowsNotExactlyException(runnableAssertion.Value, enumerable); } }
public StructFluentAssertionRunner(IRunnableAssertion <T> runnableFluentAssertion) { this.runnableFluentAssertion = runnableFluentAssertion; }