public void Assignments_ShouldBeSuccessful() { t.Should() .Be("In Process"); t2.Should() .Be(StatusEnum.Stopped); t3.Should() .Be(StatusEnum.Error.Value); t4.Description.Should() .Be(StatusEnum.Error.ToString()); t5.Description.Should() .Be("Indicates Running"); t5.Name.Should() .NotBe(t5.Description); t4.Name.Should() .Be(t4.Description); t5.Name.Should() .Be(t5.ToString()); t5.Name.Should() .Be("In Process"); vals.Should() .HaveCount(StatusEnum.Count); t3.Should() .Be(t4); StatusEnum val = "Error1"; val.Should() .BeNull(); val = 12; val.Should() .BeNull(); val = "In Process"; val.Should() .Be(StatusEnum.Running); val = 5; val.Should() .Be(StatusEnum.Running); }
public void Equality_ValuesShouldMatch() { (t3 == t4).Should() .BeTrue(); t3.Equals(t4) .Should() .BeTrue(); t2.Equals(t4) .Should() .BeFalse(); (t3 != t4).Should() .BeFalse(); (t2 == t4).Should() .BeFalse(); (t2 != t4).Should() .BeTrue(); (t3 >= t4).Should() .BeTrue(); (t2 <= t4).Should() .BeTrue(); (t2 > t4).Should() .BeFalse(); (t2 < t4).Should() .BeTrue(); t.Equals(t5) .Should() .BeTrue(); // ReSharper disable once SuspiciousTypeConversion.Global t5.Equals(t) .Should() .BeTrue(); (t5 == t).Should() .BeTrue(); t5.Should() .Be(t); t.Should() .Be(t5); t2 = StatusEnum.Error; t2.HasFlag(StatusEnum.Error) .Should() .BeFalse(); }
public void CompareEnums() { var sRegular = RegularEnum.Running.ToString(); string sEnhanced = StatusEnum.Running; string sFlags = FlagsEnum.Four; var iRegular = (int)RegularEnum.Running; int iEnhanced = StatusEnum.Running; int iFlags = FlagsEnum.Four; // String to Enum regularEnum = (RegularEnum)Enum.Parse(typeof(RegularEnum), sRegular); regularEnum = Enum.Parse <RegularEnum>(sRegular); enhancedEnum = sEnhanced; flagsEnum = sFlags; // Int to Enum regularEnum = (RegularEnum)iRegular; enhancedEnum = iEnhanced; flagsEnum = iFlags; // Flag Manipulation regularEnum = RegularEnum.Stopped | RegularEnum.Error; flagsEnum = FlagsEnum.Four | FlagsEnum.Eight; regularEnum.HasFlag(RegularEnum.Stopped); flagsEnum.HasFlag(FlagsEnum.Four); // regularEnum.HasFlag(2); // Compile Error flagsEnum.HasFlag(2); // Valid check // Errors on conversion: Configurable to be NULL / throw exception. Func <RegularEnum> regularAct = () => regularEnum = (RegularEnum)55; // Assigns 55 regularAct.Should() .NotThrow(); regularEnum.Should() .Be(55); regularAct = () => regularEnum = (RegularEnum)Enum.Parse(typeof(RegularEnum), "Running1"); // throws ArgumentException regularAct.Should() .Throw <ArgumentException>(); Func <StatusEnum> enhancedAct = () => enhancedEnum = 55; // returns null; enhancedAct.Should() .NotThrow(); enhancedEnum.Should() .BeNull(); enhancedAct = () => enhancedEnum = "Running1"; // returns null; enhancedAct.Should() .NotThrow(); enhancedEnum.Should() .BeNull(); StatusEnum.ThrowOnError = true; enhancedAct = () => enhancedEnum = 55; // throws InvalidOperationException enhancedAct.Should() .Throw <InvalidOperationException>(); enhancedAct = () => enhancedEnum = "Running1"; // throws InvalidOperationException enhancedAct.Should() .Throw <InvalidOperationException>(); }