Пример #1
0
 public static void ParsingTest()
 {
     Console.WriteLine((NumericOperator.GreaterThan, Enums.Parse <NumericOperator>("GreaterThan")));
     Console.WriteLine((NumericOperator.NotEquals, Enums.Parse <NumericOperator>("1")));
     Console.WriteLine((NumericOperator.Equals, Enums.Parse <NumericOperator>("Is", ignoreCase: false, EnumFormat.Description)));
     Console.WriteLine((DaysOfWeek.Monday | DaysOfWeek.Wednesday, Enums.Parse <DaysOfWeek>("Monday, Wednesday")));
     Console.WriteLine((DaysOfWeek.Tuesday | DaysOfWeek.Thursday, FlagEnums.ParseFlags <DaysOfWeek>("Tuesday | Thursday", ignoreCase: false, delimiter: "|")));
 }
Пример #2
0
 public void ParseFlags_ReturnsValidValue_WhenUsingValidStringWithCustomDelimiter()
 {
     Assert.AreEqual(ColorFlagEnum.Red, FlagEnums.ParseFlags <ColorFlagEnum>("Red", "|"));
     Assert.AreEqual(ColorFlagEnum.Red, FlagEnums.ParseFlags <ColorFlagEnum>("1", "|"));
     Assert.AreEqual(ColorFlagEnum.Red | ColorFlagEnum.Blue, FlagEnums.ParseFlags <ColorFlagEnum>("Blue | Red", "|"));
     Assert.AreEqual(ColorFlagEnum.Green | ColorFlagEnum.Blue, FlagEnums.ParseFlags <ColorFlagEnum>("Blue | Green", "|"));
     Assert.AreEqual(ColorFlagEnum.Red | ColorFlagEnum.Green | ColorFlagEnum.Blue, FlagEnums.ParseFlags <ColorFlagEnum>("Blue | Green | Red", "|"));
     Assert.AreEqual(ColorFlagEnum.Red | ColorFlagEnum.Green | ColorFlagEnum.Blue | ColorFlagEnum.UltraViolet, FlagEnums.ParseFlags <ColorFlagEnum>(" Blue |UltraViolet|2 | Red", " | "));
 }
Пример #3
0
    public void Parsing()
    {
        Assert.AreEqual(NumericOperator.GreaterThan, Enums.Parse <NumericOperator>("GreaterThan"));
        Assert.AreEqual(NumericOperator.NotEquals, Enums.Parse <NumericOperator>("1"));
        Assert.AreEqual(NumericOperator.Equals, Enums.Parse <NumericOperator>("Is", ignoreCase: false, EnumFormat.Description));

        Assert.AreEqual(DaysOfWeek.Monday | DaysOfWeek.Wednesday, Enums.Parse <DaysOfWeek>("Monday, Wednesday"));
        Assert.AreEqual(DaysOfWeek.Tuesday | DaysOfWeek.Thursday, FlagEnums.ParseFlags <DaysOfWeek>("Tuesday | Thursday", ignoreCase: false, delimiter: "|"));
    }
Пример #4
0
 public void ParseFlags_ReturnsValidValue_WhenUsingValidName()
 {
     Assert.AreEqual(ColorFlagEnum.Black, FlagEnums.ParseFlags <ColorFlagEnum>("Black"));
     Assert.AreEqual(ColorFlagEnum.Red, FlagEnums.ParseFlags <ColorFlagEnum>("Red"));
     Assert.AreEqual(ColorFlagEnum.Green, FlagEnums.ParseFlags <ColorFlagEnum>("Green"));
     Assert.AreEqual(ColorFlagEnum.Blue, FlagEnums.ParseFlags <ColorFlagEnum>("Blue"));
     Assert.AreEqual(ColorFlagEnum.Red | ColorFlagEnum.Blue, FlagEnums.ParseFlags <ColorFlagEnum>("Blue , Red"));
     Assert.AreEqual(ColorFlagEnum.Green | ColorFlagEnum.Blue, FlagEnums.ParseFlags <ColorFlagEnum>("Blue , Green"));
     Assert.AreEqual(ColorFlagEnum.Red | ColorFlagEnum.Green | ColorFlagEnum.Blue, FlagEnums.ParseFlags <ColorFlagEnum>("Blue , Green , Red"));
     Assert.AreEqual(ColorFlagEnum.UltraViolet, FlagEnums.ParseFlags <ColorFlagEnum>("UltraViolet"));
     Assert.AreEqual(ColorFlagEnum.Red | ColorFlagEnum.Green | ColorFlagEnum.Blue | ColorFlagEnum.UltraViolet, FlagEnums.ParseFlags <ColorFlagEnum>(" Blue ,UltraViolet,Green , Red"));
 }
