コード例 #1
0
        public void Retrieve_correct_nullable_value(string value, Sex?expectation)
        {
            var retriever = new EnumValueRetriever();
            var result    = (Sex?)retriever.Retrieve(new KeyValuePair <string, string>(IrrelevantKey, value), IrrelevantType, typeof(Sex?));

            result.Should().Be(expectation);
        }
コード例 #2
0
        public void CanRetrieve(Type type, bool expectation)
        {
            var retriever = new EnumValueRetriever();
            var result    = retriever.CanRetrieve(new KeyValuePair <string, string>(IrrelevantKey, IrrelevantKey), IrrelevantType, type);

            result.Should().Be(expectation);
        }
コード例 #3
0
        public void Throws_an_exception_when_the_value_is_illegal_for_nullable(string value, string exceptionMessage)
        {
            var retriever = new EnumValueRetriever();

            Action action = () => retriever.Retrieve(new KeyValuePair <string, string>(IrrelevantKey, value), IrrelevantType, typeof(Sex?));

            action.Should().Throw <InvalidOperationException>().WithMessage(exceptionMessage);
        }
コード例 #4
0
        public void Does_not_throw_an_exception_when_the_value_is_empty_and_enum_type_is_nullable()
        {
            var retriever = new EnumValueRetriever();

            var exceptionThrown = false;

            try
            {
                retriever.GetValue(string.Empty, typeof(Sex?));
            }
            catch (InvalidOperationException)
            {
                exceptionThrown = true;
            }
            exceptionThrown.ShouldBeFalse();
        }
コード例 #5
0
        public void Throws_an_exception_when_the_value_is_empty()
        {
            var retriever = new EnumValueRetriever();

            var exceptionThrown = false;

            try
            {
                retriever.GetValue(string.Empty, typeof(Sex));
            }
            catch (InvalidOperationException exception)
            {
                if (exception.Message == "No enum with value {empty} found")
                {
                    exceptionThrown = true;
                }
            }
            exceptionThrown.ShouldBeTrue();
        }
コード例 #6
0
        public void Throws_an_exception_when_the_value_is_not_an_enum()
        {
            var retriever = new EnumValueRetriever();

            var exceptionThrown = false;

            try
            {
                retriever.GetValue("NotDefinied", typeof(Sex));
            }
            catch (InvalidOperationException exception)
            {
                if (exception.Message == "No enum with value NotDefinied found")
                {
                    exceptionThrown = true;
                }
            }
            exceptionThrown.ShouldBeTrue();
        }
コード例 #7
0
        public void Does_not_throw_an_exception_when_the_value_is_null_and_enum_type_is_not_nullable()
        {
            var retriever = new EnumValueRetriever();

            var exceptionThrown = false;

            try
            {
                retriever.GetValue(null, typeof(Sex?));
            }
            catch (InvalidOperationException exception)
            {
                if (exception.Message == "No enum with value {null} found")
                {
                    exceptionThrown = true;
                }
            }
            exceptionThrown.Should().BeFalse();
        }
コード例 #8
0
        public void Returns_the_proper_value_when_spaces_and_casing_is_wrong()
        {
            var retriever = new EnumValueRetriever();

            retriever.GetValue("unknown sex", typeof(Sex)).ShouldEqual(Sex.UnknownSex);
        }
コード例 #9
0
        public void Returns_the_value_regardless_of_proper_casing()
        {
            var retriever = new EnumValueRetriever();

            retriever.GetValue("feMale", typeof(Sex)).ShouldEqual(Sex.Female);
        }
コード例 #10
0
        public void Should_return_the_value_when_it_includes_extra_spaces()
        {
            var retriever = new EnumValueRetriever();

            retriever.GetValue("Unknown Sex", typeof(Sex)).ShouldEqual(Sex.UnknownSex);
        }
コード例 #11
0
        public void Should_return_the_value_when_it_matches_the_enum()
        {
            var retriever = new EnumValueRetriever();

            retriever.GetValue("Male", typeof(Sex)).ShouldEqual(Sex.Male);
        }
コード例 #12
0
        public void Should_return_null_when_the_value_is_empty_and_enum_type_is_nullable()
        {
            var retriever = new EnumValueRetriever();

            retriever.GetValue(string.Empty, typeof(Sex?)).ShouldBeNull();
        }
コード例 #13
0
        public void Returns_the_proper_value_when_spaces_and_casing_is_wrong_on_a_nullable_enum()
        {
            var retriever = new EnumValueRetriever();

            retriever.GetValue("unknown sex", typeof(Sex?)).Should().Be(Sex.UnknownSex);
        }
コード例 #14
0
        public void Returns_the_value_regardless_of_proper_casing_on_a_nullable_enum()
        {
            var retriever = new EnumValueRetriever();

            retriever.GetValue("feMale", typeof(Sex?)).Should().Be(Sex.Female);
        }
コード例 #15
0
        public void Should_return_the_value_when_it_includes_extra_spaces_on_the_nullable_enum()
        {
            var retriever = new EnumValueRetriever();

            retriever.GetValue("Unknown Sex", typeof(Sex?)).Should().Be(Sex.UnknownSex);
        }