示例#1
0
        public void IndicatesIfCanUndo()
        {
            var history = new VialSetHistory();
            var set     = new VialSet()
            {
                Vials = new Vial[]
                {
                    new Vial(new Color[] { Color.Red }),
                    new Vial(new Color[] { Color.Green, Color.Red }),
                    new Vial(new Color[] { Color.Green, Color.Green }),
                }
            };

            history.CanUndo.ShouldBeFalse();

            set.Vials.ElementAt(0).Stack(set.Vials.ElementAt(1).Pop());
            history.RegisterMove(new Pouring(1, 0));

            history.CanUndo.ShouldBeTrue();

            set.Vials.ElementAt(1).Stack(set.Vials.ElementAt(2).Pop());
            set.Vials.ElementAt(1).Stack(set.Vials.ElementAt(2).Pop());
            history.RegisterMove(new Pouring(2, 1, 2));

            history.CanUndo.ShouldBeTrue();

            history.Undo(set);
            history.CanUndo.ShouldBeTrue();

            history.Undo(set);
            history.CanUndo.ShouldBeFalse();

            history.Redo(set);
            history.CanUndo.ShouldBeTrue();
        }
示例#2
0
 public VialClickedHandler(IVialSetView view, VialSet set, IVialSetHandler vialSetHandler, IEventHandler eventHandler)
 {
     View            = view;
     Set             = set;
     _vialSetHandler = vialSetHandler;
     _eventHandler   = eventHandler;
 }
示例#3
0
        public void VialMultiplePouring()
        {
            var set = new VialSet()
            {
                Vials = new Vial[] {
                    new Vial(new Color[] { Color.Red, Color.Green, Color.Green }),
                    new Vial(new Color[] { Color.Green })
                }
            };

            var handler = new VialSetHandler();

            var resultingSet = handler.Select(set, 0);

            resultingSet.Vials.First().IsSelected.ShouldBeTrue();

            resultingSet = handler.Select(set, 1);

            var vials = resultingSet.Vials.ToArray();

            foreach (var vial in vials)
            {
                vial.IsSelected.ShouldBeFalse();
            }

            vials[0].Colors.ToArray().ShouldBe(new Color[] { Color.Red, });
            vials[1].Colors.ToArray().ShouldBe(new Color[] { Color.Green, Color.Green, Color.Green });
        }
示例#4
0
        public void PouringClearsOptions()
        {
            var set = new VialSet()
            {
                Vials = new Vial[] {
                    new Vial(new Color[] { Color.Red, Color.Yellow, Color.Green }),
                    new Vial(new Color[] { Color.Blue, Color.Yellow, Color.Green, Color.Red }),
                    new Vial(new Color[] { Color.Yellow, Color.Red, Color.Green }),
                    new Vial(new Color[] { Color.Red, Color.Blue, Color.Yellow, Color.Green }),
                    new Vial(),
                    new Vial()
                }
            };

            var handler = new VialSetHandler();

            var resultingSet = handler.Select(set, 2);

            resultingSet = handler.Select(resultingSet, 4);

            foreach (var vial in resultingSet.Vials)
            {
                vial.IsOption.ShouldBeFalse();
            }
        }
示例#5
0
        public void SelectionShowOptions()
        {
            var set = new VialSet()
            {
                Vials = new Vial[] {
                    new Vial(new Color[] { Color.Red, Color.Yellow, Color.Green }),
                    new Vial(new Color[] { Color.Blue, Color.Yellow, Color.Green, Color.Red }),
                    new Vial(new Color[] { Color.Yellow, Color.Red, Color.Green }),
                    new Vial(new Color[] { Color.Red, Color.Blue, Color.Yellow, Color.Green }),
                    new Vial(),
                    new Vial()
                }
            };

            var handler = new VialSetHandler();

            var resultingSet = handler.Select(set, 2);

            var vials = resultingSet.Vials.ToArray();

            vials[0].IsOption.ShouldBeTrue();
            vials[1].IsOption.ShouldBeFalse();
            vials[2].IsOption.ShouldBeFalse();
            vials[3].IsOption.ShouldBeFalse();
            vials[4].IsOption.ShouldBeTrue();
            vials[5].IsOption.ShouldBeTrue();
        }
