Shouldly
  • Overview
  • Contributing
  • Documentation
    • Getting Started
    • Configuration
    • Equality
      • ShouldBe
      • NotBe
      • Null
      • Bool
      • Flags
      • AssignableTo
      • OfType
      • OneOf
      • Greater/Less Than
      • InRange
      • MatchApproved
      • Enumerable
      • SameAs
      • String
      • ExampleClasses
    • String
      • ShouldBe
      • Match
      • Contain
      • Null and Empty
      • StartWith
      • EndWith
    • Enumerable
      • ShouldBe
      • All
      • Empty
      • OneOf
      • Contain
      • Unique
      • SubsetOf
      • Have
    • Dictionary
      • ContainKey
      • ContainKeyAndValue
    • Exceptions
      • Throw
      • NotThrow
    • SatisfyAllConditions
    • CompleteIn
    • DynamicShould
    • Upgrade 3 to 4
Powered by GitBook
On this page
  • ShouldHaveFlag
  • ShouldNotHaveFlag
Edit on GitHub
  1. Documentation
  2. Equality

Flags

PreviousBoolNextAssignableTo

Last updated 2 years ago

ShouldHaveFlag allows you to assert whether an object is an enum and has a flag specified.

Conversely ShouldNotHaveFlag allows you to assert the opposite; that an object is an enum but does not have a flag specified.

ShouldHaveFlag

var actual = TestEnum.FlagTwo;
var value = TestEnum.FlagOne;
actual.ShouldHaveFlag(value);

|

Exception

actual
    should have flag
TestEnum.FlagOne
    but had
TestEnum.FlagTwo

ShouldNotHaveFlag

var actual = TestEnum.FlagOne;
var value = TestEnum.FlagOne;
actual.ShouldNotHaveFlag(value);

Exception

actual
    should not have flag
TestEnum.FlagOne
    but it had
TestEnum.FlagOne

|

snippet source
anchor
snippet source
anchor