Example #1
0
        public static void TestThatAllPossibleOperandTypesAreSupported(Dictionary <DataType, HashSet <DataType> > supportedOperandTypes, Func <InternalDataTypeBase, InternalDataTypeBase, InternalDataTypeBase> operation, string operationDescription)
        {
            var allTypePairs = (new[] { EnumExtensions.GetEnumCollection <DataType>(), EnumExtensions.GetEnumCollection <DataType>() })
                               .CartesianProduct()
                               .Select(r => new DataTypePair <DataType>(r.First(), r.Last()))
                               .Distinct();

            var supportedTypes = allTypePairs
                                 .Where(p => supportedOperandTypes.ContainsKey(p.Left) && supportedOperandTypes[p.Left].Contains(p.Right))
                                 .ToList();

            foreach (var pair in allTypePairs)
            {
                var valuePair = new DataTypeValuePair <DataType>(MakeDataType(pair.Left), MakeDataType(pair.Right));
                var act       = new Action(() => _ = operation(valuePair.Left as InternalDataTypeBase, valuePair.Right as InternalDataTypeBase));
                if (supportedTypes.Contains(pair))
                {
                    act.Should().NotThrow($"a {pair.Left} and {pair.Right} should be able to be {operationDescription}");
                }
                else
                {
                    act.Should().Throw <Exception>($"a {pair.Left} and {pair.Right} should not be able to be {operationDescription}");
                }
            }
        }