Пример #5
0
 public void ParseFlags_ReturnsValidValue_WhenUsingValidNumber()
 {
     Assert.AreEqual(ColorFlagEnum.Black, FlagEnums.ParseFlags <ColorFlagEnum>("0"));
     Assert.AreEqual(ColorFlagEnum.Red, FlagEnums.ParseFlags <ColorFlagEnum>("1"));
     Assert.AreEqual(ColorFlagEnum.Green, FlagEnums.ParseFlags <ColorFlagEnum>("2"));
     Assert.AreEqual(ColorFlagEnum.Red | ColorFlagEnum.Green, FlagEnums.ParseFlags <ColorFlagEnum>("+3"));
     Assert.AreEqual(ColorFlagEnum.Blue, FlagEnums.ParseFlags <ColorFlagEnum>("4"));
     Assert.AreEqual(ColorFlagEnum.Red | ColorFlagEnum.Blue, FlagEnums.ParseFlags <ColorFlagEnum>("5"));
     Assert.AreEqual(ColorFlagEnum.Green | ColorFlagEnum.Blue, FlagEnums.ParseFlags <ColorFlagEnum>("6"));
     Assert.AreEqual(ColorFlagEnum.Red | ColorFlagEnum.Green | ColorFlagEnum.Blue, FlagEnums.ParseFlags <ColorFlagEnum>("7"));
     Assert.AreEqual(ColorFlagEnum.UltraViolet, FlagEnums.ParseFlags <ColorFlagEnum>("+8"));
     Assert.AreEqual(ColorFlagEnum.Red | ColorFlagEnum.Green | ColorFlagEnum.Blue | ColorFlagEnum.UltraViolet, FlagEnums.ParseFlags <ColorFlagEnum>(" Blue ,UltraViolet,2 , Red"));
     Assert.AreEqual(ColorFlagEnum.Red | ColorFlagEnum.Green | ColorFlagEnum.Blue | ColorFlagEnum.UltraViolet, FlagEnums.ParseFlags <ColorFlagEnum>("15"));
 }
Пример #6
0
 public void ParseFlags_ReturnsValidValue_WhenUsingValidStringWhileIgnoringCase()
 {
     Assert.AreEqual(ColorFlagEnum.Black, FlagEnums.ParseFlags <ColorFlagEnum>("black", true));
     Assert.AreEqual(ColorFlagEnum.Black, FlagEnums.ParseFlags <ColorFlagEnum>("0", true));
     Assert.AreEqual(ColorFlagEnum.Red, FlagEnums.ParseFlags <ColorFlagEnum>("ReD", true));
     Assert.AreEqual(ColorFlagEnum.Red, FlagEnums.ParseFlags <ColorFlagEnum>("1", true));
     Assert.AreEqual(ColorFlagEnum.Green, FlagEnums.ParseFlags <ColorFlagEnum>("GrEeN", true));
     Assert.AreEqual(ColorFlagEnum.Green, FlagEnums.ParseFlags <ColorFlagEnum>("2", true));
     Assert.AreEqual(ColorFlagEnum.Red | ColorFlagEnum.Green, FlagEnums.ParseFlags <ColorFlagEnum>("3", true));
     Assert.AreEqual(ColorFlagEnum.Blue, FlagEnums.ParseFlags <ColorFlagEnum>("blue", true));
     Assert.AreEqual(ColorFlagEnum.Blue, FlagEnums.ParseFlags <ColorFlagEnum>("4", true));
     Assert.AreEqual(ColorFlagEnum.Red | ColorFlagEnum.Blue, FlagEnums.ParseFlags <ColorFlagEnum>("BLUE , red", true));
     Assert.AreEqual(ColorFlagEnum.Red | ColorFlagEnum.Blue, FlagEnums.ParseFlags <ColorFlagEnum>("5", true));
     Assert.AreEqual(ColorFlagEnum.Green | ColorFlagEnum.Blue, FlagEnums.ParseFlags <ColorFlagEnum>("BlUe, GReen", true));
     Assert.AreEqual(ColorFlagEnum.Green | ColorFlagEnum.Blue, FlagEnums.ParseFlags <ColorFlagEnum>("6", true));
     Assert.AreEqual(ColorFlagEnum.Red | ColorFlagEnum.Green | ColorFlagEnum.Blue, FlagEnums.ParseFlags <ColorFlagEnum>("Red ,    BluE ,greEn", true));
     Assert.AreEqual(ColorFlagEnum.Red | ColorFlagEnum.Green | ColorFlagEnum.Blue, FlagEnums.ParseFlags <ColorFlagEnum>("7", true));
     Assert.AreEqual(ColorFlagEnum.UltraViolet, FlagEnums.ParseFlags <ColorFlagEnum>("UltRaVioLet", true));
     Assert.AreEqual(ColorFlagEnum.UltraViolet, FlagEnums.ParseFlags <ColorFlagEnum>("8", true));
     Assert.AreEqual(ColorFlagEnum.Red | ColorFlagEnum.Green | ColorFlagEnum.Blue | ColorFlagEnum.UltraViolet, FlagEnums.ParseFlags <ColorFlagEnum>(" GREEN ,blue,UltraViolet , 1", true));
     Assert.AreEqual(ColorFlagEnum.Red | ColorFlagEnum.Green | ColorFlagEnum.Blue | ColorFlagEnum.UltraViolet, FlagEnums.ParseFlags <ColorFlagEnum>("15", true));
 }
