From 33894317545d1c0d7ba0b659b98f68b1b9346477 Mon Sep 17 00:00:00 2001 From: SandorDobos Date: Tue, 13 Apr 2021 12:45:45 +0200 Subject: [PATCH 1/2] Adds negative test of Enum.HasFlag. --- Tests/NFUnitTestEnum/UnitTestEnumTests.cs | 41 +++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/Tests/NFUnitTestEnum/UnitTestEnumTests.cs b/Tests/NFUnitTestEnum/UnitTestEnumTests.cs index a44545af..27c5696c 100644 --- a/Tests/NFUnitTestEnum/UnitTestEnumTests.cs +++ b/Tests/NFUnitTestEnum/UnitTestEnumTests.cs @@ -397,6 +397,12 @@ public void EnumFlags05_Test() Debug.WriteLine("check Enum.HasFlag"); TestClassEnumFlags05.TestMethod(); } + [TestMethod] + public void EnumFlags06_Test() + { + Debug.WriteLine("check Enum.HasFlag throws exception"); + TestClassEnumFlags06.TestMethod(); + } //Compiled Test Cases public class Enum_TestClass_enum01 @@ -2629,5 +2635,40 @@ public static void TestMethod() Assert.True(e2.HasFlag(TestClassEnumFlags.Third)); } } + + public class TestClassEnumFlags06 + { + [Flags] + enum enum1 + { + Zero = 0x0000, + First = 0x0001, + Second = 0x0002, + } + [Flags] + enum enum2 + { + Zero = 0x0000, + First = 0x0001, + Second = 0x0002, + } + + + public static void TestMethod() + { + var e1 = enum1.First; + var e2 = enum2.First; + + try + { + e1.HasFlag(e2); + Assert.False(true, "No exception thrown!"); + } + catch (ArgumentException) + { + // no op + } + } + } } } From fb2227a46f334f5acfc804f87339aae0300bb3f3 Mon Sep 17 00:00:00 2001 From: SandorDobos Date: Tue, 13 Apr 2021 14:34:35 +0200 Subject: [PATCH 2/2] Modifications made requested during review --- Tests/NFUnitTestEnum/UnitTestEnumTests.cs | 29 ++++++++++------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/Tests/NFUnitTestEnum/UnitTestEnumTests.cs b/Tests/NFUnitTestEnum/UnitTestEnumTests.cs index 27c5696c..578cf883 100644 --- a/Tests/NFUnitTestEnum/UnitTestEnumTests.cs +++ b/Tests/NFUnitTestEnum/UnitTestEnumTests.cs @@ -2578,6 +2578,17 @@ enum TestClassEnumFlags Third = 0x0004, Fourth = 0x0008, } + + [Flags] + enum TestClassAnotherEnumFlags + { + Zero = 0x0000, + First = 0x0001, + Second = 0x0002, + Third = 0x0004, + Fourth = 0x0008, + } + public class TestClassEnumFlags01 { public static bool TestMethod() @@ -2638,26 +2649,12 @@ public static void TestMethod() public class TestClassEnumFlags06 { - [Flags] - enum enum1 - { - Zero = 0x0000, - First = 0x0001, - Second = 0x0002, - } - [Flags] - enum enum2 - { - Zero = 0x0000, - First = 0x0001, - Second = 0x0002, - } public static void TestMethod() { - var e1 = enum1.First; - var e2 = enum2.First; + var e1 = TestClassEnumFlags.First; + var e2 = TestClassAnotherEnumFlags.First; try {