コード例 #1
0
ファイル: WarLogicTests.cs プロジェクト: neraath/YeOldeTdd
 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();
 }
コード例 #2
0
ファイル: Program.cs プロジェクト: neraath/YeOldeTdd
        /// <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");
            }
        }
コード例 #3
0
ファイル: ArmyTests.cs プロジェクト: neraath/YeOldeTdd
        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();
        }
コード例 #4
0
ファイル: ArmyTests.cs プロジェクト: neraath/YeOldeTdd
 public void ArmyAttackThrowsExceptionIfNoCombatantFactory()
 {
     this.army = new Army(null, null);
     this.army.Attack(this.enemyArmy);
 }
コード例 #5
0
ファイル: ArmyTests.cs プロジェクト: neraath/YeOldeTdd
 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 };
 }
コード例 #6
0
ファイル: ArmyTests.cs プロジェクト: neraath/YeOldeTdd
        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);
        }