Ejemplo n.º 1
0
 public void InitializeTests()
 {
     var powerGenerator = new PowerGenerator();
     var weaponFactory = new WeaponFactory();
     var combatantFactory = new CombatantFactory(powerGenerator, weaponFactory);
     this.armyA = new Army(powerGenerator, combatantFactory) { Health = 100 };
     this.armyB = new Army(powerGenerator, combatantFactory) { Health = 100 };
     this.warLogic = new WarLogic();
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Selects an action based on the printed menu.
        /// </summary>
        /// <param name="menuOption"></param>
        public static void SelectFromMenu(string menuOption)
        {
            if (string.IsNullOrEmpty(menuOption)) throw new ArgumentNullException("menuOption");

            switch (menuOption)
            {
                case "A":
                    var powerGenerator = new PowerGenerator();
                    var armyA = new Army(powerGenerator) { Name = "England", Health = 100 };
                    var armyB = new Army(powerGenerator) { Name = "Rome", Health = 100 };
                    var warLogic = new WarLogic();
                    warLogic.OnWarEnding += OnWarEnding;
                    warLogic.GoToWar(armyA, armyB);
                    break;
                case "Q":
                    Console.WriteLine("Quitting the game.");
                    break;
                default:
                    throw new ArgumentException(string.Format("Unknown parameter value: {0}", menuOption), "menuOption");
            }
        }
Ejemplo n.º 3
0
        public void ArmyAttacksWithCombatants()
        {
            IPowerGenerator generatorStub = MockRepository.GenerateStub<IPowerGenerator>();
            ICombatantFactory factoryStub = MockRepository.GenerateStub<ICombatantFactory>();
            Combatant mockCombatant1 = MockRepository.GeneratePartialMock<Combatant>();
            Army enemyArmy = new Army(generatorStub) { Health = 100 };

            // Setup our mock and stub expectations.
            factoryStub.Stub(x => x.CreateRandomCombatant("Test Combatant")).IgnoreArguments().Return(mockCombatant1);
            //factoryStub.Stub(x => x.CreateRandomCombatant("Fake Combatant")).IgnoreArguments().Return(mockCombatant2);

            mockCombatant1.Expect(x => x.Attack(enemyArmy)).Do(
                new CombatantAttack(this.StubCombatantAttacksOpponent));
            mockCombatant1.Replay();

            // Initialize our army and attack.
            Army myArmy = new Army(generatorStub, factoryStub);
            myArmy.Attack(enemyArmy);

            factoryStub.VerifyAllExpectations();
            mockCombatant1.VerifyAllExpectations();
        }
Ejemplo n.º 4
0
 public void ArmyAttackThrowsExceptionIfNoCombatantFactory()
 {
     this.army = new Army(null, null);
     this.army.Attack(this.enemyArmy);
 }
Ejemplo n.º 5
0
 public void TestSetup()
 {
     var powerGenerator = new PowerGenerator();
     var weaponFactory = new WeaponFactory();
     var combatantFactory = new CombatantFactory(powerGenerator, weaponFactory);
     this.army = new Army(powerGenerator, combatantFactory) { Health = 100 };
     this.enemyArmy = new Army(powerGenerator, combatantFactory) { Health = 100 };
 }
Ejemplo n.º 6
0
        public void ArmyPowerOfAttackControlled()
        {
            this.stubWeapon = MockRepository.GenerateStub<IWeapon>();
            var weaponFactoryStub = MockRepository.GenerateStub<IEquipmentFactory>();
            var powerGeneratorStub = MockRepository.GenerateStub<IPowerGenerator>();
            var combatantFactory = new CombatantFactory(powerGeneratorStub, weaponFactoryStub);
            this.army = new Army(powerGeneratorStub, combatantFactory);

            weaponFactoryStub.Expect(x => x.EquipCombatant(null)).IgnoreArguments().Do(
                new EquipCombatant(this.StubEquipCombatant));
            weaponFactoryStub.Replay();

            int expectedDamage = 10;
            this.stubWeapon.Expect(x => x.CalculateDamage()).Return(expectedDamage);

            int enemyHealth = this.enemyArmy.Health;
            this.army.Attack(this.enemyArmy);
            weaponFactoryStub.VerifyAllExpectations();
            this.stubWeapon.VerifyAllExpectations();
            Assert.AreEqual(expectedDamage, enemyHealth - this.enemyArmy.Health);
        }