예제 #1
0
 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);
 }
예제 #2
0
        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();
        }
예제 #3
0
 public void Rolling_a_negative_number_is_invalid()
 {
     var bg = new BowlingGame();
     bg.Bowl(-1);
     Assert.AreEqual(-1, bg.Score);
 }