public void ToggleFlag_DoesNotMutateArgument() { NoZeroFlags fourNotSet = NoZeroFlags.Three; Assert.That(fourNotSet.HasFlag(NoZeroFlags.Four), Is.False); fourNotSet.ToggleFlag(NoZeroFlags.Four); Assert.That(fourNotSet.HasFlag(NoZeroFlags.Four), Is.False); }
public void ToggleFlag_AlreadySetValue_ValueUnset() { NoZeroFlags fourAlreadySet = NoZeroFlags.Three | NoZeroFlags.Four; Assert.That(fourAlreadySet.HasFlag(NoZeroFlags.Four), Is.True); var fourToggleFlag = fourAlreadySet.ToggleFlag(NoZeroFlags.Four); Assert.That(fourToggleFlag.HasFlag(NoZeroFlags.Four), Is.False); }
public void Explore() { Assert.That(Enumeration.IsEnum <ActionTargets>(), Is.True); Assert.That(Enumeration.IsEnum <int>(), Is.False); Assert.That(Enumeration.AssertEnum <ActionTargets>, Throws.Nothing); Assert.That(Enumeration.AssertEnum <int>, Throws .InstanceOf <ArgumentException>() .With.Message.Contains("Int32")); Assert.That(Enumeration.IsFlags <ZeroFlags>(), Is.True); Assert.That(Enumeration.IsFlags <IntEnum>(), Is.False); Assert.That(Enumeration.AssertFlags <ZeroFlags>, Throws.Nothing); Assert.That(Enumeration.AssertFlags <IntEnum>, Throws .ArgumentException .With.Message.Contains("IntEnum")); Assert.That(Enumeration.IsDefined(StringComparison.Ordinal), Is.True); Assert.That(Enumeration.IsDefined((StringComparison)100), Is.False); Assert.That(Enumeration.IsDefined <LongEnum>(1L), Is.True); Assert.That(Enumeration.IsDefined <StringComparison>("undefined"), Is.False); Assert.That(Enumeration.IsDefined <StringComparison>("oRDinaL", ignoreCase: true), Is.True); Assert.That(() => Enumeration.AssertDefined(StringComparison.Ordinal), Throws.Nothing); Assert.That(() => Enumeration.AssertDefined <StringComparison>("ordinal"), Throws .InstanceOf <InvalidEnumArgumentException>() .With.Message.Contains("ordinal") .And.With.Message.Contains("StringComparison")); Assert.That(Enumeration.GetName(StringComparison.Ordinal), Is.EqualTo("Ordinal")); Assert.That(Enumeration.GetName <ULongEnum>(1UL), Is.EqualTo("Two")); Assert.That(() => Enumeration.GetName <IntEnum>(100), Throws.InstanceOf <InvalidEnumArgumentException>()); Assert.That(Enumeration.GetValues <StringSplitOptions>(), Is.EquivalentTo( new[] { StringSplitOptions.None, StringSplitOptions.RemoveEmptyEntries })); Assert.That(Enumeration.GetValue <ULongEnum, ulong>(ULongEnum.Two), Is.EqualTo(1UL)); Assert.That(Enumeration.Cast <ByteEnum>((byte)1), Is.EqualTo(ByteEnum.Two)); StringComparison?value; Assert.That(Enumeration.TryCast(100, out value), Is.False); Assert.That(Enumeration.Parse <ActionTargets>("Suite"), Is.EqualTo(ActionTargets.Suite)); Assert.That(() => Enumeration.Parse <ActionTargets>("SUIte", ignoreCase: false), Throws.InstanceOf <InvalidEnumArgumentException>()); Assert.That(Enumeration.Parse <StringComparison>("4"), Is.EqualTo(StringComparison.Ordinal)); ActionTargets?parsed; Assert.That(() => Enumeration.TryParse("100", out parsed), Is.False); Assert.That(Enumeration.TryParse("suiTE", true, out parsed), Is.True); var fourNotSet = NoZeroFlags.Three; NoZeroFlags fourSet = fourNotSet.SetFlag(NoZeroFlags.Four); Assert.That(fourSet.HasFlag(NoZeroFlags.Four), Is.True); NoZeroFlags fourUnset = fourSet.UnsetFlag(NoZeroFlags.Four); Assert.That(fourUnset.HasFlag(NoZeroFlags.Four), Is.False); fourSet = fourUnset.ToggleFlag(NoZeroFlags.Four); Assert.That(fourSet.HasFlag(NoZeroFlags.Four), Is.True); fourNotSet = fourSet.ToggleFlag(NoZeroFlags.Four); Assert.That(fourNotSet.HasFlag(NoZeroFlags.Four), Is.False); Assert.That(fourSet.GetFlags(), Is.EquivalentTo(new[] { NoZeroFlags.Three, NoZeroFlags.Four })); }