Пример #1
0
        /// <summary>
        /// Builds a chainable check with a sub item.
        /// </summary>
        /// <param name="check">original check to link to</param>
        /// <param name="item">sub itme that can be check with wich</param>
        /// <param name="label">label for the sub item</param>
        /// <typeparam name="TU">type of the sut</typeparam>
        /// <typeparam name="T">type of the sub item</typeparam>
        /// <returns>A chainable link supporting Which</returns>
        public static ICheckLinkWhich <ICheck <TU>, ICheck <T> > BuildCheckLinkWhich <TU, T>(ICheck <TU> check, T item, string label)
        {
            var chk = new FluentCheck <T>(item);

            chk.Checker.SetSutLabel(label);
            return(new CheckLinkWhich <ICheck <TU>, ICheck <T> >(check, chk));
        }
Пример #2
0
        /// <summary>
        /// Returns a <see cref="ICheck{T}" /> instance that will provide check methods to be executed on a given value.
        /// </summary>
        /// <typeparam name="T">Type of the value to be tested.</typeparam>
        /// <param name="sut">The value to be tested.</param>
        /// <returns>
        /// A <see cref="ICheck{T}" /> instance to use in order to check things on the given value.
        /// </returns>
        /// <remarks>
        /// Every method of the returned <see cref="ICheck{T}" /> instance will throw a <see cref="FluentCheckException" /> when failing.
        /// </remarks>
        public ICheck <T> That <T>(T sut)
        {
            var result = new FluentCheck <T>(sut);

            result.CustomMessage = this.message;
            return(result);
        }
Пример #3
0
        /// <summary>
        /// Builds a chainable check with a sub item.
        /// </summary>
        /// <param name="check">original check to link to</param>
        /// <param name="item">sub item that can be check with which</param>
        /// <param name="label">label for the sub item</param>
        /// <typeparam name="TU">type of the sut</typeparam>
        /// <typeparam name="T">type of the sub item</typeparam>
        /// <returns>A chainable link supporting Which</returns>
        public static ICheckLinkWhich <ICheck <TU>, ICheck <T> > BuildCheckLinkWhich <TU, T>(ICheck <TU> check, T item, EntityNamingLogic label)
        {
            var chk = new FluentCheck <T>(item);

            chk.SutName.Merge(label);
            return(new CheckLinkWhich <ICheck <TU>, ICheck <T> >(check, chk));
        }
Пример #4
0
        FailOnIllegalNegation()
        {
            var fluentChecker = new FluentCheck <Point>(null);
            var checker       = fluentChecker.Checker;

            Check.ThatCode(() =>
                           checker.BeginCheck().CantBeNegated("this").DefineExpectedValue(12, "Dummy").EndCheck())
            .Throws <InvalidOperationException>();
        }
Пример #5
0
        CascadeErrorOnSubProperty()
        {
            var fluentChecker = new FluentCheck <Point>(null);
            var checker       = fluentChecker.Checker;

            Check.ThatCode(() =>
                           checker.BeginCheck().FailIfNull().CheckSutAttributes(point => point.x, "x coordinate")
                           .FailWhen(i => i > 0, "Should be positive").EndCheck()).IsAFailingCheckWithMessage("", "The checked value's x coordinate is null.");
        }
Пример #6
0
        BeEasyForBasicChecks()
        {
            var fluentChecker = new FluentCheck <string>("test");
            var checker       = fluentChecker.Checker;

            checker.BeginCheck(true)
            .Expecting("other")
            .FailsIf((x) => x.Equals("test"), "The {0} should be equal to the {1}.")
            .EndCheck();
        }
Пример #7
0
        /// <summary>
        /// Initiates a check logic chain.
        /// </summary>
        /// <typeparam name="T">Type of sut</typeparam>
        /// <typeparam name="TU">Target type</typeparam>
        /// <param name="check">The fluent check instance to work on.</param>
        /// <param name="converter">Conversion method </param>
        /// <returns>An <see cref="ICheckLogic{T}"/>instance.</returns>
        public static ICheckLogic <TU> BeginCheckAs <T, TU>(ICheck <T> check, Func <T, TU> converter) where TU : class
        {
            var         toConvert = ExtractChecker(check).Value;
            ICheck <TU> altCheck  = new FluentCheck <TU>(toConvert == null ? null : converter(toConvert));

            if (ExtractChecker(check).Negated)
            {
                altCheck = altCheck.Not;
            }
            return(ExtractChecker(altCheck).BeginCheck());
        }
Пример #8
0
        BeEasyForBasicChecks()
        {
            var fluentChecker = new FluentCheck <string>("test");
            var checker       = ExtensibilityHelper.ExtractChecker(fluentChecker.Not);

            checker.BeginCheck()
            .DefineExpectedValue("other")
            .FailWhen((x) => x.Equals("test"), "The {0} should be equal to the {1}.")
            .OnNegate("No need")
            .EndCheck();
        }
Пример #9
0
        /// <summary>
        /// Builds a chainable check with a sub item.
        /// </summary>
        /// <typeparam name="TU">type of the sut</typeparam>
        /// <typeparam name="T">type of the sub item</typeparam>
        /// <param name="check">original check to link to</param>
        /// <param name="item">sub item that can be check with which</param>
        /// <param name="label">label for the sub item</param>
        /// <param name="hasItem">set to false is no item is available</param>
        /// <returns>A chainable link supporting Which</returns>
        public static ICheckLinkWhich <ICheck <TU>, ICheck <T> > BuildCheckLinkWhich <TU, T>(ICheck <TU> check, T item, string label, bool hasItem = true)
        {
            FluentCheck <T> chk = null;

            if (hasItem)
            {
                chk = new FluentCheck <T>(item);
                if (!string.IsNullOrEmpty(label))
                {
                    chk.Checker.SetSutLabel(label);
                }
            }

            return(new CheckLinkWhich <ICheck <TU>, ICheck <T> >(check, chk));
        }