예제 #1
0
 public void hit_decreases_hp_properly()
 {
     var tank = new Tank();
     var initialHealth = tank.Health;
     tank.Hit(10);
     Assert.AreEqual(initialHealth-10, tank.Health);
 }
예제 #2
0
 public void bullet_fired_event_is_fired()
 {
     var tank = new Tank();
     var firedGuid = Guid.Empty;
     tank.BulletFired += (sender, guid) => firedGuid = guid;
     tank.Fire();
     Assert.AreNotEqual(Guid.Empty, firedGuid);
 }
예제 #3
0
 public void firing_with_no_bullets_does_not_throw()
 {
     var tank = new Tank();
     var numBullets = tank.Bullets.Count;
     for (int i = 0; i <= numBullets; i++)
     {
         Assert.DoesNotThrow(() => tank.Fire());
     }
     Assert.AreEqual(0, tank.Bullets.Count);
 }
예제 #4
0
 public void fired_bullet_removed_from_stack()
 {
     var tank = new Tank();
     var firedGuid = Guid.Empty;
     tank.BulletFired += (sender, guid) => firedGuid = guid;
     tank.Fire();
     if(tank.Bullets.GroupBy(b => b.SerialNumber).Any(g => g.Count() > 1))
     {
         Assert.Inconclusive("Duplicate guids!");
         //Let me know if you get this! Pic or didn't happen!
     }
     Assert.AreNotEqual(Guid.Empty, firedGuid);
     Assert.That(tank.Bullets.All(b => b.SerialNumber != firedGuid));
 }
예제 #5
0
 public void Repair(Tank tank)
 {
     if (tank.IsGoodTank)
     {
         throw new Exception("Cannot fix good tank");
     }
     if (tank.IsDestroyed)
     {
         throw new Exception("Cannot fix destroyed tank!");
     }
     if (tank.IsBroken)
     {
         tank.Health = 100;
     }
 }
예제 #6
0
 public void hit_received_is_fired()
 {
     var tank = new Tank();
     bool eventFired = false;
     int healthAfterHit = 0;
     tank.HitReceived += (sender, currentHealth) =>
     {
         eventFired = true;
         healthAfterHit = currentHealth;
     };
     var initialHealth = tank.Health;
     const int hitVal = 50;
     tank.Hit(hitVal);
     Assert.That(eventFired);
     Assert.AreEqual(initialHealth-hitVal, healthAfterHit);
 }
예제 #7
0
 public void cannot_fix_tank_with_hp_less_than_1()
 {
     var tank = new Tank();
     tank.Hit(tank.Health);
     Assert.Throws<Exception>(() => _mechanic.Repair(tank));
 }
예제 #8
0
 public void cannot_fix_good_tank()
 {
     var tank = new Tank();
     Assert.Throws<Exception>(() => { _mechanic.Repair(tank); });
 }
예제 #9
0
 public void no_unidentified_bullets()
 {
     var tank = new Tank();
     Assert.That(tank.AllBulletsPassTest(b => b.SerialNumber != Guid.Empty));
 }
예제 #10
0
 public void hp_equals_100_after_repairs()
 {
     var tank = new Tank();
     tank.Hit(96);
     _mechanic.Repair(tank);
     Assert.AreEqual(100, tank.Health);
 }
예제 #11
0
 public void hp_cannot_be_negative()
 {
     var tank = new Tank();
     Assert.Throws<Exception>(() => tank.Hit(tank.Health*2));
 }