public void performance_test_reflective_versus_non_reflective()
        {
            System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
            int count = 1000000;

            stopwatch.Start();

            for (int i = 0; i < count; ++i)
            {
                //test the overload that uses Enum.GetValues() behind the scenes
                ArgumentHelper.AssertEnumMember(DayOfWeek.Sunday, "test");
                ArgumentHelper.AssertEnumMember(DayOfWeek.Saturday, "test");
            }

            stopwatch.Stop();
            Console.WriteLine("Reflective: {0}", stopwatch.ElapsedMilliseconds);

            stopwatch.Reset();
            stopwatch.Start();
            DayOfWeek[] validValues = new DayOfWeek[] { DayOfWeek.Sunday, DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday, DayOfWeek.Friday, DayOfWeek.Saturday };

            for (int i = 0; i < count; ++i)
            {
                //test the overload that allows you to explicitly state acceptable values
                ArgumentHelper.AssertEnumMember(DayOfWeek.Sunday, "test", validValues);
                ArgumentHelper.AssertEnumMember(DayOfWeek.Saturday, "test", validValues);
            }

            stopwatch.Stop();
            Console.WriteLine("Non-reflective: {0}", stopwatch.ElapsedMilliseconds);
        }
        public void assert_enum_member_does_not_throw_if_valid_values_are_specified_and_enumeration_values_are_valid()
        {
            var validValues = new DayOfWeek[] { DayOfWeek.Friday, DayOfWeek.Sunday, DayOfWeek.Saturday };

            ArgumentHelper.AssertEnumMember(DayOfWeek.Friday, "test", validValues);
            ArgumentHelper.AssertEnumMember(DayOfWeek.Sunday, "test", validValues);
            ArgumentHelper.AssertEnumMember(DayOfWeek.Saturday, "test", validValues);
        }
        public void assert_enum_member_works_for_byte_enumeration()
        {
            ArgumentHelper.AssertEnumMember(ByteEnum.One, "test");
            ArgumentHelper.AssertEnumMember(ByteEnum.Two, "test");
            ArgumentHelper.AssertEnumMember(ByteEnum.Three, "test");

            var ex = Assert.Throws <ArgumentException>(() => ArgumentHelper.AssertEnumMember((ByteEnum)10, "test"));

            Assert.Equal(string.Format(CultureInfo.InvariantCulture, "Enum value '10' is not defined for enumeration 'Kent.Boogaart.HelperTrinity.UnitTests.ArgumentHelperFixture+ByteEnum'.{0}Parameter name: test", Environment.NewLine), ex.Message);
        }
        public void assert_enum_member_works_for_byte_flags_enumeration()
        {
            ArgumentHelper.AssertEnumMember(ByteFlagsEnum.One | ByteFlagsEnum.Three, "test");
            ArgumentHelper.AssertEnumMember(ByteFlagsEnum.None, "test");
            ArgumentHelper.AssertEnumMember(ByteFlagsEnum.One | ByteFlagsEnum.Two | ByteFlagsEnum.Three, "test");

            var ex = Assert.Throws <ArgumentException>(() => ArgumentHelper.AssertEnumMember((ByteFlagsEnum)80, "test"));

            Assert.Equal(string.Format(CultureInfo.InvariantCulture, "Enum value '80' is not valid for flags enumeration 'HelperTrinity.UnitTests.ArgumentHelperFixture+ByteFlagsEnum'.{0}Parameter name: test", Environment.NewLine), ex.Message);
        }
        public void assert_enum_member_does_not_throw_if_flag_enumeration_values_are_valid()
        {
            var validValues = new FlagsEnum[] { FlagsEnum.One, FlagsEnum.Two, FlagsEnum.Four, FlagsEnum.None };

            ArgumentHelper.AssertEnumMember(FlagsEnum.None, "test", validValues);
            ArgumentHelper.AssertEnumMember(FlagsEnum.One, "test", validValues);
            ArgumentHelper.AssertEnumMember(FlagsEnum.Two, "test", validValues);
            ArgumentHelper.AssertEnumMember(FlagsEnum.Four, "test", validValues);
            ArgumentHelper.AssertEnumMember(FlagsEnum.One | FlagsEnum.Two, "test", validValues);
            ArgumentHelper.AssertEnumMember(FlagsEnum.One | FlagsEnum.Four, "test", validValues);
            ArgumentHelper.AssertEnumMember(FlagsEnum.One | FlagsEnum.Two | FlagsEnum.Four, "test", validValues);
        }
 public void assert_enum_member_does_not_throw_if_enumeration_flags_are_valid()
 {
     ArgumentHelper.AssertEnumMember(FlagsEnum.None, "test");
     ArgumentHelper.AssertEnumMember(FlagsEnum.One, "test");
     ArgumentHelper.AssertEnumMember(FlagsEnum.Two, "test");
     ArgumentHelper.AssertEnumMember(FlagsEnum.Three, "test");
     ArgumentHelper.AssertEnumMember(FlagsEnum.Four, "test");
     ArgumentHelper.AssertEnumMember(FlagsEnum.One | FlagsEnum.Two, "test");
     ArgumentHelper.AssertEnumMember(FlagsEnum.Two | FlagsEnum.Four, "test");
     ArgumentHelper.AssertEnumMember(FlagsEnum.One | FlagsEnum.Two | FlagsEnum.Three, "test");
     ArgumentHelper.AssertEnumMember(FlagsEnum.One | FlagsEnum.Two | FlagsEnum.Three | FlagsEnum.Four, "test");
 }
 public static void AssertEnumMember <TEnum>(this TEnum enumValue, string argName, params TEnum[] validValues)
     where TEnum : struct, IConvertible
 {
     ArgumentHelper.AssertEnumMember(enumValue, argName, validValues);
 }