Пример #7
0
 public void ParseFlags_ReturnsValidValue_WhenUsingValidStringWithCustomDelimiterWhileIgnoringCase()
 {
     Assert.AreEqual(ColorFlagEnum.Black, FlagEnums.ParseFlags <ColorFlagEnum>("black", true, "|"));
     Assert.AreEqual(ColorFlagEnum.Black, FlagEnums.ParseFlags <ColorFlagEnum>("0", true, "|"));
     Assert.AreEqual(ColorFlagEnum.Red, FlagEnums.ParseFlags <ColorFlagEnum>("ReD", true, "|"));
     Assert.AreEqual(ColorFlagEnum.Red, FlagEnums.ParseFlags <ColorFlagEnum>("1", true, "|"));
     Assert.AreEqual(ColorFlagEnum.Green, FlagEnums.ParseFlags <ColorFlagEnum>("GrEeN", true, "|"));
     Assert.AreEqual(ColorFlagEnum.Green, FlagEnums.ParseFlags <ColorFlagEnum>("2", true, "|"));
     Assert.AreEqual(ColorFlagEnum.Red | ColorFlagEnum.Green, FlagEnums.ParseFlags <ColorFlagEnum>("RED|green", true, "|"));
     Assert.AreEqual(ColorFlagEnum.Red | ColorFlagEnum.Green, FlagEnums.ParseFlags <ColorFlagEnum>("3", true, "|"));
     Assert.AreEqual(ColorFlagEnum.Blue, FlagEnums.ParseFlags <ColorFlagEnum>("blue", true, "|"));
     Assert.AreEqual(ColorFlagEnum.Blue, FlagEnums.ParseFlags <ColorFlagEnum>("4", true, "|"));
     Assert.AreEqual(ColorFlagEnum.Red | ColorFlagEnum.Blue, FlagEnums.ParseFlags <ColorFlagEnum>("BLUE | red", true, "|"));
     Assert.AreEqual(ColorFlagEnum.Red | ColorFlagEnum.Blue, FlagEnums.ParseFlags <ColorFlagEnum>("5", true, "|"));
     Assert.AreEqual(ColorFlagEnum.Green | ColorFlagEnum.Blue, FlagEnums.ParseFlags <ColorFlagEnum>("BlUe| GReen", true, "|"));
     Assert.AreEqual(ColorFlagEnum.Green | ColorFlagEnum.Blue, FlagEnums.ParseFlags <ColorFlagEnum>("6", true, "|"));
     Assert.AreEqual(ColorFlagEnum.Red | ColorFlagEnum.Green | ColorFlagEnum.Blue, FlagEnums.ParseFlags <ColorFlagEnum>("BluE |    greEn |Red", true, "|"));
     Assert.AreEqual(ColorFlagEnum.Red | ColorFlagEnum.Green | ColorFlagEnum.Blue, FlagEnums.ParseFlags <ColorFlagEnum>("7", true, "|"));
     Assert.AreEqual(ColorFlagEnum.UltraViolet, FlagEnums.ParseFlags <ColorFlagEnum>("UltRaVioLet", true, "|"));
     Assert.AreEqual(ColorFlagEnum.UltraViolet, FlagEnums.ParseFlags <ColorFlagEnum>("8", true, "|"));
     Assert.AreEqual(ColorFlagEnum.Red | ColorFlagEnum.Green | ColorFlagEnum.Blue | ColorFlagEnum.UltraViolet, FlagEnums.ParseFlags <ColorFlagEnum>(" GREEN |blue|UltraViolet | 1", true, "|"));
     Assert.AreEqual(ColorFlagEnum.Red | ColorFlagEnum.Green | ColorFlagEnum.Blue | ColorFlagEnum.UltraViolet, FlagEnums.ParseFlags <ColorFlagEnum>("15", true, "|"));
 }
