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(); }
public VialClickedHandler(IVialSetView view, VialSet set, IVialSetHandler vialSetHandler, IEventHandler eventHandler) { View = view; Set = set; _vialSetHandler = vialSetHandler; _eventHandler = eventHandler; }
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 }); }
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(); } }
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(); }
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(); }
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(); }
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(); }
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(); }
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); }
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); } }