コード例 #1
0
        // Since this class is the model/template for the generation of all the other numbers related FluentAssertionExtensions classes, don't forget to re-generate all the other classes every time you change this one. To do that, just save the ..\T4\NumberFluentAssertionGenerator.tt file within Visual Studio 2012. This will trigger the T4 code generation process.

        /// <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 <int> > IsEqualTo(this IFluentAssertion <int> fluentAssertion, object expected)
        {
            // TODO transform NumberFluentAssertion<T> into a static class with functions only?
            var numberAssertionStrategy = new NumberFluentAssertion <int>(fluentAssertion);

            return(numberAssertionStrategy.IsEqualTo(expected));
        }
コード例 #2
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)));
        }
コード例 #3
0
        /// <summary>
        /// Checks that the actual value is true.
        /// </summary>
        /// <param name="fluentAssertion">The fluent assertion to be extended.</param>
        /// <returns>
        /// A chainable assertion.
        /// </returns>
        /// <exception cref="FluentAssertionException">The actual value is not true.</exception>
        public static IChainableFluentAssertion <IFluentAssertion <bool> > IsTrue(this IFluentAssertion <bool> fluentAssertion)
        {
            var assertionRunner   = fluentAssertion as IFluentAssertionRunner <bool>;
            var runnableAssertion = fluentAssertion as IRunnableAssertion <bool>;

            return(assertionRunner.ExecuteAssertion(
                       () =>
            {
                if (!runnableAssertion.Value)
                {
                    throw new FluentAssertionException(string.Format("\nThe actual value:\n\t[{0}]\nis not true.", runnableAssertion.Value.ToStringProperlyFormated()));
                }
            },
                       string.Format("\nThe actual value:\n\t[{0}]\nis true.", runnableAssertion.Value.ToStringProperlyFormated())));
        }
コード例 #4
0
        /// <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.");
        }
コード例 #5
0
        /// <summary>
        /// Checks that the actual value is less than an operand.
        /// </summary>
        /// <param name="fluentAssertion">
        /// The Fluent assertion to be extended.
        /// </param>
        /// <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 static IChainableFluentAssertion <IFluentAssertion <decimal> > IsLessThan(this IFluentAssertion <decimal> fluentAssertion, decimal comparand)
        {
            var numberAssertionStrategy = new NumberFluentAssertion <decimal>(fluentAssertion);

            return(numberAssertionStrategy.IsLessThan(comparand));
        }
コード例 #6
0
        /// <summary>
        /// Checks that the actual value is NOT equal to zero.
        /// </summary>
        /// <param name="fluentAssertion">The fluent assertion to be extended.</param>
        /// <returns>
        ///   <returns>A chainable assertion.</returns>
        /// </returns>
        /// <exception cref="FluentAssertionException">The value is equal to zero.</exception>
        public static IChainableFluentAssertion <IFluentAssertion <decimal> > IsNotZero(this IFluentAssertion <decimal> fluentAssertion)
        {
            var numberAssertionStrategy = new NumberFluentAssertion <decimal>(fluentAssertion);

            return(numberAssertionStrategy.IsNotZero());
        }
コード例 #7
0
        /// <summary>
        /// Checks that the actual duration is less (strictly) than a comparand.
        /// </summary>
        /// <param name="fluentAssertion">The fluent assertion to be extended.</param>
        /// <param name="comparand">The value to compare to.</param>
        /// <returns>A chainable assertion.</returns>
        /// <exception cref="FluentAssertionException">The actual value is not less than the provided comparand.</exception>
        public static IChainableFluentAssertion <IFluentAssertion <TimeSpan> > IsLessThan(this IFluentAssertion <TimeSpan> fluentAssertion, TimeSpan comparand)
        {
            var assertionRunner   = fluentAssertion as IFluentAssertionRunner <TimeSpan>;
            var runnableAssertion = fluentAssertion as IRunnableAssertion <TimeSpan>;

            TimeUnit unit = TimeHelper.DiscoverUnit(comparand);

            return(assertionRunner.ExecuteAssertion(
                       () =>
            {
                if (runnableAssertion.Value >= comparand)
                {
                    throw new FluentAssertionException(string.Format("\nThe actual value of:\n\t[{0} {2}]\nis not less than:\n\t[{1} {2}]\nas expected.", TimeHelper.Convert(runnableAssertion.Value, unit), TimeHelper.Convert(comparand, unit), unit));
                }
            },
                       string.Format("\nThe actual value of:\n\t[{0} {2}]\nis less than:\n\t[{1} {2}]\nwhich is unexpected.", TimeHelper.Convert(runnableAssertion.Value, unit), TimeHelper.Convert(comparand, unit), unit)));
        }
