예제 #1
0
        public IEnumerable <Test> test_group()
        {
            var data =
                DictionaryTestData.Build()
                .Add("Value", new MyClass())
                .MakeReadOnly();

            yield return(test_increment().ToTestGroup("group", data));
        }
예제 #2
0
        /// <summary>
        /// Equivalent to <see cref="TestExtension.TestSatisfy{X}(X, Expression{Func{X, bool}})"/>.
        /// </summary>
        /// <typeparam name="X"></typeparam>
        /// <param name="value"></param>
        /// <param name="predicate"></param>
        /// <returns></returns>
        public static Test Satisfy <X>(X value, Expression <Func <X, bool> > predicate)
        {
            var isPassed = predicate.Compile().Invoke(value);
            var data     =
                DictionaryTestData.Build()
                .Add("Value", value)
                .Add("Predicate", predicate)
                .MakeReadOnly();

            return(FromResult(nameof(Satisfy), isPassed, data));
        }
예제 #3
0
        /// <summary>
        /// Tests that two values are equal, using <paramref name="comparer"/>.
        /// <para lang="ja">
        /// <paramref name="comparer"/> で比較して、2つの値が等しいことを検査する。
        /// </para>
        /// </summary>
        /// <typeparam name="X"></typeparam>
        /// <param name="expected"></param>
        /// <param name="actual"></param>
        /// <param name="comparer"></param>
        /// <returns></returns>
        public static Test Equal <X>(X expected, X actual, IEqualityComparer comparer)
        {
            var isPassed = comparer.Equals(actual, expected);
            var data     =
                DictionaryTestData.Build()
                .Add("Expected", expected)
                .Add("Actual", actual)
                .MakeReadOnly();

            return(FromResult(nameof(Equal), isPassed, data));
        }
 /// <summary>
 /// Executes a parameterized test.
 /// <para lang="ja">
 /// パラメーター化されたテストを実行する。
 /// </para>
 /// </summary>
 /// <param name="run"></param>
 /// <returns></returns>
 public IEnumerable <Test> Run(Func <TParameter, IEnumerable <Test> > run)
 {
     foreach (var parameter in Parameters)
     {
         var data =
             DictionaryTestData.Build()
             .Add("Parameter", parameter)
             .MakeReadOnly();
         yield return(run(parameter).ToTestGroup(nameof(Case), data));
     }
 }
예제 #5
0
        public static Test IsNot <X>(this X actual, X unexpected)
        {
            var name     = nameof(IsNot);
            var isPassed = !Equals(actual, unexpected);
            var data     =
                DictionaryTestData.Build()
                .Add("Value", actual)
                .MakeReadOnly();

            return(Test.FromResult(name, isPassed, data));
        }
예제 #6
0
        /// <summary>
        /// Tests that an action throws an exception of type <typeparamref name="E"/>.
        /// <para lang="ja">
        /// アクションが型 <typeparamref name="E"/> の例外を送出することを検査する。
        /// </para>
        /// </summary>
        /// <typeparam name="E"></typeparam>
        /// <param name="f"></param>
        /// <returns></returns>
        public static Test Catch <E>(Action f)
            where E : Exception
        {
            var exceptionOrNull = default(Exception);

            try
            {
                f();
            }
            catch (E exception)
            {
                exceptionOrNull = exception;
            }

            var data =
                DictionaryTestData.Build()
                .Add("Type", typeof(E))
                .Add("ExceptionOrNull", exceptionOrNull)
                .MakeReadOnly();

            return(FromResult(nameof(Catch), !ReferenceEquals(exceptionOrNull, null), data));
        }