public void Legacy_Rolling_a_negative_number_is_invalid() { // Demonstrates a one way to avoid re-writing legacy assertions. Better to re-write. var bg = new BowlingGame(); bg.LegacyBowl(-1); Assert.AreEqual(-1, bg.Score); }
public static void Main(string[] args) { try { var bg = new BowlingGame(); bg.SetScore(-1); // Should fail at runtime due to invariant protection } catch (Exception ex) { // Unfortunately the exception thrown is a RunTime type derived from system.Exception Console.WriteLine(ex.Message); } try { var bg = new BowlingGame(); bg.Bowl(-1); // Static checker catches this and you should see a warning in build output. } catch (Exception ex) { Console.WriteLine(ex.Message); } try { var frame = new Frame(); frame.Roll(2); frame.Roll(3); frame.Roll(1); // Postcondition from contract class should fail } catch (ArgumentException ex) { Console.WriteLine(ex.Message); } Console.ReadLine(); }
public void Rolling_a_negative_number_is_invalid() { var bg = new BowlingGame(); bg.Bowl(-1); Assert.AreEqual(-1, bg.Score); }