示例#6
0
        public void NextCanBeFetched()
        {
            var history = new VialSetHistory();
            var set     = new VialSet()
            {
                Vials = new Vial[]
                {
                    new Vial(new Color[] { Color.Red }),
                    new Vial(new Color[] { Color.Green, Color.Red }),
                    new Vial(new Color[] { Color.Green, Color.Green }),
                }
            };

            set.Vials.ElementAt(0).Stack(set.Vials.ElementAt(1).Pop());
            history.RegisterMove(new Pouring(1, 0));

            set.Vials.ElementAt(1).Stack(set.Vials.ElementAt(2).Pop());
            set.Vials.ElementAt(1).Stack(set.Vials.ElementAt(2).Pop());
            history.RegisterMove(new Pouring(2, 1, 2));

            set = history.Undo(set);
            set = history.Undo(set);

            set = history.Redo(set);

            set.ContentEquals(new VialSet()
            {
                Vials = new Vial[]
                {
                    new Vial(new Color[] { Color.Red, Color.Red }),
                    new Vial(new Color[] { Color.Green }),
                    new Vial(new Color[] { Color.Green, Color.Green }),
                }
            }).ShouldBeTrue();

            set = history.Redo(set);

            set.ContentEquals(new VialSet()
            {
                Vials = new Vial[]
                {
                    new Vial(new Color[] { Color.Red, Color.Red }),
                    new Vial(new Color[] { Color.Green, Color.Green, Color.Green }),
                    new Vial(new Color[] { }),
                }
            }).ShouldBeTrue();

            set = history.Redo(set);

            set.ContentEquals(new VialSet()
            {
                Vials = new Vial[]
                {
                    new Vial(new Color[] { Color.Red, Color.Red }),
                    new Vial(new Color[] { Color.Green, Color.Green, Color.Green }),
                    new Vial(new Color[] { }),
                }
            }).ShouldBeTrue();
        }
示例#7
0
        public void NotMatchingIsntComplete()
        {
            var set = new VialSet()
            {
                Vials = new Vial[] {
                    new Vial(new Color[] { Color.Red, Color.Red, Color.Red, Color.Red }),
                    new Vial(new Color[] { Color.Blue, Color.Yellow, Color.Blue, Color.Blue }),
                    new Vial(new Color[] { Color.Yellow, Color.Yellow, Color.Yellow, Color.Yellow }),
                    new Vial(new Color[] { Color.Green, Color.Green, Color.Green, Color.Green }),
                    new Vial(),
                    new Vial()
                }
            };

            set.IsComplete.ShouldBeFalse();
        }
示例#8
0
        public void CompletedIsComplete()
        {
            var set = new VialSet()
            {
                Vials = new Vial[] {
                    new Vial(new Color[] { Color.Red, Color.Red, Color.Red, Color.Red }),
                    new Vial(new Color[] { Color.Blue, Color.Blue, Color.Blue, Color.Blue }),
                    new Vial(new Color[] { Color.Yellow, Color.Yellow, Color.Yellow, Color.Yellow }),
                    new Vial(new Color[] { Color.Green, Color.Green, Color.Green, Color.Green }),
                    new Vial(),
                    new Vial()
                }
            };

            set.IsComplete.ShouldBeTrue();
        }
示例#9
0
        public void SetIsntMarkedAsChangedOnSelect()
        {
            var set = new VialSet()
            {
                Vials = new Vial[] {
                    new Vial(new Color[] { Color.Red, Color.Yellow, Color.Green }),
                    new Vial(new Color[] { Color.Blue, Color.Yellow, Color.Green, Color.Red }),
                    new Vial(new Color[] { Color.Yellow, Color.Red, Color.Green }),
                    new Vial(new Color[] { Color.Red, Color.Blue, Color.Yellow, Color.Green }),
                    new Vial(),
                    new Vial()
                }
            };

            var handler = new VialSetHandler();

            var resultingSet = handler.Select(set, 2);

            resultingSet.HasChanged.ShouldBeFalse();
        }
示例#10
0
        public static bool ContentEquals(this VialSet set, VialSet otherSet)
        {
            if (otherSet == null)
            {
                return(false);
            }
            else if (set.Vials.Count() != otherSet.Vials.Count())
            {
                return(false);
            }

            for (int i = 0; i < set.Vials.Count(); i++)
            {
                if (!set.Vials.ElementAt(i).Colors.IsEqualTo(otherSet.Vials.ElementAt(i).Colors))
                {
                    return(false);
                }
            }

            return(true);
        }
示例#11
0
        public void Handle(object sender, EventType eventType)
        {
            if (eventType != EventType.VialWasClicked)
            {
                return;
            }

            if (Set.IsComplete)
            {
                return;
            }

            var index = ((IVialView)sender).VialIndex;

            Set      = _vialSetHandler.Select(Set, index);
            View.Set = Set;

            if (View.Set.HasChanged)
            {
                _eventHandler.Handle(this, EventType.MoveWasMade);
            }
        }