示例#1
0
 public void UnsafeFlagEnumsBasicTest()
 {
     Assert.Throws <ArgumentException>(() => FlagEnums.GetAllFlagsUnsafe <int>());
     Assert.Throws <ArgumentException>(() => FlagEnums.GetAllFlagsUnsafe <Enum>());
     Assert.Throws <ArgumentException>(() => FlagEnums.GetAllFlagsUnsafe <string>());
     Assert.AreEqual(ColorFlagEnum.All, FlagEnums.GetAllFlagsUnsafe <ColorFlagEnum>());
 }
示例#2
0
        public void TryParseFlags_ReturnsFalse_WhenUsingUndefinedString()
        {
            ColorFlagEnum result;

            Assert.IsFalse(FlagEnums.TryParseFlags("Turquoise", out result));
            Assert.AreEqual(default(ColorFlagEnum), result);
        }
示例#3
0
    public void FlagEnumOperations()
    {
        // CombineFlags ~ bitwise OR
        Assert.AreEqual(DaysOfWeek.Monday | DaysOfWeek.Wednesday, DaysOfWeek.Monday.CombineFlags(DaysOfWeek.Wednesday));
        Assert.AreEqual(DaysOfWeek.Monday | DaysOfWeek.Wednesday | DaysOfWeek.Friday, FlagEnums.CombineFlags(DaysOfWeek.Monday, DaysOfWeek.Wednesday, DaysOfWeek.Friday));

        // HasAnyFlags
        Assert.IsTrue(DaysOfWeek.Monday.HasAnyFlags(DaysOfWeek.Monday | DaysOfWeek.Wednesday));
        Assert.IsFalse((DaysOfWeek.Monday | DaysOfWeek.Wednesday).HasAnyFlags(DaysOfWeek.Friday));

        // HasAllFlags
        Assert.IsTrue((DaysOfWeek.Monday | DaysOfWeek.Wednesday | DaysOfWeek.Friday).HasAllFlags(DaysOfWeek.Monday | DaysOfWeek.Wednesday));
        Assert.IsFalse(DaysOfWeek.Monday.HasAllFlags(DaysOfWeek.Monday | DaysOfWeek.Wednesday));

        // CommonFlags ~ bitwise AND
        Assert.AreEqual(DaysOfWeek.Monday, DaysOfWeek.Monday.CommonFlags(DaysOfWeek.Monday | DaysOfWeek.Wednesday));
        Assert.AreEqual(DaysOfWeek.None, DaysOfWeek.Monday.CommonFlags(DaysOfWeek.Wednesday));

        // RemoveFlags
        Assert.AreEqual(DaysOfWeek.Wednesday, (DaysOfWeek.Monday | DaysOfWeek.Wednesday).RemoveFlags(DaysOfWeek.Monday));
        Assert.AreEqual(DaysOfWeek.None, (DaysOfWeek.Monday | DaysOfWeek.Wednesday).RemoveFlags(DaysOfWeek.Monday | DaysOfWeek.Wednesday));

        // GetFlags, splits out the individual flags in increasing value order
        List <DaysOfWeek> flags = DaysOfWeek.Weekend.GetFlags().ToList();

        Assert.AreEqual(2, flags.Count);
        Assert.AreEqual(DaysOfWeek.Sunday, flags[0]);
        Assert.AreEqual(DaysOfWeek.Saturday, flags[1]);

        // GetAllFlags
        Assert.AreEqual(DaysOfWeek.All, FlagEnums.GetAllFlags <DaysOfWeek>());
    }