コード例 #8
0
        // 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)));
        }
コード例 #9
0
        /// <summary>
        /// Checks that the actual value is more than an operand.
        /// </summary>
        /// <param name="fluentAssertion">
        /// The Fluent assertion to be extended.
        /// </param>
        /// <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 static IChainableFluentAssertion <IFluentAssertion <int> > IsGreaterThan(this IFluentAssertion <int> fluentAssertion, int comparand)
        {
            var numberAssertionStrategy = new NumberFluentAssertion <int>(fluentAssertion);

            return(numberAssertionStrategy.IsGreaterThan(comparand));
        }
コード例 #10
0
        /// <summary>
        /// Checks that the enumerable contains only the values of another enumerable and nothing else, in order.
        /// This assertion should only be used with IEnumerable that have a consistent iteration order
        /// (i.e. don't use it with <see cref="Hashtable" />, prefer <see cref="ContainsOnly{T}" /> in that case).
        /// </summary>
        /// <param name="fluentAssertion">The fluent assertion to be extended.</param>
        /// <param name="otherEnumerable">The other enumerable containing the exact expected values to be found.</param>
        /// <returns>
        /// A chainable assertion.
        /// </returns>
        /// <exception cref="FluentAssertionException">The enumerable does not contains only the exact given values and nothing else, in order.</exception>
        public static IChainableFluentAssertion <IFluentAssertion <IEnumerable> > ContainsExactly(this IFluentAssertion <IEnumerable> fluentAssertion, IEnumerable otherEnumerable)
        {
            var assertionRunner   = fluentAssertion as IFluentAssertionRunner <IEnumerable>;
            var runnableAssertion = fluentAssertion as IRunnableAssertion <IEnumerable>;

            return(assertionRunner.ExecuteAssertion(
                       () =>
            {
                ContainsExactlyImpl(runnableAssertion, otherEnumerable);
            },
                       BuildExceptionMessageForContainsExactly(runnableAssertion.Value, otherEnumerable)));
        }
コード例 #11
0
        /// <summary>
        /// Checks that the enumerable has the proper number of elements.
        /// </summary>
        /// <param name="fluentAssertion">The fluent assertion to be extended.</param>
        /// <param name="expectedSize">The expected size to be found.</param>
        /// <returns>
        /// A chainable assertion.
        /// </returns>
        /// <exception cref="FluentAssertionException">The enumerable has not the expected number of elements.</exception>
        public static IChainableFluentAssertion <IFluentAssertion <IEnumerable> > HasSize(this IFluentAssertion <IEnumerable> fluentAssertion, long expectedSize)
        {
            var assertionRunner   = fluentAssertion as IFluentAssertionRunner <IEnumerable>;
            var runnableAssertion = fluentAssertion as IRunnableAssertion <IEnumerable>;

            return(assertionRunner.ExecuteAssertion(
                       () =>
            {
                HasSizeImpl(runnableAssertion.Value, expectedSize);
            },
                       BuildHasSizeExceptionMessage(runnableAssertion.Value)));
        }
