Beispiel #1
0
        /// <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 <bool> > IsEqualTo(this IFluentAssertion <bool> fluentAssertion, object expected)
        {
            var assertionRunner   = fluentAssertion as IFluentAssertionRunner <bool>;
            var runnableAssertion = fluentAssertion as IRunnableAssertion <bool>;

            var instanceTypeMessage = EqualityHelper.BuildTypeDescriptionMessage(expected, false);

            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.ToStringProperlyFormated(), instanceTypeMessage)));
        }
Beispiel #2
0
        /// <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))));
        }
Beispiel #3
0
        /// <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())));
        }
Beispiel #4
0
        /// <summary>
        /// Determines whether the specified value is before the other one.
        /// </summary>
        /// <param name="fluentAssertion">The fluent assertion to be extended.</param>
        /// <param name="otherValue">The other value.</param>
        /// <returns>
        /// A chainable assertion.
        /// </returns>
        /// <exception cref="NFluent.FluentAssertionException">The current value is not before the other one.</exception>
        public static IChainableFluentAssertion <IFluentAssertion <IComparable> > IsBefore(this IFluentAssertion <IComparable> fluentAssertion, IComparable otherValue)
        {
            var assertionRunner   = fluentAssertion as IFluentAssertionRunner <IComparable>;
            var runnableAssertion = fluentAssertion as IRunnableAssertion <IComparable>;

            return(assertionRunner.ExecuteAssertion(
                       () =>
            {
                if (runnableAssertion.Value == null || runnableAssertion.Value.CompareTo(otherValue) >= 0)
                {
                    throw new FluentAssertionException(string.Format("\nThe actual value:\n\t[{0}]{1}\nis not before:\n\t[{2}]{3}.", runnableAssertion.Value.ToStringProperlyFormated(), EqualityHelper.BuildTypeDescriptionMessage(runnableAssertion.Value), otherValue.ToStringProperlyFormated(), EqualityHelper.BuildTypeDescriptionMessage(otherValue)));
                }
            },
                       string.Format("\nThe actual value:\n\t[{0}]{1}\nis before:\n\t[{2}]{3}.", runnableAssertion.Value.ToStringProperlyFormated(), EqualityHelper.BuildTypeDescriptionMessage(runnableAssertion.Value), otherValue.ToStringProperlyFormated(), EqualityHelper.BuildTypeDescriptionMessage(otherValue))));
        }