示例#4
0
        public void FormatFlags_ReturnsValidString_WhenUsingValidValueWithCustomDelimiter()
        {
            AssertTryFormatFlags(ColorFlagEnum.Black, " | ", "Black");
            AssertTryFormatFlags(ColorFlagEnum.Red, " | ", "Red");
            AssertTryFormatFlags(ColorFlagEnum.Green, " | ", "Green");
            AssertTryFormatFlags(ColorFlagEnum.Blue, " | ", "Blue");
            AssertTryFormatFlags(ColorFlagEnum.Red | ColorFlagEnum.Green, " | ", "Red | Green");
            AssertTryFormatFlags(ColorFlagEnum.Red | ColorFlagEnum.Blue, " | ", "Red | Blue");
            AssertTryFormatFlags(ColorFlagEnum.Green | ColorFlagEnum.Blue, " | ", "Green | Blue");
            AssertTryFormatFlags(ColorFlagEnum.Red | ColorFlagEnum.Green | ColorFlagEnum.Blue, " | ", "Red | Green | Blue");
            AssertTryFormatFlags(ColorFlagEnum.UltraViolet, " | ", "UltraViolet");
            AssertTryFormatFlags(ColorFlagEnum.Red | ColorFlagEnum.Green | ColorFlagEnum.Blue | ColorFlagEnum.UltraViolet, " | ", "All");

            void AssertTryFormatFlags(ColorFlagEnum value, string delimiter, string expected)
            {
                Assert.AreEqual(expected, FlagEnums.FormatFlags(value, delimiter));
#if SPAN
                var dest = new char[expected.Length];
                Assert.True(FlagEnums.TryFormatFlags(value, dest, out var charsWritten, delimiter));
                Assert.AreEqual(expected.Length, charsWritten);
                Assert.AreEqual(expected, new string(dest));

                dest = new char[expected.Length - 1];
                Assert.False(FlagEnums.TryFormatFlags(value, dest, out charsWritten, delimiter));
                Assert.AreEqual(0, charsWritten);
                CollectionAssert.AreEqual(new char[dest.Length], dest);
#endif
            }
        }
示例#5
0
        public void TryParseFlags_ReturnsFalse_WhenUsingEmptyString()
        {
            ColorFlagEnum result;

            Assert.IsFalse(FlagEnums.TryParseFlags(string.Empty, out result));
            Assert.AreEqual(default(ColorFlagEnum), result);
        }
示例#6
0
        public void TryParseFlags_ReturnsFalse_WhenUsingLargeNumber()
        {
            ColorFlagEnum result;

            Assert.IsFalse(FlagEnums.TryParseFlags("128", out result));
            Assert.AreEqual(default(ColorFlagEnum), result);
        }
示例#7
0
        public void TryParseFlags_ReturnsValidValue_WhenUsingValidNumber()
        {
            ColorFlagEnum result;

            Assert.IsTrue(FlagEnums.TryParseFlags("0", out result));
            Assert.AreEqual(ColorFlagEnum.Black, result);
            Assert.IsTrue(FlagEnums.TryParseFlags("1", out result));
            Assert.AreEqual(ColorFlagEnum.Red, result);
            Assert.IsTrue(FlagEnums.TryParseFlags("+2", out result));
            Assert.AreEqual(ColorFlagEnum.Green, result);
            Assert.IsTrue(FlagEnums.TryParseFlags("3", out result));
            Assert.AreEqual(ColorFlagEnum.Red | ColorFlagEnum.Green, result);
            Assert.IsTrue(FlagEnums.TryParseFlags("4", out result));
            Assert.AreEqual(ColorFlagEnum.Blue, result);
            Assert.IsTrue(FlagEnums.TryParseFlags("+5", out result));
            Assert.AreEqual(ColorFlagEnum.Red | ColorFlagEnum.Blue, result);
            Assert.IsTrue(FlagEnums.TryParseFlags("6", out result));
            Assert.AreEqual(ColorFlagEnum.Green | ColorFlagEnum.Blue, result);
            Assert.IsTrue(FlagEnums.TryParseFlags("7", out result));
            Assert.AreEqual(ColorFlagEnum.Red | ColorFlagEnum.Green | ColorFlagEnum.Blue, result);
            Assert.IsTrue(FlagEnums.TryParseFlags("8", out result));
            Assert.AreEqual(ColorFlagEnum.UltraViolet, result);
            Assert.IsTrue(FlagEnums.TryParseFlags(" Blue ,UltraViolet,+2 , Red", out result));
            Assert.AreEqual(ColorFlagEnum.Red | ColorFlagEnum.Green | ColorFlagEnum.Blue | ColorFlagEnum.UltraViolet, result);
            Assert.IsTrue(FlagEnums.TryParseFlags("15", out result));
            Assert.AreEqual(ColorFlagEnum.All, result);
        }
示例#8
0
        public void TryParseFlags_ReturnsFalse_WhenUsingWhiteSpaceString()
        {
            ColorFlagEnum result;

            Assert.IsFalse(FlagEnums.TryParseFlags(" ", out result));
            Assert.AreEqual(default(ColorFlagEnum), result);
        }
