Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds negative test of Enum.HasFlag #131

Merged
merged 2 commits into from
Apr 13, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions Tests/NFUnitTestEnum/UnitTestEnumTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -2572,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()
Expand Down Expand Up @@ -2629,5 +2646,26 @@ public static void TestMethod()
Assert.True(e2.HasFlag(TestClassEnumFlags.Third));
}
}

public class TestClassEnumFlags06
{


public static void TestMethod()
{
var e1 = TestClassEnumFlags.First;
var e2 = TestClassAnotherEnumFlags.First;

try
{
e1.HasFlag(e2);
Assert.False(true, "No exception thrown!");
}
catch (ArgumentException)
{
// no op
}
}
}
}
}