Example #1
0
        private TestValueResult InvokeMethood(object testObject, MethodInfo method, int currentIndex, BreakItOptions options, object[] list, TestValue testValue)
        {
            list[currentIndex] = testValue.Value;
            Exception invokeException = null;
            object    returnValue     = null;

            try
            {
                options?.SetUp?.Invoke(list);
                returnValue = method.Invoke(testObject, list);
            }
            catch (Exception ex)
            {
                invokeException = ex.InnerException;
            }

            var result = new TestValueResult
            {
                MemberPath   = testValue.MemberPath,
                Exception    = invokeException,
                TestingValue = testValue,
                IsSuccess    = options?.Validation?.Invoke(testValue, returnValue, invokeException),
                ReturnValue  = returnValue
            };

            _logger?.Log(result);
            return(result);
        }
Example #2
0
        /// <summary>
        /// Execute multiple test against a method by invoking it with different test valu
        /// </summary>
        /// <param name="testObject">The base object to test</param>
        /// <param name="method">The method to invoke.</param>
        /// <param name="defaultValues">A list of default values/argument to the method. Important that they match the invoked methods parameter list.</param>
        /// <param name="options">Optional options.</param>
        /// <returns>A list with the result of all test values.</returns>
        public IList <TestValueResult> Execute(object testObject, MethodInfo method, IList <object> defaultValues, BreakItOptions options = null)
        {
            var paramenters = method.GetParameters();

            if (defaultValues.Count != paramenters.Length)
            {
                throw new Exception("Each parameter must have a default value");
            }

            var createdDefaultValues = paramenters.Select(
                (parameter, index) => new DefaultValue(parameter.Name, defaultValues[index])).ToList();
            var defaultObjectValues = BuildDefaultObject(method.GetParameters(), createdDefaultValues);

            var results = new List <TestValueResult>();

            for (int i = 0; i < defaultObjectValues.Count; i++)
            {
                results.AddRange(TestCombinations(testObject, method, defaultObjectValues, i, options));
            }

            return(results);
        }
Example #3
0
        private IEnumerable <TestValueResult> TestCombinations(object testObject, MethodInfo method, IList <DefaultValueParameter> values, int currentIndex, BreakItOptions options)
        {
            var results      = new List <TestValueResult>();
            var type         = values[currentIndex].ParameterInfo.ParameterType;
            var combinations = _combinationFactory.GetTestValues(values[currentIndex].ParameterInfo.Name, type, values[currentIndex].DefaultValue, options?.ExcludeList);
            var list         = new object[values.Count];

            values.Select(v => v.DefaultValue).ToList().CopyTo(list);
            foreach (var combination in combinations)
            {
                results.Add(InvokeMethood(testObject, method, currentIndex, options, list, combination));
            }

            return(results);
        }
Example #4
0
 /// <summary>
 /// Execute multiple test against a method by invoking it with different test values.
 /// </summary>
 /// <param name="testObject">The base object to test</param>
 /// <param name="methodName">Name of the method to test.</param>
 /// <param name="defaultValues">A list of default values/argument to the method. Important that they match the invoked methods parameter list.</param>
 /// <param name="options">Optional options.</param>
 /// <returns>A list with the result of all test values.</returns>
 public IList <TestValueResult> Execute(object testObject, string methodName, IList <object> defaultValues, BreakItOptions options = null)
 {
     return(Execute(testObject, testObject.GetType().GetMethod(methodName), defaultValues, options));
 }