Пример #1
0
        public void TestCanExecuteExactMatch()
        {
            var fm = new EnumDelegateMap <LongFlags, int>();

            fm.AssignToExactValue(LongFlags.Eight, (f) =>
            {
                f.ShouldBeEquivalentTo(LongFlags.Eight);
                return(9);
            });
            fm.ExecuteExactMatch(LongFlags.Eight).ShouldBeEquivalentTo(9);
            fm.AssignToExactValue(LongFlags.Eight | LongFlags.Five, (f) => 10);
            fm.ExecuteExactMatch(LongFlags.Eight | LongFlags.Five).ShouldBeEquivalentTo(10);
            fm.ExecuteExactMatch(LongFlags.Four).ShouldBeEquivalentTo(default(LongFlags));
            fm = new EnumDelegateMap <LongFlags, int>();
            fm.AssignToEachFlag(LongFlags.Eight | LongFlags.Five, (f) => 42);
            fm.ExecuteExactMatch(LongFlags.Eight).ShouldBeEquivalentTo(42);
            fm.ExecuteExactMatch(LongFlags.Five).ShouldBeEquivalentTo(42);
            fm.ExecuteExactMatch(LongFlags.Eight | LongFlags.Five).ShouldBeEquivalentTo(default(LongFlags));
            fm = new EnumDelegateMap <LongFlags, int>();
            fm.AssignToEachFlag(LongFlags.Eight | LongFlags.Five, (f) =>
            {
                return(42);
            });
            fm.ExecuteExactMatch(LongFlags.Eight | LongFlags.Five).ShouldBeEquivalentTo(default(LongFlags));
        }
Пример #2
0
        public void TestCanExecuteFlags()
        {
            var fm = new EnumDelegateMap <LongFlags, int>();

            fm.AssignToEachFlag(LongFlags.Eight | LongFlags.Five, (f) => 42);

            var dic = fm.ExecuteFlagsMatches(LongFlags.Five);

            dic.Count.ShouldBeEquivalentTo(1);
            dic[LongFlags.Five].ShouldBeEquivalentTo(42);
            dic = fm.ExecuteFlagsMatches(LongFlags.Eight | LongFlags.Five);
            dic.Count.ShouldBeEquivalentTo(2);
            dic[LongFlags.Five].ShouldBeEquivalentTo(42);
            dic[LongFlags.Eight].ShouldBeEquivalentTo(42);

            LongFlags.Nine.EqualsAny(LongFlags.Five, LongFlags.Eight).Should().BeFalse();
            fm.AssignToExactValue(LongFlags.Nine, (f) =>
            {
                f.ShouldBeEquivalentTo(LongFlags.Eight | LongFlags.Five | LongFlags.Nine);
                return(41);
            });
            dic = fm.ExecuteFlagsMatches(LongFlags.Eight | LongFlags.Five | LongFlags.Nine);
            dic.Count.ShouldBeEquivalentTo(3);
            dic[LongFlags.Five].ShouldBeEquivalentTo(42);
            dic[LongFlags.Eight].ShouldBeEquivalentTo(42);
            dic[LongFlags.Nine].ShouldBeEquivalentTo(41);
            fm.ExecuteExactMatch(LongFlags.Four).ShouldBeEquivalentTo(default(LongFlags));
        }
