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); }
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); }
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); }
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(); }
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(); }
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(); }
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(); }
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); }
public void Returns_the_value_regardless_of_proper_casing() { var retriever = new EnumValueRetriever(); retriever.GetValue("feMale", typeof(Sex)).ShouldEqual(Sex.Female); }
public void Should_return_the_value_when_it_includes_extra_spaces() { var retriever = new EnumValueRetriever(); retriever.GetValue("Unknown Sex", typeof(Sex)).ShouldEqual(Sex.UnknownSex); }
public void Should_return_the_value_when_it_matches_the_enum() { var retriever = new EnumValueRetriever(); retriever.GetValue("Male", typeof(Sex)).ShouldEqual(Sex.Male); }
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(); }
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); }
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); }
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); }