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 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)); }
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 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)); }