Пример #3
0
        public void TestCanExecuteExactMatchWithDefault()
        {
            var fm = new EnumDelegateMap <LongFlags, int>((f) => 11);

            fm.ExecuteExactMatch(LongFlags.Nine).ShouldBeEquivalentTo(11);
            fm.AssignToExactValue(LongFlags.Nine, (f) => 10);
            fm.ExecuteExactMatch(LongFlags.Nine).ShouldBeEquivalentTo(10);
            fm.ExecuteExactMatch(LongFlags.Five).ShouldBeEquivalentTo(11);
            fm.ExecuteExactMatch(LongFlags.Nine, (f) => 12).ShouldBeEquivalentTo(10);
            fm.ExecuteExactMatch(LongFlags.One, (f) => 13).ShouldBeEquivalentTo(13);
        }
        public void TestCanExecuteFlags()
        {
            var fm = new EnumDelegateMap<LongFlags, int>();

            fm.AssignToEachFlag(LongFlags.Eight | LongFlags.Five, (f) => 42);

            var dic = fm.ExecuteFlagsMatches(LongFlags.Five);
            dic.Count.ShouldBeEquivalentTo(1);
            dic[LongFlags.Five].ShouldBeEquivalentTo(42);
            dic = fm.ExecuteFlagsMatches(LongFlags.Eight | LongFlags.Five);
            dic.Count.ShouldBeEquivalentTo(2);
            dic[LongFlags.Five].ShouldBeEquivalentTo(42);
            dic[LongFlags.Eight].ShouldBeEquivalentTo(42);

            LongFlags.Nine.EqualsAny(LongFlags.Five, LongFlags.Eight).Should().BeFalse();
            fm.AssignToExactValue(LongFlags.Nine, (f) =>
                                  {
                                      f.ShouldBeEquivalentTo(LongFlags.Eight | LongFlags.Five | LongFlags.Nine);
                                      return 41;
                                  });
            dic = fm.ExecuteFlagsMatches(LongFlags.Eight | LongFlags.Five | LongFlags.Nine);
            dic.Count.ShouldBeEquivalentTo(3);
            dic[LongFlags.Five].ShouldBeEquivalentTo(42);
            dic[LongFlags.Eight].ShouldBeEquivalentTo(42);
            dic[LongFlags.Nine].ShouldBeEquivalentTo(41);
            fm.ExecuteExactMatch(LongFlags.Four).ShouldBeEquivalentTo(default(LongFlags));
        }
 public void TestCanExecuteExactMatchWithDefault()
 {
     var fm = new EnumDelegateMap<LongFlags, int>((f) => 11);
     fm.ExecuteExactMatch(LongFlags.Nine).ShouldBeEquivalentTo(11);
     fm.AssignToExactValue(LongFlags.Nine, (f) => 10);
     fm.ExecuteExactMatch(LongFlags.Nine).ShouldBeEquivalentTo(10);
     fm.ExecuteExactMatch(LongFlags.Five).ShouldBeEquivalentTo(11);
     fm.ExecuteExactMatch(LongFlags.Nine, (f) => 12).ShouldBeEquivalentTo(10);
     fm.ExecuteExactMatch(LongFlags.One, (f) => 13).ShouldBeEquivalentTo(13);
 }
 public void TestCanExecuteExactMatch()
 {
     var fm = new EnumDelegateMap<LongFlags, int>();
     fm.AssignToExactValue(LongFlags.Eight, (f) =>
                           {
                               f.ShouldBeEquivalentTo(LongFlags.Eight);
                               return 9;
                           });
     fm.ExecuteExactMatch(LongFlags.Eight).ShouldBeEquivalentTo(9);
     fm.AssignToExactValue(LongFlags.Eight | LongFlags.Five, (f) => 10);
     fm.ExecuteExactMatch(LongFlags.Eight | LongFlags.Five).ShouldBeEquivalentTo(10);
     fm.ExecuteExactMatch(LongFlags.Four).ShouldBeEquivalentTo(default(LongFlags));
     fm = new EnumDelegateMap<LongFlags, int>();
     fm.AssignToEachFlag(LongFlags.Eight | LongFlags.Five, (f) => 42);
     fm.ExecuteExactMatch(LongFlags.Eight).ShouldBeEquivalentTo(42);
     fm.ExecuteExactMatch(LongFlags.Five).ShouldBeEquivalentTo(42);
     fm.ExecuteExactMatch(LongFlags.Eight | LongFlags.Five).ShouldBeEquivalentTo(default(LongFlags));
     fm = new EnumDelegateMap<LongFlags, int>();
     fm.AssignToEachFlag(LongFlags.Eight | LongFlags.Five, (f) =>
                         {
                             return 42;
                         });
     fm.ExecuteExactMatch(LongFlags.Eight | LongFlags.Five).ShouldBeEquivalentTo(default(LongFlags));
 }