示例#9
0
        /// <summary>
        /// Looks up roles of the authenticated user and selects a user view model type accordingly.
        /// </summary>
        /// <param name="controllerContext">Controller context.</param>
        /// <param name="bindingContext">Binding context.</param>
        /// <returns>Specific user view model, based on the highest role.</returns>
        /// <exception cref="Exception">Thrown when no user identity is found in the HTTP context.</exception>
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            if (bindingContext.ModelType != typeof(IUserViewModel))
            {
                throw new Exception($"The model is not of type {nameof(IUserViewModel)}.");
            }
            else
            {
                var user = UserManager.FindByNameAsync(controllerContext.HttpContext.User?.Identity?.Name).Result;

                if (user == null)
                {
                    throw new Exception($"The {nameof(IUserViewModel)} model cannot be bound because the user could not be retrieved.");
                }
                else
                {
                    var userRoles = UserManager.GetRolesAsync(user.Id).Result.ToMedioClinicRoles();

                    // The roles should be evaluated from the highest to the lowest.
                    if (FlagEnums.HasAnyFlags(Roles.Doctor, userRoles))
                    {
                        bindingContext.ModelMetadata.Model = new DoctorViewModel();
                    }
                    else if (FlagEnums.HasAnyFlags(Roles.Patient, userRoles))
                    {
                        bindingContext.ModelMetadata.Model = new PatientViewModel();
                    }

                    return(DefaultModelBinder.BindModel(controllerContext, bindingContext));
                }
            }
        }
示例#10
0
        public void TryParseFlags_ReturnsValidValue_WhenUsingValidName()
        {
            ColorFlagEnum result;

            Assert.IsTrue(FlagEnums.TryParseFlags("Black", out result));
            Assert.AreEqual(ColorFlagEnum.Black, result);
            Assert.IsTrue(FlagEnums.TryParseFlags("Red", out result));
            Assert.AreEqual(ColorFlagEnum.Red, result);
            Assert.IsTrue(FlagEnums.TryParseFlags("Green", out result));
            Assert.AreEqual(ColorFlagEnum.Green, result);
            Assert.IsTrue(FlagEnums.TryParseFlags("Red, Green", out result));
            Assert.AreEqual(ColorFlagEnum.Red | ColorFlagEnum.Green, result);
            Assert.IsTrue(FlagEnums.TryParseFlags("Blue", out result));
            Assert.AreEqual(ColorFlagEnum.Blue, result);
            Assert.IsTrue(FlagEnums.TryParseFlags("Blue , Red", out result));
            Assert.AreEqual(ColorFlagEnum.Red | ColorFlagEnum.Blue, result);
            Assert.IsTrue(FlagEnums.TryParseFlags("Blue , Green", out result));
            Assert.AreEqual(ColorFlagEnum.Green | ColorFlagEnum.Blue, result);
            Assert.IsTrue(FlagEnums.TryParseFlags("Blue , Green , Red", out result));
            Assert.AreEqual(ColorFlagEnum.Red | ColorFlagEnum.Green | ColorFlagEnum.Blue, result);
            Assert.IsTrue(FlagEnums.TryParseFlags("UltraViolet", out result));
            Assert.AreEqual(ColorFlagEnum.UltraViolet, result);
            Assert.IsTrue(FlagEnums.TryParseFlags(" Blue ,UltraViolet,Green , Red", out result));
            Assert.AreEqual(ColorFlagEnum.Red | ColorFlagEnum.Green | ColorFlagEnum.Blue | ColorFlagEnum.UltraViolet, result);
        }
示例#11
0
        public void TryParseFlags_ReturnsTrue_WhenUsingInvalidNumber()
        {
            ColorFlagEnum result;

            Assert.IsTrue(FlagEnums.TryParseFlags("16", out result));
            Assert.AreEqual((ColorFlagEnum)16, result);
        }
        public void KeyboardClass_Tests()
        {
            Assert.True(FlagEnums.HasAnyFlags(DeviceCapabilityClass.Keyboard, DeviceCapability.KeyA.GetClass()));
            Assert.False(FlagEnums.HasAnyFlags(DeviceCapabilityClass.Controller, DeviceCapability.KeyA.GetClass()));

            Assert.True(FlagEnums.HasAnyFlags(DeviceCapabilityClass.KeyboardMouse, DeviceCapability.KeyA.GetClass()));
            Assert.False(FlagEnums.HasAnyFlags(DeviceCapabilityClass.Mouse, DeviceCapability.KeyA.GetClass()));
        }
示例#13
0
        public void TryParseFlags_UsesDefaultDelimiter_WhenUsingNullDelimiter()
        {
            ColorFlagEnum result0;
            ColorFlagEnum result1;

            Assert.AreEqual(FlagEnums.TryParseFlags("Red, Green", out result0), FlagEnums.TryParseFlags("Red, Green", ignoreCase: false, null, out result1));
            Assert.AreEqual(result0, result1);
        }
