public void Move_RuleViolation_RaisesEvent() { var grid = new UniversalGrid <string>(3, 3); var thing1 = "A".AsSpatialObject(1, 1); ISpatialRule rule = null; grid.RuleViolated += (s, e) => { rule = e.Rule; }; grid.AddConstraint((x, m) => m.Any(p => p.Y > 1), 1, 23); // Add a rule which prevents Y from exceeding 2 grid.SetObject(thing1); thing1.Move(Direction.Right); // 2, 1 Assert.That(rule == null); thing1.Move(Direction.Down); // try to move => 2, 2 Assert.That(thing1.TopLeft.Y, Is.EqualTo(1), "The Y value should remain unchanged"); Assert.That(thing1.TopLeft.X, Is.EqualTo(2), "The X value should remain unchanged"); Assert.That(rule.Id == 23); }
public void Move_NonTypes_RuleViolation_RaisesEvent() { var grid = new UniversalGrid <string>(3, 3); var thing1 = "A".AsSpatialObject(1, 1); var rule = grid.AddConstraint((x, m) => m.Any(p => p.Y > 1)); // Add a rule which prevents Y from exceeding 2 bool wasExecuted = false; grid.RuleViolated += (s, e) => { wasExecuted = true; Assert.That(e.Rule, Is.SameAs(rule)); }; grid.SetObject(thing1); thing1.Move(Direction.Down); // try to move => 1, 2 Assert.That(rule.Id == 1); Assert.That(wasExecuted); }