public void PriorityReturnsValueHigherThanNumericValueGenerator()
        {
            var sut   = new AgeValueGenerator();
            var other = new NumericValueGenerator();

            sut.Priority.Should().BeGreaterThan(other.Priority);
        }
        public void GenerateCanReturnNullAndNonNullValuesTest()
        {
            var nullFound = false;
            var valueFound = false;

            var target = new AgeValueGenerator();

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

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

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

            nullFound.Should().BeTrue();
            valueFound.Should().BeTrue();
        }
        public void AllowNullDeterminesWhetherNullCanBeReturned(bool allowNull)
        {
            var nullFound = false;

            var executeStrategy = Substitute.For <IExecuteStrategy>();

            var buildChain = new BuildHistory();

            executeStrategy.BuildChain.Returns(buildChain);

            var sut = new AgeValueGenerator
            {
                AllowNull = allowNull
            };

            for (var index = 0; index < 10000; index++)
            {
                var value = sut.Generate(executeStrategy, typeof(int?));

                if (value == null)
                {
                    nullFound = true;

                    break;
                }
            }

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

            var target = new AgeValueGenerator();

            for (var index = 0; index < 10000; index++)
            {
                var value = target.Generate(type, "Age", 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 typeSupported, double min, double max)
        {
            if (typeSupported == false)
            {
                // Ignore this test
                return;
            }

            var target = new AgeValueGenerator();

            var value = target.Generate(type, "Age", 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.MaxAge);
            convertedValue.Should().BeGreaterOrEqualTo(1);
        }
        public void SettingMaxAgeShouldNotChangeDefaultMaxAgeTest()
        {
            var target = new AgeValueGenerator
            {
                MaxAge = Environment.TickCount
            };

            AgeValueGenerator.DefaultMaxAge.Should().NotBe(target.MaxAge);
        }
        public void SettingDefaultMaxAgeOnlyAffectsNewInstancesTest()
        {
            var expected = AgeValueGenerator.DefaultMaxAge;

            try
            {
                var first = new AgeValueGenerator();

                AgeValueGenerator.DefaultMaxAge = 11;

                var second = new AgeValueGenerator();

                first.MaxAge.Should().Be(expected);
                second.MaxAge.Should().Be(11);
            }
            finally
            {
                AgeValueGenerator.DefaultMaxAge = expected;
            }
        }
        public void IsSupportedThrowsExceptionWithNullTypeTest()
        {
            var target = new AgeValueGenerator();

            Action action = () => target.IsSupported(null, null, null);

            action.ShouldThrow<ArgumentNullException>();
        }
        public void IsSupportedReturnsTrueWhenReferenceNameIncludesAgeTest(Type type, bool typeSupported, double min,
            double max)
        {
            if (typeSupported == false)
            {
                // Ignore this test
                return;
            }

            var target = new AgeValueGenerator();

            var actual = target.IsSupported(type, "SomeAgeValue", null);

            actual.Should().BeTrue();
        }
        public void IsSupportedEvaluatesRequestedTypeTest(Type type, bool typeSupported, double min, double max)
        {
            var target = new AgeValueGenerator();

            var actual = target.IsSupported(type, "Age", null);

            actual.Should().Be(typeSupported);
        }
        public void HasHigherPriorityThanNumericValueGeneratorTest()
        {
            var target = new AgeValueGenerator();
            var other = new NumericValueGenerator();

            target.Priority.Should().BeGreaterThan(other.Priority);
        }
        public void GenerateValidatesRequestedTypeTest(Type type, bool typeSupported, double min, double max)
        {
            var target = new AgeValueGenerator();

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

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

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

            action.ShouldThrow<NotSupportedException>();
        }
        public void AllowNullReturnsFalseByDefault()
        {
            var sut = new AgeValueGenerator();

            sut.AllowNull.Should().BeFalse();
        }
        public void MinAgeDefaultsTo1()
        {
            var sut = new AgeValueGenerator();

            sut.MinAge.Should().Be(1);
        }
        public void MaxAgeDefaultsTo100()
        {
            var sut = new AgeValueGenerator();

            sut.MaxAge.Should().Be(100);
        }