Ejemplo n.º 1
0
        /// <summary>
        /// Checks that the execution time is below a specified threshold.
        /// </summary>
        /// <typeparam name="T">Type of the checked type.</typeparam>
        /// <param name="check">The fluent check to be extended.
        /// </param>
        /// <param name="threshold">
        /// The threshold.
        /// </param>
        /// <param name="timeUnit">
        /// The time unit of the given threshold.
        /// </param>
        /// <returns>
        /// A check link.
        /// </returns>
        /// <exception cref="FluentCheckException">
        /// Execution was strictly above limit.
        /// </exception>
        public static ICheckLink <ICodeCheck <T> > LastsLessThan <T>(
            this ICodeCheck <T> check, double threshold, TimeUnit timeUnit) where T : RunTrace
        {
            var checker           = ExtensibilityHelper.ExtractCodeChecker(check);
            var comparand         = new Duration(checker.Value.ExecutionTime, timeUnit);
            var durationThreshold = new Duration(threshold, timeUnit);

            checker.ExecuteCheck(
                () =>
            {
                if (comparand > durationThreshold)
                {
                    var message =
                        checker.BuildMessage(
                            "The checked code took too much time to execute.")
                        .For(LabelForExecTime)
                        .Expected(durationThreshold)
                        .Comparison(LabelForLessThan)
                        .ToString();

                    throw new FluentCheckException(message);
                }
            },
                checker.BuildMessage("The checked code took too little time to execute.").For(LabelForExecTime).Expected(durationThreshold).Comparison(LabelForMoreThan).ToString());

            return(new CheckLink <ICodeCheck <T> >(check));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Checks that the CPU time is below a specified threshold.
        /// </summary>
        /// <typeparam name="T">Type of the checked type.</typeparam>
        /// <param name="check">The fluent check to be extended.
        /// </param>
        /// <param name="threshold">
        /// The threshold.
        /// </param>
        /// <param name="timeUnit">
        /// The time unit of the given threshold.
        /// </param>
        /// <returns>
        /// A check link.
        /// </returns>
        /// <exception cref="FluentCheckException">
        /// Execution was strictly above limit.
        /// </exception>
        public static ICheckLink <ICodeCheck <T> > ConsumesLessThan <T>(
            this ICodeCheck <T> check, double threshold, TimeUnit timeUnit) where T : RunTrace
        {
            var checker           = ExtensibilityHelper.ExtractCodeChecker(check);
            var comparand         = new Duration(checker.Value.TotalProcessorTime, timeUnit);
            var durationThreshold = new Duration(threshold, timeUnit);

            checker.ExecuteCheck(
                () =>
            {
                if (comparand > durationThreshold)
                {
                    var message =
                        FluentMessage.BuildMessage(
                            "The checked code consumed too much CPU time.")
                        .For("cpu time")
                        .On(comparand)
                        .And.Expected(durationThreshold)
                        .Comparison("less than")
                        .ToString();

                    throw new FluentCheckException(message);
                }
            },
                FluentMessage.BuildMessage("The checked code took too little cpu time to execute.").For("cpu time").On(comparand).And.Expected(durationThreshold).Comparison("more than").ToString());

            return(new CheckLink <ICodeCheck <T> >(check));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Builds a check
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="TV"></typeparam>
        /// <param name="check"></param>
        /// <param name="extractor"></param>
        /// <returns></returns>
        public static ICheck <TV> BuildCheck <T, TV>(ICodeCheck <T> check, Func <T, TV> extractor) where T : RunTrace
        {
            var extract = (FluentSut <T>)check;
            var value   = extractor(ExtractCodeChecker(check).Value);

            return(!string.IsNullOrEmpty(extract.CustomMessage) ? Check.WithCustomMessage(extract.CustomMessage).That(value) : Check.That(value));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Checks that the code did throw an exception of a specified type.
        /// </summary>
        /// <typeparam name="T">Expected exception type.</typeparam>
        /// <param name="check">The fluent check to be extended.
        /// </param>
        /// <returns>
        /// A check link.
        /// </returns>
        /// <exception cref="FluentCheckException">The code did not raised an exception of the specified type, or did not raised an exception at all.</exception>
        public static ILambdaExceptionCheck <T> Throws <T>(this ICodeCheck <RunTrace> check)
            where T : Exception
        {
            var exc = CheckExceptionType(check, typeof(T));

            return(new LambdaExceptionCheck <T>((T)exc, ((INegated)check).Negated));
        }
Ejemplo n.º 5
0
        /// <summary>
        ///     Verify that the code results in a failed NFluent check with a specified message.
        /// </summary>
        /// <param name="check"></param>
        /// <param name="lines"></param>
        /// <returns>A link check</returns>
        public static ICheckLink <ICodeCheck <RunTrace> > IsAFailingCheckWithMessage(this ICodeCheck <RunTrace> check,
                                                                                     params string[] lines)
        {
            ExtensibilityHelper.BeginCheck(check)
            .SetSutName("fluent check")
            .CheckSutAttributes((sut) => sut.RaisedException, "raised exception")
            .FailIfNull("The check succeeded whereas it should have failed.")
            .FailWhen((sut) => !ExceptionHelper.IsFailedException(sut),
                      $"The exception raised is not of the expected type.")
            .CheckSutAttributes((sut) => sut.Message.SplitAsLines(), "error message")
            .Analyze((messageLines, test) =>
            {
                var expectedLines = (lines.Length == 1) ? lines[0].SplitAsLines() : lines;
                for (var i = 0; i < expectedLines.Count; i++)
                {
                    if (expectedLines[i] == "*")
                    {
                        //any line
                        continue;
                    }

                    if (messageLines.Count <= i)
                    {
                        test.Fail($"Lines are missing in the error message starting at #{i}");
                        break;
                    }

                    if (expectedLines[i].StartsWith("#"))
                    {
                        if (!Regex.IsMatch(messageLines[i], expectedLines[i].Substring(1)))
                        {
                            test.Fail($"Line {i} is different from what is expected" + Environment.NewLine +
                                      "Act:" + messageLines[i].DoubleCurlyBraces() + Environment.NewLine +
                                      "Exp (regex):" + expectedLines[i].DoubleCurlyBraces()
                                      );
                            break;
                        }
                    }
                    else if (messageLines[i] != expectedLines[i])
                    {
                        test.Fail($"Line {i} is different from what is expected" + Environment.NewLine +
                                  "Act:" + messageLines[i].DoubleCurlyBraces() + Environment.NewLine +
                                  "Exp:" + expectedLines[i].DoubleCurlyBraces());
                        break;
                    }
                }

                if (messageLines.Count > expectedLines.Count)
                {
                    test.Fail($"Too many lines in the error message starting at #{expectedLines.Count}");
                }
            }).
            DefineExpectedValue(lines).
            EndCheck();
            return(ExtensibilityHelper.BuildCheckLink(check));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Checks that the code did throw an exception of a specified type.
        /// </summary>
        /// <param name="check">The fluent check to be extended.</param>
        /// <param name="exceptionType">Expected exception type.</param>
        /// <returns>A check link.</returns>
        public static ILambdaExceptionCheck <Exception> ThrowsType(this ICodeCheck <RunTrace> check, Type exceptionType)
        {
            CheckExceptionType(check, exceptionType);

            var checker = ExtensibilityHelper.ExtractCodeChecker(check);

            return(checker.Negated
                ? (ILambdaExceptionCheck <Exception>) new NegatedLambdaExceptionCheck <Exception>()
                : new LambdaExceptionCheck <Exception>(checker.Value.RaisedException));
        }
Ejemplo n.º 7
0
 private static void CheckExceptionType(ICodeCheck <RunTrace> check, Type expecting)
 {
     ExtensibilityHelper.BeginCheck(check).SutNameIs("code")
     .GetSutProperty((sut) => sut.RaisedException, "raised exception")
     .ExpectingType(expecting, expectedLabel: "", negatedLabel: "should not be")
     .FailsIfNull("The checked code did not raise an exception, whereas it must.")
     .FailsIf((sut) => !expecting.IsInstanceOfType(sut),
              "The {0} is of a different type than expected.")
     .Negates("The {0} raised an exception of the forbidden type.")
     .EndCheck();
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Checks that the code did throw an exception of a specified type.
        /// </summary>
        /// <typeparam name="T">Expected exception type.</typeparam>
        /// <param name="check">The fluent check to be extended.
        /// </param>
        /// <returns>
        /// A check link.
        /// </returns>
        /// <exception cref="FluentCheckException">The code did not raised an exception of the specified type, or did not raised an exception at all.</exception>
        public static ILambdaExceptionCheck <T> Throws <T>(this ICodeCheck <RunTrace> check)
            where T : Exception
        {
            CheckExceptionType(check, typeof(T));

            var checker = ExtensibilityHelper.ExtractCodeChecker(check);

            return(checker.Negated
                ? (ILambdaExceptionCheck <T>) new NegatedLambdaExceptionCheck <T>()
                : new LambdaExceptionCheck <T>((T)checker.Value.RaisedException));
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Check that the code does not throw an exception.
 /// </summary>
 /// <param name="check">The fluent check to be extended.
 /// </param>
 /// <typeparam name="T">Inferred type of the code.</typeparam>
 /// <returns>
 /// A check link.
 /// </returns>
 /// <exception cref="FluentCheckException">The code raised an exception.</exception>
 public static ICheckLink <ICodeCheck <T> > DoesNotThrow <T>(this ICodeCheck <T> check)
     where T : RunTrace
 {
     ExtensibilityHelper.BeginCheck(check).
     SetSutName("code").
     CheckSutAttributes(sut => sut.RaisedException, "raised exception").
     FailWhen(sut => sut != null, "The checked code raised an exception, whereas it must not.").
     OnNegate("The checked code did not raise an exception, whereas it must.", MessageOption.NoCheckedBlock).
     EndCheck();
     return(ExtensibilityHelper.BuildCheckLink(check));
 }
Ejemplo n.º 10
0
 /// <summary>
 ///     Verify that the code results in a failed NFluent check with a specified message.
 /// </summary>
 /// <param name="check"></param>
 /// <returns>A link check</returns>
 public static ICheckLink <ICodeCheck <RunTrace> > IsAFaillingCheck(this ICodeCheck <RunTrace> check)
 {
     ExtensibilityHelper.BeginCheck(check)
     .GetSutProperty((sut) => sut.RaisedException, "raised exception")
     .SutNameIs("fluent check")
     .FailsIfNull()
     .FailsIf((sut) => !ExceptionHelper.IsFailedException(sut),
              "The exception raised is not of the expected type").
     ExpectingType(ExceptionHelper.BuildException(string.Empty).GetType(), "an instance of:", "an instance of a different type").
     EndCheck();
     return(ExtensibilityHelper.BuildCheckLink(check));
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Checks that the code did throw an exception of a specified type.
        /// </summary>
        /// <param name="check">
        /// The fluent check to be extended.
        /// </param>
        /// <returns>
        /// A check link.
        /// </returns>
        /// <exception cref="FluentCheckException">
        /// The code did not raised an exception of the specified type, or did not raised an exception at all.
        /// </exception>
        public static ILambdaExceptionCheck <Exception> ThrowsAny(this ICodeCheck <RunTrace> check)
        {
            ExtensibilityHelper.BeginCheck(check)
            .OnNegate("The checked code raised an exception, whereas it must not.")
            .SetSutName("code")
            .CheckSutAttributes((sut) => sut.RaisedException, "raised exception")
            .FailIfNull("The checked code did not raise an exception, whereas it must.")
            .EndCheck();
            var checker = ExtensibilityHelper.ExtractCodeChecker(check);

            return(new LambdaExceptionCheck <Exception>(checker.Value.RaisedException, ((INegated)check).Negated));
        }
Ejemplo n.º 12
0
 /// <summary>
 ///     Verify that the code results in a failed NFluent check with a specified message.
 /// </summary>
 /// <param name="check"></param>
 /// <returns>A link check</returns>
 public static ICheckLink <ICodeCheck <RunTrace> > IsAFaillingCheck(this ICodeCheck <RunTrace> check)
 {
     ExtensibilityHelper.BeginCheck(check)
     .SetSutName("fluent check")
     .CheckSutAttributes((sut) => sut.RaisedException, "raised exception")
     .FailIfNull("The fluent check did not raise an exception, where as it must.")
     .FailWhen((sut) => !ExceptionHelper.IsFailedException(sut),
               "The exception raised is not of the expected type").
     DefineExpectedType(ExceptionHelper.BuildException(string.Empty).GetType()).
     EndCheck();
     return(ExtensibilityHelper.BuildCheckLink(check));
 }
Ejemplo n.º 13
0
        /// <summary>
        /// Checks that the execution time is below a specified threshold.
        /// </summary>
        /// <typeparam name="T">Type of the checked type.</typeparam>
        /// <param name="check">The fluent check to be extended.
        /// </param>
        /// <param name="threshold">
        /// The threshold.
        /// </param>
        /// <param name="timeUnit">
        /// The time unit of the given threshold.
        /// </param>
        /// <returns>
        /// A check link.
        /// </returns>
        /// <exception cref="FluentCheckException">
        /// Execution was strictly above limit.
        /// </exception>
        public static ICheckLink <ICodeCheck <T> > LastsLessThan <T>(
            this ICodeCheck <T> check,
            double threshold,
            TimeUnit timeUnit)
            where T : RunTrace
        {
            var durationThreshold = new Duration(threshold, timeUnit);

            ExtensibilityHelper.BeginCheck(check).FailsIf((sut) =>
                                                          new Duration(sut.ExecutionTime, timeUnit) > durationThreshold, "The checked code took too much time to execute.").
            Expecting(durationThreshold, "less than", "more than").
            SutNameIs("execution time").
            Negates("The checked code took too little time to execute.").
            EndCheck();

            return(ExtensibilityHelper.BuildCheckLink(check));
        }
        public static ICheckLink <ICodeCheck <T> > LastsLessThan <T>(
            this ICodeCheck <T> check,
            double threshold,
            TimeUnit timeUnit)
            where T : RunTrace
        {
            var durationThreshold = new Duration(threshold, timeUnit);

            ExtensibilityHelper.BeginCheck(check).
            SetSutName(Stryker.ActiveMutationHelper.ActiveMutation == 7?"":"code").
            CheckSutAttributes(sut => new Duration(sut.ExecutionTime, timeUnit), Stryker.ActiveMutationHelper.ActiveMutation == 8?"":"execution time").
            FailWhen((sut) => Stryker.ActiveMutationHelper.ActiveMutation == 10?sut >= durationThreshold:Stryker.ActiveMutationHelper.ActiveMutation == 9?sut <durationThreshold : sut> durationThreshold, Stryker.ActiveMutationHelper.ActiveMutation == 11?"":"The {checked} was too high.").
            DefineExpectedValue(durationThreshold, Stryker.ActiveMutationHelper.ActiveMutation == 12?"":"less than", Stryker.ActiveMutationHelper.ActiveMutation == 13?"":"more than").
            OnNegate(Stryker.ActiveMutationHelper.ActiveMutation == 14?"":"The {checked} was too low.").
            EndCheck();

            return(ExtensibilityHelper.BuildCheckLink(check));
        }
Ejemplo n.º 15
0
        public static ICheckLink <ICodeCheck <T> > LastsLessThan <T>(
            this ICodeCheck <T> check,
            double threshold,
            TimeUnit timeUnit)
            where T : RunTrace
        {
            var durationThreshold = new Duration(threshold, timeUnit);

            ExtensibilityHelper.BeginCheck(check).
            SetSutName((StrykerNamespace.MutantControl.IsActive(7)?"":"code")).
            CheckSutAttributes(sut => new Duration(sut.ExecutionTime, timeUnit), (StrykerNamespace.MutantControl.IsActive(8)?"":"execution time")).
            FailWhen((sut) => (StrykerNamespace.MutantControl.IsActive(10)?sut >= durationThreshold:(StrykerNamespace.MutantControl.IsActive(9)?sut <durationThreshold : sut> durationThreshold)), (StrykerNamespace.MutantControl.IsActive(11)?"":"The {checked} was too high.")).
            DefineExpectedValue(durationThreshold, (StrykerNamespace.MutantControl.IsActive(12)?"":"less than"), (StrykerNamespace.MutantControl.IsActive(13)?"":"more than")).
            OnNegate((StrykerNamespace.MutantControl.IsActive(14)?"":"The {checked} was too low.")).
            EndCheck();

            return(ExtensibilityHelper.BuildCheckLink(check));
        }
Ejemplo n.º 16
0
        public static ICheckLink <ICodeCheck <T> > LastsLessThan <T>(
            this ICodeCheck <T> check,
            double threshold,
            TimeUnit timeUnit)
            where T : RunTrace
        {
            var durationThreshold = new Duration(threshold, timeUnit);

            ExtensibilityHelper.BeginCheck(check).
            SetSutName("code").
            CheckSutAttributes(sut => new Duration(sut.ExecutionTime, timeUnit), "execution time").
            FailWhen((sut) => sut > durationThreshold, "The {checked} was too high.").
            DefineExpectedValue(durationThreshold, "less than", "more than").
            OnNegate("The {checked} was too low.").
            EndCheck();

            return(ExtensibilityHelper.BuildCheckLink(check));
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Checks that the CPU time is below a specified threshold.
        /// </summary>
        /// <typeparam name="T">Type of the checked type.</typeparam>
        /// <param name="check">The fluent check to be extended.
        /// </param>
        /// <param name="threshold">
        /// The threshold.
        /// </param>
        /// <param name="timeUnit">
        /// The time unit of the given threshold.
        /// </param>
        /// <returns>
        /// A check link.
        /// </returns>
        /// <exception cref="FluentCheckException">
        /// Execution was strictly above limit.
        /// </exception>
        public static ICheckLink <ICodeCheck <T> > ConsumesLessThan <T>(
            this ICodeCheck <T> check,
            double threshold,
            TimeUnit timeUnit)
            where T : RunTrace
        {
            var durationThreshold = new Duration(threshold, timeUnit);

            ExtensibilityHelper.BeginCheck(check).
            GetSutProperty(sut => new Duration(sut.TotalProcessorTime, timeUnit), "").
            FailsIf((sut) =>
                    sut > durationThreshold, "The checked code consumed too much CPU time.").
            Expecting(durationThreshold, "less than", "more than").
            SutNameIs("cpu time").
            Negates("The checked code took too little cpu time to execute.").
            EndCheck();

            return(ExtensibilityHelper.BuildCheckLink(check));
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Checks that the code did throw an exception of a specified type.
        /// </summary>
        /// <param name="check">
        /// The fluent check to be extended.
        /// </param>
        /// <returns>
        /// A check link.
        /// </returns>
        /// <exception cref="FluentCheckException">
        /// The code did not raised an exception of the specified type, or did not raised an exception at all.
        /// </exception>
        public static ILambdaExceptionCheck <Exception> ThrowsAny(this ICodeCheck <RunTrace> check)
        {
            ExtensibilityHelper.BeginCheck(check)
            .Negates("The checked code raised an exception, whereas it must not.")
            .SutNameIs("code")
            .GetSutProperty((sut) => sut.RaisedException, "raised exception")
            .FailsIfNull("The checked code did not raise an exception, whereas it must.")
            .EndCheck();
            var checker = ExtensibilityHelper.ExtractCodeChecker(check);

            if (checker.Negated)
            {
                return(new NegatedLambdaExceptionCheck <Exception>());
            }
            else
            {
                return(new LambdaExceptionCheck <Exception>(checker.Value.RaisedException));
            }
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Checks that the code did throw an exception of a specified type.
        /// </summary>
        /// <param name="check">
        /// The fluent check to be extended.
        /// </param>
        /// <returns>
        /// A check link.
        /// </returns>
        /// <exception cref="FluentCheckException">
        /// The code did not raised an exception of the specified type, or did not raised an exception at all.
        /// </exception>
        public static ILambdaExceptionCheck <RunTrace> ThrowsAny(this ICodeCheck <RunTrace> check)
        {
            var checker = ExtensibilityHelper.ExtractCodeChecker(check);

            checker.ExecuteCheck(
                () =>
            {
                if (checker.Value.RaisedException == null)
                {
                    var message =
                        FluentMessage.BuildMessage(
                            "The {0} did not raise an exception, whereas it must.")
                        .For("code")
                        .ToString();
                    throw new FluentCheckException(message);
                }
            },
                FluentMessage.BuildMessage("The {0} raised an exception, whereas it must not.").For("code").On(checker.Value.RaisedException).Label("Raised Exception").ToString());
            return(new LambdaExceptionCheck <RunTrace>(checker.Value.RaisedException));
        }
Ejemplo n.º 20
0
        private static Exception CheckExceptionType(ICodeCheck <RunTrace> check, Type expecting)
        {
            Exception result = null;

            ExtensibilityHelper.BeginCheck(check).SetSutName("code")
            .CheckSutAttributes(sut =>
            {
                result = sut.RaisedException;
                return(result);
            }, "raised exception")
            .DefineExpectedType(expecting)
            .FailIfNull("The checked code did not raise an exception, whereas it must.")
            .FailWhen(sut => !expecting.IsInstanceOfType(sut),
                      "The {0} is of a different type than expected.")
            .OnNegate("The {0} raised an exception of the forbidden type.")
            .EndCheck();
            if (!expecting.IsInstanceOfType(result))
            {
                result = null;
            }
            return(result);
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Check that the code does not throw an exception.
        /// </summary>
        /// <param name="check">The fluent check to be extended.
        /// </param>
        /// <typeparam name="T">Inferred type of the code.</typeparam>
        /// <returns>
        /// A check link.
        /// </returns>
        /// <exception cref="FluentCheckException">The code raised an exception.</exception>
        public static ICheckLink <ICodeCheck <T> > DoesNotThrow <T>(this ICodeCheck <T> check) where T : RunTrace
        {
            var checker = ExtensibilityHelper.ExtractCodeChecker(check);

            checker.ExecuteCheck(
                () =>
            {
                if (checker.Value.RaisedException != null)
                {
                    var message =
                        FluentMessage.BuildMessage(
                            "The {0} raised an exception, whereas it must not.")
                        .For("code")
                        .On(checker.Value.RaisedException)
                        .Label("The raised exception:")
                        .ToString();

                    throw new FluentCheckException(message);
                }
            },
                FluentMessage.BuildMessage("The {0} did not raise an exception, whereas it must.").For("code").ToString());
            return(new CheckLink <ICodeCheck <T> >(check));
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Checks that the code did throw an exception of a specified type.
        /// </summary>
        /// <typeparam name="T">Expected exception type.</typeparam>
        /// <param name="check">The fluent check to be extended.
        /// </param>
        /// <returns>
        /// A check link.
        /// </returns>
        /// <exception cref="FluentCheckException">The code did not raised an exception of the specified type, or did not raised an exception at all.</exception>
        public static ILambdaExceptionCheck <RunTrace> Throws <T>(this ICodeCheck <RunTrace> check)
        {
            var checker = ExtensibilityHelper.ExtractCodeChecker(check);

            checker.ExecuteCheck(
                () =>
            {
                if (checker.Value.RaisedException == null)
                {
                    var message =
                        FluentMessage.BuildMessage(
                            "The {0} did not raise an exception, whereas it must.")
                        .For("code")
                        .Expected(typeof(T))
                        .Label("Expected exception type is:")
                        .ToString();
                    throw new FluentCheckException(message);
                }

                if (!(checker.Value.RaisedException is T))
                {
                    var message =
                        FluentMessage.BuildMessage(
                            "The {0} raised an exception of a different type than expected.")
                        .For("code")
                        .On(checker.Value.RaisedException)
                        .Label("Raised Exception")
                        .And.Expected(typeof(T))
                        .Label("Expected exception type is:")
                        .ToString();

                    throw new FluentCheckException(message);
                }
            },
                FluentMessage.BuildMessage("The {0} raised an exception of the forbidden type.").For("code").On(checker.Value.RaisedException).Label("Raised Exception").ToString());
            return(new LambdaExceptionCheck <RunTrace>(checker.Value.RaisedException));
        }
Ejemplo n.º 23
0
 /// <summary>
 /// Allows to perform checks on the result value.
 /// </summary>
 /// <typeparam name="T">Type of the code result. Should be inferred.</typeparam>
 /// <param name="check">The fluent check to be extended.</param>
 /// <returns>A check object for the result.</returns>
 public static ICheck <T> WhichResult <T>(this ICodeCheck <RunTraceResult <T> > check)
 {
     return(ExtensibilityHelper.BuildCheck(check, sut => sut.Result));
 }
Ejemplo n.º 24
0
 public static ICheckLink <ICodeCheck <RunTrace> > IsAFaillingCheckWithMessage(this ICodeCheck <RunTrace> check,
                                                                               params string[] lines)
 {
     return(check.IsAFailingCheckWithMessage(lines));
 }
Ejemplo n.º 25
0
 /// <summary>
 /// Extracts the code checker.
 /// </summary>
 /// <typeparam name="TU">The type of checked value.</typeparam>
 /// <param name="check">The check.</param>
 /// <returns>The checker to be used to check things on the value contained in the fluent check.</returns>
 public static IChecker <TU, ICodeCheck <TU> > ExtractCodeChecker <TU>(ICodeCheck <TU> check) where TU : RunTrace
 {
     // ok this is a crappy cast, but it's for the good cause here (i.e. a clean and virgin intellisense for users)
     return((check as ICheckForExtensibility <TU, ICodeCheck <TU> >).Checker);
 }
Ejemplo n.º 26
0
 public static ILambdaExceptionCheck <T> ThrowsFromRecursivity <T>(this ICodeCheck <RunTrace> codeCheck) where T : Exception
 {
     return(codeCheck.Throws <TargetInvocationException>().DueTo <T>());
 }
Ejemplo n.º 27
0
 /// <summary>
 /// Extracts the code checker.
 /// </summary>
 /// <typeparam name="TU">The type of checked value.</typeparam>
 /// <param name="check">The check.</param>
 /// <returns>The checker to be used to check things on the value contained in the fluent check.</returns>
 public static IChecker <TU, ICodeCheck <TU> > ExtractCodeChecker <TU>(ICodeCheck <TU> check) where TU : RunTrace
 {
     // ok this is a crappy cast, but it's for the good cause here (i.e. a clean and virgin intellisense for users)
     // ReSharper disable once SuspiciousTypeConversion.Global
     return(((ICheckForExtensibility <TU, ICodeCheck <TU> >)check).Checker);
 }
Ejemplo n.º 28
0
        /// <summary>
        /// Checks that the code did throw an exception of a specified type.
        /// </summary>
        /// <param name="check">The fluent check to be extended.</param>
        /// <param name="exceptionType">Expected exception type.</param>
        /// <returns>A check link.</returns>
        public static ILambdaExceptionCheck <Exception> ThrowsType(this ICodeCheck <RunTrace> check, Type exceptionType)
        {
            var exc = CheckExceptionType(check, exceptionType);

            return(new LambdaExceptionCheck <Exception>(exc, ((INegated)check).Negated));
        }
Ejemplo n.º 29
0
 /// <summary>
 /// Builds a chainable object.
 /// </summary>
 /// <typeparam name="T">Type of sut</typeparam>
 /// <param name="check">The fluent check instance to work on.</param>
 /// <returns>An <see cref="ICheckLink{T}"/> instance to add further checks.</returns>
 public static ICheckLink <ICodeCheck <T> > BuildCheckLink <T>(ICodeCheck <T> check) where T : RunTrace
 {
     return(ExtractCodeChecker(check).BuildChainingObject());
 }
Ejemplo n.º 30
0
 /// <summary>
 /// Initiates a check logic chain.
 /// </summary>
 /// <typeparam name="T">Type of sut</typeparam>
 /// <param name="check">The fluent check instance to work on.</param>
 /// <returns>An <see cref="ICheckLogic{T}"/>instance.</returns>
 public static ICheckLogic <T> BeginCheck <T>(ICodeCheck <T> check) where T : RunTrace
 {
     return(ExtractCodeChecker(check).BeginCheck());
 }