Skip to content

Commit 290ca6c

Browse files
authored
Adds negative test of Enum.HasFlag (#131)
1 parent b996f0c commit 290ca6c

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

Tests/NFUnitTestEnum/UnitTestEnumTests.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,12 @@ public void EnumFlags05_Test()
397397
Debug.WriteLine("check Enum.HasFlag");
398398
TestClassEnumFlags05.TestMethod();
399399
}
400+
[TestMethod]
401+
public void EnumFlags06_Test()
402+
{
403+
Debug.WriteLine("check Enum.HasFlag throws exception");
404+
TestClassEnumFlags06.TestMethod();
405+
}
400406

401407
//Compiled Test Cases
402408
public class Enum_TestClass_enum01
@@ -2572,6 +2578,17 @@ enum TestClassEnumFlags
25722578
Third = 0x0004,
25732579
Fourth = 0x0008,
25742580
}
2581+
2582+
[Flags]
2583+
enum TestClassAnotherEnumFlags
2584+
{
2585+
Zero = 0x0000,
2586+
First = 0x0001,
2587+
Second = 0x0002,
2588+
Third = 0x0004,
2589+
Fourth = 0x0008,
2590+
}
2591+
25752592
public class TestClassEnumFlags01
25762593
{
25772594
public static bool TestMethod()
@@ -2629,5 +2646,26 @@ public static void TestMethod()
26292646
Assert.True(e2.HasFlag(TestClassEnumFlags.Third));
26302647
}
26312648
}
2649+
2650+
public class TestClassEnumFlags06
2651+
{
2652+
2653+
2654+
public static void TestMethod()
2655+
{
2656+
var e1 = TestClassEnumFlags.First;
2657+
var e2 = TestClassAnotherEnumFlags.First;
2658+
2659+
try
2660+
{
2661+
e1.HasFlag(e2);
2662+
Assert.False(true, "No exception thrown!");
2663+
}
2664+
catch (ArgumentException)
2665+
{
2666+
// no op
2667+
}
2668+
}
2669+
}
26322670
}
26332671
}

0 commit comments

Comments
 (0)