コード例 #1
0
        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();
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        public void GenerateReturnsOnlyAvailableEnumValueWhenSingleValueDefinedTest()
        {
            var target = new EnumValueGenerator();

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

            first.Should().BeOfType<SingleEnum>();
            first.Should().Be(SingleEnum.First);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        public void AllowNullReturnsFalseByDefault()
        {
            var sut = new EnumValueGenerator();

            sut.AllowNull.Should().BeFalse();
        }
コード例 #7
0
        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();
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        public void IsSupportedThrowsExceptionWithNullTypeTest()
        {
            var target = new EnumValueGenerator();

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

            action.ShouldThrow<ArgumentNullException>();
        }
コード例 #10
0
        public void IsSupportedTest(Type type, bool expected)
        {
            var target = new EnumValueGenerator();

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

            actual.Should().Be(expected);
        }
コード例 #11
0
        public void GenerateThrowsExceptionWithInvalidParametersTest(Type type)
        {
            var target = new EnumValueGenerator();

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

            action.ShouldThrow<NotSupportedException>();
        }
コード例 #12
0
        public void GenerateReturnsZeroForEmptyEnumTest()
        {
            var target = new EnumValueGenerator();

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

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