//		[CLSCompliant(false)]
        internal static void AssertEnumMember <TEnum>(this TEnum enumValue, string argName)
            where TEnum : struct, IConvertible
        {
            ArgumentHelper.AssertEnumMember(enumValue, argName);
        }
        public void assert_enum_member_if_valid_values_are_provided_but_the_enumeration_value_is_not_a_valid_enumeration_value()
        {
            var ex = Assert.Throws <ArgumentException>(() => ArgumentHelper.AssertEnumMember((DayOfWeek)69, "test", DayOfWeek.Friday, DayOfWeek.Sunday));

            Assert.Equal(string.Format(CultureInfo.InvariantCulture, "Enum value '69' is not defined for enumeration 'System.DayOfWeek'.{0}Parameter name: test", Environment.NewLine), ex.Message);
        }
        public void assert_enum_member_throws_if_value_is_not_a_valid_value()
        {
            var ex = Assert.Throws <ArgumentException>(() => ArgumentHelper.AssertEnumMember(DayOfWeek.Monday, "test", DayOfWeek.Friday, DayOfWeek.Sunday));

            Assert.Equal(string.Format(CultureInfo.InvariantCulture, "Enum value 'Monday' is defined for enumeration 'System.DayOfWeek' but it is not permitted in this context.{0}Parameter name: test", Environment.NewLine), ex.Message);
        }
        public void assert_enum_member_throws_if_zero_flag_enumeration_value_is_passed_in_but_it_is_not_a_valid_value()
        {
            var ex = Assert.Throws <ArgumentException>(() => ArgumentHelper.AssertEnumMember(FlagsEnum.None, "test", FlagsEnum.One));

            Assert.Equal(string.Format(CultureInfo.InvariantCulture, "Enum value 'None' is not allowed for flags enumeration 'Kent.Boogaart.HelperTrinity.UnitTests.ArgumentHelperFixture+FlagsEnum'.{0}Parameter name: test", Environment.NewLine), ex.Message);
        }
        public void assert_enum_member_if_valid_flag_values_are_provided_but_the_enumeration_value_is_not_a_valid_flag_enumeration_value()
        {
            var ex = Assert.Throws <ArgumentException>(() => ArgumentHelper.AssertEnumMember((FlagsEnum)68, "test", FlagsEnum.One, FlagsEnum.Two, FlagsEnum.Four));

            Assert.Equal(string.Format(CultureInfo.InvariantCulture, "Enum value '68' is not allowed for flags enumeration 'Kent.Boogaart.HelperTrinity.UnitTests.ArgumentHelperFixture+FlagsEnum'.{0}Parameter name: test", Environment.NewLine), ex.Message);
        }
 public void assert_enum_member_throws_if_no_valid_values_are_provided()
 {
     Assert.Throws <ArgumentNullException>(() => ArgumentHelper.AssertEnumMember(DayOfWeek.Monday, "test", null));
 }
 public void assert_enum_member_does_not_throw_if_enumeration_values_are_valid()
 {
     ArgumentHelper.AssertEnumMember(DayOfWeek.Monday, "test");
     ArgumentHelper.AssertEnumMember((DayOfWeek)3, "test");
 }
        public void assert_enum_member_throws_if_given_invalid_zero_flag_enumeration_value()
        {
            var ex = Assert.Throws <ArgumentException>(() => ArgumentHelper.AssertEnumMember((FlagsEnumNoNone)0, "test"));

            Assert.Equal(string.Format(CultureInfo.InvariantCulture, "Enum value '0' is not valid for flags enumeration 'Kent.Boogaart.HelperTrinity.UnitTests.ArgumentHelperFixture+FlagsEnumNoNone'.{0}Parameter name: test", Environment.NewLine), ex.Message);
        }
        public void assert_enum_member_throws_if_flag_value_is_not_a_valid_value()
        {
            var ex = Assert.Throws <ArgumentException>(() => ArgumentHelper.AssertEnumMember(FlagsEnum.Three, "test", FlagsEnum.One, FlagsEnum.Two, FlagsEnum.Four));

            Assert.Equal(string.Format(CultureInfo.InvariantCulture, "Enum value 'Three' is not valid for flags enumeration 'HelperTrinity.UnitTests.ArgumentHelperFixture+FlagsEnum'.{0}Parameter name: test", Environment.NewLine), ex.Message);
        }