コード例 #12
0
        /// <summary>
        /// Checks that the enumerable contains only the values present in another enumerable, and nothing else, in any order.
        /// </summary>
        /// <param name="fluentAssertion">The fluent assertion to be extended.</param>
        /// <param name="expectedValues">The expected values to be found.</param>
        /// <returns>
        /// A chainable assertion.
        /// </returns>
        /// <exception cref="FluentAssertionException">The enumerable does not contain only the expected values present in the other enumerable.</exception>
        public static IChainableFluentAssertion <IFluentAssertion <IEnumerable> > ContainsOnly(this IFluentAssertion <IEnumerable> fluentAssertion, IEnumerable expectedValues)
        {
            var assertionRunner   = fluentAssertion as IFluentAssertionRunner <IEnumerable>;
            var runnableAssertion = fluentAssertion as IRunnableAssertion <IEnumerable>;

            return(assertionRunner.ExecuteAssertion(
                       () =>
            {
                var unexpectedValuesFound = ExtractUnexpectedValues(runnableAssertion.Value, expectedValues);

                if (unexpectedValuesFound.Count > 0)
                {
                    throw new FluentAssertionException(string.Format("\nThe actual enumerable:\n\t[{0}]\ndoes not contain only the expected value(s):\n\t[{1}].\nIt contains also other values:\n\t[{2}]", runnableAssertion.Value.ToEnumeratedString(), expectedValues.ToEnumeratedString(), unexpectedValuesFound.ToEnumeratedString()));
                }
            },
                       string.Format("\nThe actual enumerable:\n\t[{0}]\ncontains only the expected value(s):\n\t[{1}].\nwhich is unexpected.", runnableAssertion.Value.ToEnumeratedString(), expectedValues.ToEnumeratedString())));
        }
コード例 #13
0
        /// <summary>
        /// Checks that the enumerable contains only the given expected values and nothing else, in order.
        /// This assertion should only be used with IEnumerable that have a consistent iteration order
        /// (i.e. don't use it with <see cref="Hashtable" />, prefer <see cref="ContainsOnly{T}" /> in that case).
        /// </summary>
        /// <typeparam name="T">Type of the elements to be found.</typeparam>
        /// <param name="fluentAssertion">The fluent assertion to be extended.</param>
        /// <param name="expectedValues">The expected values to be found.</param>
        /// <returns>
        /// A chainable assertion.
        /// </returns>
        /// <exception cref="FluentAssertionException">The enumerable does not contains only the exact given values and nothing else, in order.</exception>
        public static IChainableFluentAssertion <IFluentAssertion <IEnumerable> > ContainsExactly <T>(this IFluentAssertion <IEnumerable> fluentAssertion, params T[] expectedValues)
        {
            IEnumerable properExpectedValues = ExtractEnumerableValueFromPossibleOneValueArray(expectedValues);

            return(fluentAssertion.ContainsExactly(properExpectedValues));
        }
コード例 #14
0
        /// <summary>
        /// Checks that the enumerable contains all the values present in another enumerable, in any order.
        /// </summary>
        /// <param name="fluentAssertion">The fluent assertion to be extended.</param>
        /// <param name="otherEnumerable">The enumerable containing the expected values to be found.</param>
        /// <returns>
        /// A chainable assertion.
        /// </returns>
        /// <exception cref="FluentAssertionException">The enumerable does not contain all the expected values present in the other enumerable.</exception>
        public static IChainableFluentAssertion <IFluentAssertion <IEnumerable> > Contains(this IFluentAssertion <IEnumerable> fluentAssertion, IEnumerable otherEnumerable)
        {
            var assertionRunner   = fluentAssertion as IFluentAssertionRunner <IEnumerable>;
            var runnableAssertion = fluentAssertion as IRunnableAssertion <IEnumerable>;

            return(assertionRunner.ExecuteAssertion(
                       () =>
            {
                var notFoundValues = ExtractNotFoundValues(runnableAssertion.Value, otherEnumerable);

                if (notFoundValues.Count > 0)
                {
                    throw new FluentAssertionException(string.Format("\nThe actual enumerable:\n\t[{0}]\ndoes not contain the expected value(s):\n\t[{1}]", runnableAssertion.Value.ToEnumeratedString(), notFoundValues.ToEnumeratedString()));
                }
            },
                       string.Format("\nThe actual enumerable:\n\t[{0}]\ncontains all the given value(s):\n\t[{1}]\nwhich is unexpected.", runnableAssertion.Value.ToEnumeratedString(), otherEnumerable.ToEnumeratedString())));
        }