示例#14
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: "|")));
 }
示例#15
0
        public void TryParseFlags_UsesDefaultDelimiter_WhenUsingEmptyStringDelimiter()
        {
            ColorFlagEnum result0;
            ColorFlagEnum result1;

            Assert.AreEqual(FlagEnums.TryParseFlags("Red, Green", out result0), FlagEnums.TryParseFlags("Red, Green", string.Empty, out result1));
            Assert.AreEqual(result0, result1);
        }
示例#16
0
 public void IsValid_ReturnsSameResultAsIsValidFlagCombination_WhenUsingFlagEnum()
 {
     for (int i = sbyte.MinValue; i <= sbyte.MaxValue; ++i)
     {
         var value = (ColorFlagEnum)i;
         Assert.AreEqual(FlagEnums.IsValidFlagCombination(value), value.IsValid());
     }
 }
示例#17
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", " | "));
 }
示例#18
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: "|"));
    }
        public void MouseClass_Tests()
        {
            Assert.True(FlagEnums.HasAnyFlags(DeviceCapabilityClass.Mouse, DeviceCapability.Mouse0.GetClass()));
            Assert.True(FlagEnums.HasAnyFlags(DeviceCapabilityClass.MouseButton, DeviceCapability.Mouse0.GetClass()));
            Assert.False(FlagEnums.HasAnyFlags(DeviceCapabilityClass.MouseCursor, DeviceCapability.Mouse0.GetClass()));

            Assert.True(FlagEnums.HasAnyFlags(DeviceCapabilityClass.Mouse, DeviceCapability.CursorX.GetClass()));
            Assert.True(FlagEnums.HasAnyFlags(DeviceCapabilityClass.MouseCursor, DeviceCapability.CursorX.GetClass()));
            Assert.False(FlagEnums.HasAnyFlags(DeviceCapabilityClass.MouseButton, DeviceCapability.CursorX.GetClass()));
        }
        public void ControllerClass_Tests()
        {
            Assert.True(FlagEnums.HasAnyFlags(DeviceCapabilityClass.Controller, DeviceCapability.Button0.GetClass()));
            Assert.True(FlagEnums.HasAnyFlags(DeviceCapabilityClass.Controller, DeviceCapability.Axis0.GetClass()));
            Assert.True(FlagEnums.HasAnyFlags(DeviceCapabilityClass.Controller, DeviceCapability.Hat0E.GetClass()));

            Assert.True(FlagEnums.HasAnyFlags(DeviceCapabilityClass.ControllerDirectional, DeviceCapability.Hat0E.GetClass()));
            Assert.True(FlagEnums.HasAnyFlags(DeviceCapabilityClass.ControllerFaceButton, DeviceCapability.Button0.GetClass()));
            Assert.True(FlagEnums.HasAnyFlags(DeviceCapabilityClass.ControllerAxis, DeviceCapability.Axis0.GetClass()));
        }
        public void AppendFlagEnumTest()
        {
            var week = WeekEnum.Monday;

            FlagEnums.Add(ref week, WeekEnum.Tuesday);

            (0 != (week & WeekEnum.Monday)).ShouldBeTrue();
            (0 != (week & WeekEnum.Tuesday)).ShouldBeTrue();
            (0 != (week & WeekEnum.Wednesday)).ShouldBeFalse();
        }
        public void ContainsFlagEnumTest()
        {
            var week = WeekEnum.Monday;

            FlagEnums.Contains(week, WeekEnum.Monday).ShouldBeTrue();
            FlagEnums.Contains(week, WeekEnum.Tuesday).ShouldBeFalse();

            FlagEnums.Add(ref week, WeekEnum.Tuesday, WeekEnum.Wednesday);

            FlagEnums.Contains(week, WeekEnum.Monday).ShouldBeTrue();
            FlagEnums.Contains(week, WeekEnum.Tuesday).ShouldBeTrue();
        }
示例#23
0
        private static object GetEnums(this Type enumType, object value)
        {
            if (FlagEnums.IsFlagEnum(enumType) && FlagEnums.HasAnyFlags(enumType, value))
            {
                return(string.Join("|", FlagEnums.GetFlagMembers(enumType, value)
                                   .Select(member => $"{enumType.FullName}.{member.Name}")));
            }

            var name = Enum.GetName(enumType, value);

            return($"{enumType.FullName}.{name}");
        }
示例#24
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"));
 }
