Example #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BreakIt"/> class.
 /// </summary>
 /// <param name="testValueLogger">Optional server to log each test value.</param>
 /// <param name="testValueFactory">Optional factory to create test value combinations.</param>
 public BreakIt(TestValueLogger testValueLogger = null, ITestValueFactory testValueFactory = null)
     : this()
 {
     _logger             = testValueLogger;
     _combinationFactory = testValueFactory ?? new TestValueFactory();
 }
 public void SetUp()
 {
     _testValueFactory = new TestValueFactory();
 }
Example #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BreakIt"/> class.
 /// </summary>
 public BreakIt()
 {
     _combinationFactory = new TestValueFactory();
 }
Example #4
0
        public TestValue[] GetTestValues(string memberPath, Type type, object defaultValue, IList <Func <string, Type, bool> > excludeList, ITestValueFactory combinationFactory)
        {
            if (!type.IsDictionary() || defaultValue == null)
            {
                return(null);
            }

            var combinations    = new List <TestValue>();
            var dictionaryClone = defaultValue.DeepClone() as IDictionary;

            foreach (var key in dictionaryClone.Keys)
            {
                var combination = combinationFactory.GetTestValues($"{memberPath}[{key}]", dictionaryClone[key].GetType(), dictionaryClone[key], excludeList);
                foreach (var combination1 in combination)
                {
                    var newDic = dictionaryClone.DeepClone();
                    newDic[key]        = combination1.Value;
                    combination1.Value = newDic;
                    combinations.Add(combination1);
                }
            }

            return(combinations.ToArray());
        }
Example #5
0
        public TestValue[] GetTestValues(string memberPath, Type type, object defaultValue, IList <Func <string, Type, bool> > excludeList, ITestValueFactory combinationFactory)
        {
            if (type.IsEnum)
            {
                return(GetEnumCombinations(memberPath, type, false));
            }

            var underlying = Nullable.GetUnderlyingType(type);

            if (underlying != null && underlying.IsEnum)
            {
                return(GetEnumCombinations(memberPath, underlying, true));
            }

            return(null);
        }
Example #6
0
        public TestValue[] GetTestValues(string memberPath, Type type, object defaultValue, IList <Func <string, Type, bool> > excludeList, ITestValueFactory combinationFactory)
        {
            if (!(defaultValue is IList))
            {
                return(null);
            }

            var allCombinations = new List <TestValue>();
            var listClone       = defaultValue.DeepClone() as IList;

            for (int n = 0; n < listClone.Count; n++)
            {
                var item         = listClone[n];
                var combinations = combinationFactory.GetTestValues($"{memberPath}[{n}]", item.GetType(), item, excludeList);
                foreach (var comb in combinations)
                {
                    var newList = listClone.DeepClone();
                    newList[n] = comb.Value;
                    comb.Value = newList;
                    allCombinations.Add(comb);
                }
            }

            return(allCombinations.ToArray());
        }
        public TestValue[] GetTestValues(string memberPath, Type type, object defaultValue, IList <Func <string, Type, bool> > excludeList, ITestValueFactory combinationFactory)
        {
            if (IsBuiltInType(type))
            {
                throw new Exception($"Failed to create combination for memberPath = {memberPath}, type = {type}");
            }

            if (defaultValue == null)
            {
                return(new TestValue[0]);
            }

            var allCombinations = new List <TestValue>();
            var properties      = type.GetProperties();

            foreach (var propertyInfo in properties)
            {
                var clone        = defaultValue.DeepClone();
                var combinations = combinationFactory.GetTestValues($"{memberPath}.{propertyInfo.Name}", propertyInfo.PropertyType, propertyInfo.GetValue(clone), excludeList);
                if (combinations != null)
                {
                    foreach (var combination in combinations)
                    {
                        var secondClone = clone.DeepClone();
                        propertyInfo.SetValue(secondClone, combination.Value);
                        combination.Value = secondClone;
                        allCombinations.Add(combination);
                    }
                }
            }

            return(allCombinations.ToArray());
        }