コード例 #15
0
        public static IChainableFluentAssertion <IFluentAssertion <Movie> > IsDirectedBy(this IFluentAssertion <Movie> fluentAssertion, string directorFullName)
        {
            var assertionRunner   = fluentAssertion as IFluentAssertionRunner <Movie>;
            var runnableAssertion = fluentAssertion as IRunnableAssertion <Movie>;

            return(assertionRunner.ExecuteAssertion(
                       () =>
            {
                if (!runnableAssertion.Value.Director.ToString().ToLower().Contains(directorFullName.ToLower()))
                {
                    throw new FluentAssertionException(string.Format("Not!"));
                }
            },
                       "Effectively..."));
        }
コード例 #16
0
        public static IChainableFluentAssertion <IFluentAssertion <Movie> > IsAFGreatMovie(this IFluentAssertion <Movie> fluentAssertion)
        {
            var assertionRunner   = fluentAssertion as IFluentAssertionRunner <Movie>;
            var runnableAssertion = fluentAssertion as IRunnableAssertion <Movie>;

            return(assertionRunner.ExecuteAssertion(
                       () =>
            {
                if (!runnableAssertion.Value.Name.Contains("Eternal sunshine of the spotless mind"))
                {
                    throw new FluentAssertionException(string.Format("[{0}]Is not a great movie", runnableAssertion.Value.Name.ToStringProperlyFormated()));
                }
            },
                       string.Format("[{0}]Is a great movie!", runnableAssertion.Value.Name.ToStringProperlyFormated())));
        }
コード例 #17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NumberFluentAssertion{N}" /> class.
 /// </summary>
 /// <param name="fluentAssertion">The fluent assertion.</param>
 public NumberFluentAssertion(IFluentAssertion <N> fluentAssertion)
 {
     this.fluentAssertion       = fluentAssertion;
     this.fluentAssertionRunner = new FluentAssertionRunner <N>(this);
 }
コード例 #18
0
        /// <summary>
        /// Checks that the enumerable is empty.
        /// </summary>
        /// <param name="fluentAssertion">The fluent assertion to be extended.</param>
        /// <returns>
        /// A chainable assertion.
        /// </returns>
        /// <exception cref="FluentAssertionException">The enumerable is not empty.</exception>
        public static IChainableFluentAssertion <IFluentAssertion <IEnumerable> > IsEmpty(this IFluentAssertion <IEnumerable> fluentAssertion)
        {
            var assertionRunner   = fluentAssertion as IFluentAssertionRunner <IEnumerable>;
            var runnableAssertion = fluentAssertion as IRunnableAssertion <IEnumerable>;

            return(assertionRunner.ExecuteAssertion(
                       () =>
            {
                if (runnableAssertion.Value.Cast <object>().Any())
                {
                    throw new FluentAssertionException(string.Format("\nThe actual enumerable is not empty. Contains:\n\t[{0}]", runnableAssertion.Value.ToEnumeratedString()));
                }
            },
                       string.Format("\nThe actual enumerable is empty, which is unexpected.")));
        }
コード例 #19
0
        /// <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));
        }
コード例 #20
0
        /// <summary>
        /// Checks that the actual value is not 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 equal to the expected value.</exception>
        public static IChainableFluentAssertion <IFluentAssertion <int> > IsNotEqualTo(this IFluentAssertion <int> fluentAssertion, object expected)
        {
            var numberAssertionStrategy = new NumberFluentAssertion <int>(fluentAssertion);

            return(numberAssertionStrategy.IsNotEqualTo(expected));
        }
コード例 #21
0
        /// <summary>
        /// Checks that the actual value is strictly positive.
        /// </summary>
        /// <param name="fluentAssertion">The fluent assertion to be extended.</param>
        /// <returns>
        /// A chainable assertion.
        /// </returns>
        /// <exception cref="FluentAssertionException">The value is not strictly positive.</exception>
        public static IChainableFluentAssertion <IFluentAssertion <int> > IsPositive(this IFluentAssertion <int> fluentAssertion)
        {
            var numberAssertionStrategy = new NumberFluentAssertion <int>(fluentAssertion);

            return(numberAssertionStrategy.IsPositive());
        }