示例#25
0
        public bool NonGenericFlagEnums_HasAllFlags()
        {
            var result = false;

            foreach (var attributeTargets in _attributeTargets)
            {
                foreach (var otherAttributeTargets in _allAttributeTargets)
                {
                    result |= FlagEnums.HasAllFlags(_enumType, attributeTargets, otherAttributeTargets);
                }
            }
            return(result);
        }
示例#26
0
 public void FormatFlags_ReturnsValidString_WhenUsingValidValue()
 {
     Assert.AreEqual("Black", FlagEnums.FormatFlags(ColorFlagEnum.Black));
     Assert.AreEqual("Red", FlagEnums.FormatFlags(ColorFlagEnum.Red));
     Assert.AreEqual("Green", FlagEnums.FormatFlags(ColorFlagEnum.Green));
     Assert.AreEqual("Blue", FlagEnums.FormatFlags(ColorFlagEnum.Blue));
     Assert.AreEqual("Red, Green", FlagEnums.FormatFlags(ColorFlagEnum.Red | ColorFlagEnum.Green));
     Assert.AreEqual("Red, Blue", FlagEnums.FormatFlags(ColorFlagEnum.Red | ColorFlagEnum.Blue));
     Assert.AreEqual("Green, Blue", FlagEnums.FormatFlags(ColorFlagEnum.Green | ColorFlagEnum.Blue));
     Assert.AreEqual("Red, Green, Blue", FlagEnums.FormatFlags(ColorFlagEnum.Red | ColorFlagEnum.Green | ColorFlagEnum.Blue));
     Assert.AreEqual("UltraViolet", FlagEnums.FormatFlags(ColorFlagEnum.UltraViolet));
     Assert.AreEqual("All", FlagEnums.FormatFlags(ColorFlagEnum.Red | ColorFlagEnum.Green | ColorFlagEnum.Blue | ColorFlagEnum.UltraViolet));
 }
示例#27
0
 public void FormatFlags_ReturnsValidString_WhenUsingValidValueWithCustomDelimiter()
 {
     Assert.AreEqual("Black", FlagEnums.FormatFlags(ColorFlagEnum.Black, " | "));
     Assert.AreEqual("Red", FlagEnums.FormatFlags(ColorFlagEnum.Red, " | "));
     Assert.AreEqual("Green", FlagEnums.FormatFlags(ColorFlagEnum.Green, " | "));
     Assert.AreEqual("Blue", FlagEnums.FormatFlags(ColorFlagEnum.Blue, " | "));
     Assert.AreEqual("Red | Green", FlagEnums.FormatFlags(ColorFlagEnum.Red | ColorFlagEnum.Green, " | "));
     Assert.AreEqual("Red | Blue", FlagEnums.FormatFlags(ColorFlagEnum.Red | ColorFlagEnum.Blue, " | "));
     Assert.AreEqual("Green | Blue", FlagEnums.FormatFlags(ColorFlagEnum.Green | ColorFlagEnum.Blue, " | "));
     Assert.AreEqual("Red | Green | Blue", FlagEnums.FormatFlags(ColorFlagEnum.Red | ColorFlagEnum.Green | ColorFlagEnum.Blue, " | "));
     Assert.AreEqual("UltraViolet", FlagEnums.FormatFlags(ColorFlagEnum.UltraViolet, " | "));
     Assert.AreEqual("All", FlagEnums.FormatFlags(ColorFlagEnum.Red | ColorFlagEnum.Green | ColorFlagEnum.Blue | ColorFlagEnum.UltraViolet, " | "));
 }
示例#28
0
        public static void Extend(this PredifinedModelMapperConfiguration configuration, Action <ModelMapperConfiguration> configure = null)
        {
            var results = FlagEnums.GetFlagMembers(configuration).Select(_ => _.Value)
                          .Select(_ => {
                var modelMapperConfiguration = _.ModelMapperConfiguration(configure);
                return(modelMapperConfiguration.MapData.typeToMap, modelMapperConfiguration);
            });

            foreach (var result in results)
            {
                result.Extend(result.modelMapperConfiguration.MapData.modelType);
            }
        }
示例#29
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"));
 }
示例#30
0
 public void IsValidFlagCombination_Test()
 {
     for (int i = sbyte.MinValue; i <= sbyte.MaxValue; ++i)
     {
         if (i >= 0 && i <= 15)
         {
             Assert.IsTrue(FlagEnums.IsValidFlagCombination((ColorFlagEnum)i));
         }
         else
         {
             Assert.IsFalse(FlagEnums.IsValidFlagCombination((ColorFlagEnum)i));
         }
     }
 }