コード例 #1
0
    public void TestIfHeroGainXP()
    {
        IWeapon weapon = new FakeWeapon();
        ITarget target = new FakeTarget();

        Hero hero = new Hero("Pesho", weapon);

        hero.Attack(target);

        int expectedResult = 10;
        int actualResult   = hero.Experience;

        Assert.AreEqual(expectedResult, actualResult, "The value of gained XP is not correct!");
    }
コード例 #2
0
    public void HeroGainsExperienceAfterAttackIfTargetDies()
    {
        // Arrange
        ITarget fakeTarget = new FakeTarget();
        IWeapon fakeWeapon = new FakeWeapon();
        Hero    hero       = new Hero(HeroName, fakeWeapon);

        // Act
        hero.Attack(fakeTarget);
        int expectedExperience = fakeTarget.GiveExperience();

        // Assert
        Assert.AreEqual(expectedExperience, hero.Experience);
    }
コード例 #3
0
    public void AttackShouldNotChangeHeroExperienceWhenTargetIsAlive()
    {
        // Arrange
        var target     = new Dummy(DeadTargetHealth + HealthIncrement, TargetExperience);
        var fakeWeapon = new FakeWeapon(WeaponAttackPoints, WeaponDurability);

        this.hero = new Hero(HeroName, fakeWeapon);

        // Act
        this.hero.Attack(target);

        // Assert
        Assert.AreEqual(this.heroInitialExperience, this.hero.Experience,
                        "Hero experience should not change!");
    }
コード例 #4
0
    public void AttackShouldAddTargetExperienceToHeroExperienceWhenTargetIsDead()
    {
        // Arrange
        var fakeTarget = new FakeDeadTarget(TargetExperience);
        var fakeWeapon = new FakeWeapon(WeaponAttackPoints, WeaponDurability);

        this.hero = new Hero(HeroName, fakeWeapon);

        // Act
        this.hero.Attack(fakeTarget);

        // Assert
        Assert.AreEqual(this.heroInitialExperience + TargetExperience, this.hero.Experience,
                        "Hero does not gain target experience!");
    }
コード例 #5
0
ファイル: UnitTest1.cs プロジェクト: jmarkova/ITCareer
        public void HeroGainsExperienceAfterAttackIfTargetDies()
        {
            // Arrange
            ITarget fakeTarget = new FakeTarget();
            IWeapon fakeWeapon = new FakeWeapon();
            Hero    hero       = new Hero(HeroName, fakeWeapon);

            // Act
            var xp = hero.Experience;

            hero.Attack(fakeTarget);

            // Assert
            Assert.IsTrue(hero.Experience > xp);
        }
コード例 #6
0
    public void Hero_Should_Get_Exp_If_The_Target_Is_Dead()
    {
        // WITH FAKE CLASSES!

        // Arrange
        var weapon = new FakeWeapon();
        var target = new FakeTarget();
        var hero   = new Hero("Stavri", weapon);

        // Act
        hero.Attack(target);

        // Assert
        Assert.That(hero.Experience, Is.EqualTo(FakeTarget.DEFAULT_EXP));
    }
コード例 #7
0
    public void HeroGainsExperienceAfterAttackIfTargetDies()
    {
        // Arrange
        ITarget fakeTarget = new FakeTarget();
        IWeapon fakeWeapon = new FakeWeapon();

        Hero hero = new Hero(HeroName, fakeWeapon);

        // Act
        hero.Attack(fakeTarget);

        // Assert
        Assert.That(hero.Experience, Is.EqualTo(0));

        // Act
        hero.Attack(fakeTarget);

        // Assert
        Assert.That(hero.Experience, Is.EqualTo(fakeTarget.GiveExperience()));
    }
コード例 #8
0
    public void HeroShouldIncreaseExperienceIfTargetIsDead()
    {
        Hero hero = new Hero("Spiderman");

        int health     = 0;
        int experience = 40;

        FakeTarget fakeTarget = new FakeTarget(health, experience);

        int attackPoints     = 10;
        int durabilityPoints = 20;
        var givenXP          = fakeTarget.GiveExperience();

        //this.experience += target.GiveExperience();
        FakeWeapon fakeWeapon = new FakeWeapon(attackPoints, durabilityPoints);

        hero.Attack(fakeTarget);

        int expectedXP = 40 + givenXP;

        Assert.AreEqual(expectedXP, hero.Experience);
    }
コード例 #9
0
    public void AttackShouldNotChangeHeroExperienceWhenTargetIsAlive_Mock()
    {
        // Arrange
        var fakeTarget = new Mock <ITarget>();

        fakeTarget
        .Setup(t => t.IsDead())
        .Returns(false);
        fakeTarget
        .Setup(t => t.GiveExperience())
        .Callback(() => throw new InvalidOperationException("Dummy is dead."));

        var fakeWeapon = new FakeWeapon(WeaponAttackPoints, WeaponDurability);

        this.hero = new Hero(HeroName, fakeWeapon);

        // Act
        this.hero.Attack(fakeTarget.Object);

        // Assert
        Assert.AreEqual(this.heroInitialExperience, this.hero.Experience,
                        "Hero experience should not change!");
    }