コード例 #22
0
        /// <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));
        }
コード例 #23
0
        /// <summary>
        /// Checks that the actual value is not 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 equal to the expected value.</exception>
        public static IChainableFluentAssertion <IFluentAssertion <IEnumerable> > IsNotEqualTo(this IFluentAssertion <IEnumerable> fluentAssertion, object expected)
        {
            var assertionRunner   = fluentAssertion as IFluentAssertionRunner <IEnumerable>;
            var runnableAssertion = fluentAssertion as IRunnableAssertion <IEnumerable>;

            var expectedEnumerable = expected as IEnumerable;

            return(assertionRunner.ExecuteAssertion(
                       () =>
            {
                EqualityHelper.IsNotEqualTo(runnableAssertion.Value, expected);
            },
                       EqualityHelper.BuildErrorMessage(runnableAssertion.Value, expectedEnumerable, false)));
        }
コード例 #24
0
        /// <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())));
        }
コード例 #25
0
        /// <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 numberAssertionStrategy = new NumberFluentAssertion <int>(fluentAssertion);

            return(numberAssertionStrategy.IsInstanceOf <T>());
        }
コード例 #26
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ChainableNullableFluentAssertionOrNumberFluentAssertion{N}" /> class.
 /// </summary>
 /// <param name="previousFluentAssertion">The previous fluent assertion.</param>
 public ChainableNullableFluentAssertionOrNumberFluentAssertion(IFluentAssertion <N?> previousFluentAssertion)
 {
     this.previousFluentAssertion = previousFluentAssertion;
 }
コード例 #27
0
        /// <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)));
        }
コード例 #28
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))));
        }
コード例 #29
0
        /// <summary>
        /// Checks that the actual duration is greater (strictly) than a comparand.
        /// </summary>
        /// <param name="fluentAssertion">The fluent assertion to be extended.</param>
        /// <param name="providedDuration">The duration to compare to.</param>
        /// <param name="unit">The unit in which the duration is expressed.</param>
        /// <returns>A chainable assertion.</returns>
        /// <exception cref="FluentAssertionException">The actual value is not greater than the provided comparand.</exception>
        public static IChainableFluentAssertion <IFluentAssertion <TimeSpan> > IsGreaterThan(this IFluentAssertion <TimeSpan> fluentAssertion, double providedDuration, TimeUnit unit)
        {
            var assertionRunner   = fluentAssertion as IFluentAssertionRunner <TimeSpan>;
            var runnableAssertion = fluentAssertion as IRunnableAssertion <TimeSpan>;

            TimeSpan comparand = TimeHelper.ToTimeSpan(providedDuration, unit);

            return(assertionRunner.ExecuteAssertion(
                       () =>
            {
                if (runnableAssertion.Value <= comparand)
                {
                    throw new FluentAssertionException(string.Format("\nThe actual value of:\n\t[{0} {2}]\nis not greater than:\n\t[{1} {2}]\nas expected.", TimeHelper.Convert(runnableAssertion.Value, unit), TimeHelper.Convert(comparand, unit), unit));
                }
            },
                       string.Format("\nThe actual value of:\n\t[{0} {2}]\nis greater than:\n\t[{1} {2}]\nwhich is unexpected.", TimeHelper.Convert(runnableAssertion.Value, unit), TimeHelper.Convert(comparand, unit), unit)));
        }
コード例 #30
0
        /// <summary>
        /// Checks that the actual value is equal to zero.
        /// </summary>
        /// <param name="fluentAssertion">The fluent assertion to be extended.</param>
        /// <returns>
        /// A chainable assertion.
        /// </returns>
        /// <exception cref="FluentAssertionException">The value is not equal to zero.</exception>
        public static IChainableFluentAssertion <IFluentAssertion <ushort> > IsZero(this IFluentAssertion <ushort> fluentAssertion)
        {
            var numberAssertionStrategy = new NumberFluentAssertion <ushort>(fluentAssertion);

            return(numberAssertionStrategy.IsZero());
        }