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

            var target = new EnumValueGenerator();

            for (var index = 0; index < 1000; index++)
            {
                var value = (SingleEnum?) target.Generate(typeof(SingleEnum?), null, 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 EnumValueGenerator
            {
                AllowNull = allowNull
            };

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

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

                    break;
                }
            }

            nullFound.Should().Be(allowNull);
        }
        public void GenerateReturnsOnlyAvailableEnumValueWhenSingleValueDefinedTest()
        {
            var target = new EnumValueGenerator();

            var first = target.Generate(typeof(SingleEnum), null, null);

            first.Should().BeOfType<SingleEnum>();
            first.Should().Be(SingleEnum.First);
        }
        public void GenerateReturnsRandomFileAttributesValueTest()
        {
            var target = new EnumValueGenerator();

            var first = target.Generate(typeof(FileAttributes), null, null);

            first.Should().BeOfType<FileAttributes>();

            var second = target.Generate(typeof(FileAttributes), null, null);

            first.Should().NotBe(second);
        }
        public void GenerateReturnsRandomFlagsEnumValueTest()
        {
            var target = new EnumValueGenerator();

            var first = target.Generate(typeof(BigFlagsEnum), null, null);

            first.Should().BeOfType<BigFlagsEnum>();

            var values = Enum.GetValues(typeof(BigFlagsEnum));

            values.Should().NotContain(first);

            var second = target.Generate(typeof(BigFlagsEnum), null, null);

            first.Should().NotBe(second);
        }
        public void AllowNullReturnsFalseByDefault()
        {
            var sut = new EnumValueGenerator();

            sut.AllowNull.Should().BeFalse();
        }
        public void GenerateReturnsSmallFlagsEnumTest()
        {
            var target = new EnumValueGenerator();
            var first = false;
            var second = false;
            var third = false;

            for (var index = 0; index < 1000; index++)
            {
                var actual = (SmallFlags) target.Generate(typeof(SmallFlags), null, null);

                if (actual == SmallFlags.First)
                {
                    first = true;
                }
                else if (actual == SmallFlags.Second)
                {
                    second = true;
                }
                else if (actual == (SmallFlags.First | SmallFlags.Second))
                {
                    third = true;
                }

                if (first &&
                    second &&
                    third)
                {
                    break;
                }
            }

            first.Should().BeTrue();
            second.Should().BeTrue();
            third.Should().BeTrue();
        }
        public void GenerateReturnsRandomValueWhenTypeIsEnumTest()
        {
            var target = new EnumValueGenerator();

            var first = target.Generate(typeof(BigEnum), null, null);

            first.Should().BeOfType<BigEnum>();
            Enum.IsDefined(typeof(BigEnum), first).Should().BeTrue();

            var second = target.Generate(typeof(BigEnum), null, null);

            first.Should().NotBe(second);
        }
        public void IsSupportedThrowsExceptionWithNullTypeTest()
        {
            var target = new EnumValueGenerator();

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

            action.ShouldThrow<ArgumentNullException>();
        }
        public void IsSupportedTest(Type type, bool expected)
        {
            var target = new EnumValueGenerator();

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

            actual.Should().Be(expected);
        }
        public void GenerateThrowsExceptionWithInvalidParametersTest(Type type)
        {
            var target = new EnumValueGenerator();

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

            action.ShouldThrow<NotSupportedException>();
        }
        public void GenerateReturnsZeroForEmptyEnumTest()
        {
            var target = new EnumValueGenerator();

            var first = target.Generate(typeof(EmptyEnum), null, null);

            first.Should().BeOfType<EmptyEnum>();
            first.Should().Be((EmptyEnum) 0);
        }