コード例 #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 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();
        }
コード例 #3
0
 public void MoveWasMade(Pouring pouring)
 {
     VialSetHistory.RegisterMove(pouring);
     RefreshControls();
 }