public void GenerateCanReturnNullAndNonNullValuesTest()
        {
            var nullFound = false;
            var valueFound = false;

            var target = new CountValueGenerator();

            for (var index = 0; index < 1000; index++)
            {
                var value = (int?)target.Generate(typeof(int?), "Count", null);

                if (value == null)
                {
                    nullFound = true;
                }
                else
                {
                    valueFound = true;
                }

                if (nullFound && valueFound)
                {
                    break;
                }
            }

            nullFound.Should().BeTrue();
            valueFound.Should().BeTrue();
        }
        public void GenerateCanEvalutateManyTimesTest(Type type, bool isSupported, double min, double max)
        {
            if (isSupported == false)
            {
                // Ignore this test
                return;
            }

            var target = new CountValueGenerator();

            for (var index = 0; index < 10000; index++)
            {
                var value = target.Generate(type, "Count", null);

                if (type.IsNullable() &&
                    value == null)
                {
                    // Nullable values could be returned so nothing more to assert
                    return;
                }

                var evaluateType = type;

                if (type.IsNullable())
                {
                    evaluateType = type.GenericTypeArguments[0];
                }

                value.Should().BeOfType(evaluateType);

                var convertedValue = Convert.ToDouble(value);

                convertedValue.Should().BeGreaterOrEqualTo(min);
                convertedValue.Should().BeLessOrEqualTo(max);
            }
        }
        public void GenerateReturnsNewValueTest(Type type, bool isSupported, double min, double max)
        {
            if (isSupported == false)
            {
                // Ignore this test
                return;
            }

            var target = new CountValueGenerator();

            var value = target.Generate(type, "Count", null);

            if (type.IsNullable() &&
                value == null)
            {
                // We can't run the assertions because null is a valid outcome
                return;
            }

            var evaluateType = type;

            if (type.IsNullable())
            {
                evaluateType = type.GenericTypeArguments[0];
            }

            value.Should().BeOfType(evaluateType);

            var convertedValue = Convert.ToDouble(value);

            convertedValue.Should().BeLessOrEqualTo(target.MaxCount);
            convertedValue.Should().BeGreaterOrEqualTo(1);
        }
        public void GenerateValidatesRequestedTypeTest(Type type, bool isSupported, double min, double max)
        {
            var target = new CountValueGenerator();

            Action action = () => target.Generate(type, "Count", null);

            if (isSupported)
            {
                action.ShouldNotThrow();
            }
            else
            {
                action.ShouldThrow<NotSupportedException>();
            }
        }
        public void GenerateThrowsExceptionWhenReferenceNotCountTest(
            Type type,
            bool isSupported,
            double min,
            double max)
        {
            var target = new CountValueGenerator();

            Action action = () => target.Generate(type, "Stuff", null);

            action.ShouldThrow<NotSupportedException>();
        }