Пример #8
0
 public void ParseFlags_UsesDefaultDelimiter_WhenUsingEmptyStringDelimiter()
 {
     Assert.AreEqual(FlagEnums.ParseFlags <ColorFlagEnum>("Red, Green"), FlagEnums.ParseFlags <ColorFlagEnum>("Red, Green", string.Empty));
 }
Пример #9
0
 public void ParseFlags_UsesDefaultDelimiter_WhenUsingNullDelimiter()
 {
     Assert.AreEqual(FlagEnums.ParseFlags <ColorFlagEnum>("Red, Green"), FlagEnums.ParseFlags <ColorFlagEnum>("Red, Green", (string)null));
 }
Пример #10
0
 public void ParseFlags_ThrowsOverflowException_WhenUsingLargeNumber()
 {
     TestHelper.ExpectException <OverflowException>(() => FlagEnums.ParseFlags <ColorFlagEnum>("128"));
 }
Пример #11
0
 public void ParseFlags_ReturnsValidValue_WhenUsingInvalidNumber()
 {
     Assert.AreEqual((ColorFlagEnum)16, FlagEnums.ParseFlags <ColorFlagEnum>("16"));
 }
Пример #12
0
 public void ParseFlags_ThrowsArgumentException_WhenUsingUndefinedString()
 {
     TestHelper.ExpectException <ArgumentException>(() => FlagEnums.ParseFlags <ColorFlagEnum>("Turquoise"));
 }
Пример #13
0
 public void ParseFlags_ThrowsArgumentException_WhenUsingWhiteSpaceString()
 {
     TestHelper.ExpectException <ArgumentException>(() => FlagEnums.ParseFlags <ColorFlagEnum>(" "));
 }
Пример #14
0
 public void ParseFlags_ThrowsArgumentNullException_WhenUsingNullString()
 {
     TestHelper.ExpectException <ArgumentNullException>(() => FlagEnums.ParseFlags <ColorFlagEnum>(null));
 }
Пример #15
0
 public void ParseFlags_ThrowsArgumentNullException_WhenUsingNullString()
 {
     Assert.Throws <ArgumentNullException>(() => FlagEnums.ParseFlags <ColorFlagEnum>(null));
 }
Пример #16
0
 public void ParseFlags_ThrowsArgumentException_WhenUsingWhiteSpaceString()
 {
     Assert.Throws <ArgumentException>(() => FlagEnums.ParseFlags <ColorFlagEnum>(" "));
 }
Пример #17
0
 public void ParseFlags_ThrowsOverflowException_WhenUsingLargeNumber()
 {
     Assert.Throws <OverflowException>(() => FlagEnums.ParseFlags <ColorFlagEnum>("128"));
 }
Пример #18
0
 public void ParseFlags_ThrowsArgumentException_WhenUsingUndefinedString()
 {
     Assert.Throws <ArgumentException>(() => FlagEnums.ParseFlags <ColorFlagEnum>("Turquoise"));
 }