Esempio n. 1
0
        public void Default()
        {
            // Arrange
            var character = Mock.Of <ICharacter>();
            EquipmentSection equipmentSection = new EquipmentSection(character);

            // Act
            var(ring1, ring2) = equipmentSection.Rings;

            // Assert
            Assert.IsNull(equipmentSection.Armor);
            Assert.IsNull(equipmentSection.Belt);
            Assert.IsNull(equipmentSection.Body);
            Assert.IsNull(equipmentSection.Chest);
            Assert.IsNull(equipmentSection.Eyes);
            Assert.IsNull(equipmentSection.Feet);
            Assert.IsNull(equipmentSection.Hands);
            Assert.IsNull(equipmentSection.Head);
            Assert.IsNull(equipmentSection.Headband);
            Assert.IsNull(equipmentSection.Neck);
            Assert.IsNull(ring1);
            Assert.IsNull(ring2);
            Assert.IsNull(equipmentSection.Shield);
            Assert.IsNull(equipmentSection.Shoulders);
            Assert.IsNull(equipmentSection.Spellbook);
            Assert.IsNull(equipmentSection.Wrists);
            Assert.IsEmpty(equipmentSection.GetInventory());
        }
Esempio n. 2
0
        public void StowIStowable_Null_Throws()
        {
            // Arrange
            var character = Mock.Of <ICharacter>();
            EquipmentSection equipmentSection = new EquipmentSection(character);
            IStowable        item             = null;

            // Act
            TestDelegate stow = () => equipmentSection.Stow(item);

            // Assert
            Assert.Throws <ArgumentNullException>(stow);
        }
Esempio n. 3
0
        public void EquipShoulders_Null_Throws()
        {
            // Arrange
            var character = Mock.Of <ICharacter>();
            EquipmentSection equipmentSection = new EquipmentSection(character);
            IShouldersSlot   shoulders        = null;

            // Act
            TestDelegate equip = () => equipmentSection.Equip(shoulders);

            // Assert
            Assert.Throws <ArgumentNullException>(equip);
        }
Esempio n. 4
0
        public void EquipHeadband_Null_Throws()
        {
            // Arrange
            var character = Mock.Of <ICharacter>();
            EquipmentSection equipmentSection = new EquipmentSection(character);
            IHeadbandSlot    headband         = null;

            // Act
            TestDelegate equip = () => equipmentSection.Equip(headband);

            // Assert
            Assert.Throws <ArgumentNullException>(equip);
        }
Esempio n. 5
0
        public void EquipRing_Null_Throws()
        {
            // Arrange
            var character = Mock.Of <ICharacter>();
            EquipmentSection equipmentSection = new EquipmentSection(character);
            IRingSlot        ring             = null;

            // Act
            TestDelegate equip = () => equipmentSection.Equip(ring);

            // Assert
            Assert.Throws <ArgumentNullException>(equip);
        }
Esempio n. 6
0
        public void EquipArmor_Twice_Throws()
        {
            // Arrange
            var character = Mock.Of <ICharacter>();
            var armor     = Mock.Of <IArmorSlot>();
            EquipmentSection equipmentSection = new EquipmentSection(character);

            // Act
            TestDelegate equip = () => equipmentSection.Equip(armor);

            // Assert
            Assert.DoesNotThrow(equip);                       // No exception is thrown the first time
            Assert.Throws <InvalidOperationException>(equip); // Throws the second time
        }
Esempio n. 7
0
        public void StowIStowable_Twice_Throws()
        {
            // Arrange
            var character = Mock.Of <ICharacter>();
            var item      = Mock.Of <IStowable>();
            EquipmentSection equipmentSection = new EquipmentSection(character);

            // Act
            TestDelegate stow = () => equipmentSection.Stow(item);

            // Assert
            Assert.DoesNotThrow(stow);                       // No exception is thrown the first time
            Assert.Throws <InvalidOperationException>(stow); // Throws the second time
        }
Esempio n. 8
0
        public void EquipWrists_HappyPath()
        {
            // Arrange
            var character = Mock.Of <ICharacter>();
            var wrists    = Mock.Of <IWristsSlot>();
            EquipmentSection equipmentSection = new EquipmentSection(character);

            // Act
            equipmentSection.Equip(wrists);

            // Assert
            Assert.AreSame(wrists, equipmentSection.Wrists,
                           "Equipping wrists should create a reference in the equipment section's Wrists slot.");
            Mock.Get(wrists)
            .Verify(w => w.ApplyTo(It.Is <ICharacter>(c => c == character)),
                    "Equipping the item should call the item's .ApplyTo method, passing in the character as an argument.");
        }
Esempio n. 9
0
        public void EquipShield_HappyPath()
        {
            // Arrange
            var character = Mock.Of <ICharacter>();
            var shield    = Mock.Of <IShieldSlot>();
            EquipmentSection equipmentSection = new EquipmentSection(character);

            // Act
            equipmentSection.Equip(shield);

            // Assert
            Assert.AreSame(shield, equipmentSection.Shield,
                           "Equipping a shield should create a reference in the equipment section's Shield slot.");
            Mock.Get(shield)
            .Verify(s => s.ApplyTo(It.Is <ICharacter>(c => c == character)),
                    "Equipping the item should call the item's .ApplyTo method, passing in the character as an argument.");
        }
Esempio n. 10
0
        public void EquipNeck_HappyPath()
        {
            // Arrange
            var character = Mock.Of <ICharacter>();
            var neck      = Mock.Of <INeckSlot>();
            EquipmentSection equipmentSection = new EquipmentSection(character);

            // Act
            equipmentSection.Equip(neck);

            // Assert
            Assert.AreSame(neck, equipmentSection.Neck,
                           "Equipping a neck should create a reference in the equipment section's Neck slot.");
            Mock.Get(neck)
            .Verify(n => n.ApplyTo(It.Is <ICharacter>(c => c == character)),
                    "Equipping the item should call the item's .ApplyTo method, passing in the character as an argument.");
        }
Esempio n. 11
0
        public void EquipHeadband_HappyPath()
        {
            // Arrange
            var character = Mock.Of <ICharacter>();
            var headband  = Mock.Of <IHeadbandSlot>();
            EquipmentSection equipmentSection = new EquipmentSection(character);

            // Act
            equipmentSection.Equip(headband);

            // Assert
            Assert.AreSame(headband, equipmentSection.Headband,
                           "Equipping a headband should create a reference in the equipment section's Headband slot.");
            Mock.Get(headband)
            .Verify(h => h.ApplyTo(It.Is <ICharacter>(c => c == character)),
                    "Equipping the item should call the item's .ApplyTo method, passing in the character as an argument.");
        }
Esempio n. 12
0
        public void EquipFeet_HappyPath()
        {
            // Arrange
            var character = Mock.Of <ICharacter>();
            var feet      = Mock.Of <IFeetSlot>();
            EquipmentSection equipmentSection = new EquipmentSection(character);

            // Act
            equipmentSection.Equip(feet);

            // Assert
            Assert.AreSame(feet, equipmentSection.Feet,
                           "Equipping feet should create a reference in the equipment section's Feet slot.");
            Mock.Get(feet)
            .Verify(f => f.ApplyTo(It.Is <ICharacter>(c => c == character)),
                    "Equipping the item should call the item's .ApplyTo method, passing in the character as an argument.");
        }
Esempio n. 13
0
        public void StowSpellbook_HappyPath()
        {
            // Arrange
            var character = Mock.Of <ICharacter>();
            var spellbook = Mock.Of <ISpellbook>();
            EquipmentSection equipmentSection = new EquipmentSection(character);

            // Act
            equipmentSection.Stow(spellbook);

            // Assert
            Assert.AreSame(spellbook, equipmentSection.Spellbook,
                           "Stowing a spellbook should create a reference in the equipment section's Spellbook slot.");
            Mock.Get(spellbook)
            .Verify(s => s.ApplyTo(It.Is <ICharacter>(c => c == character)),
                    "Stowing the item should call the item's .ApplyTo method, passing in the character as an argument.");
        }
Esempio n. 14
0
        public void EquipArmor_HappyPath()
        {
            // Arrange
            var character = Mock.Of <ICharacter>();
            var armor     = Mock.Of <IArmorSlot>();
            EquipmentSection equipmentSection = new EquipmentSection(character);

            // Act
            equipmentSection.Equip(armor);

            // Assert
            Assert.AreSame(armor, equipmentSection.Armor,
                           "Equipping armor should create a reference in the equipment section's Armor slot.");
            Mock.Get(armor)
            .Verify(a => a.ApplyTo(It.Is <ICharacter>(c => c == character)),
                    "Equipping the item should call the item's .ApplyTo method, passing in the character as an argument.");
        }
Esempio n. 15
0
        public void EquipBody_HappyPath()
        {
            // Arrange
            var character = Mock.Of <ICharacter>();
            var body      = Mock.Of <IBodySlot>();
            EquipmentSection equipmentSection = new EquipmentSection(character);

            // Act
            equipmentSection.Equip(body);

            // Assert
            Assert.AreSame(body, equipmentSection.Body,
                           "Equipping a body should create a reference in the equipment section's Body slot.");
            Mock.Get(body)
            .Verify(b => b.ApplyTo(It.Is <ICharacter>(c => c == character)),
                    "Equipping the item should call the item's .ApplyTo method, passing in the character as an argument.");
        }
Esempio n. 16
0
        public void StowIStowable_HappyPath()
        {
            // Arrange
            var character = Mock.Of <ICharacter>();
            var item      = Mock.Of <IStowable>();
            EquipmentSection equipmentSection = new EquipmentSection(character);

            // Act
            equipmentSection.Stow(item);

            // Assert
            Assert.Contains(item, equipmentSection.GetInventory(),
                            "Stowing an item should create a reference in the equipment section's GetInventory collection.");
            Mock.Get(item)
            .Verify(i => i.ApplyTo(It.Is <ICharacter>(c => c == character)),
                    "Stowing the item should call the item's .ApplyTo method, passing in the character as an argument.");
        }
Esempio n. 17
0
        public void EquipingThirdRing_Throws()
        {
            // Arrange
            var character = Mock.Of <ICharacter>();
            var ring1     = Mock.Of <IRingSlot>();
            var ring2     = Mock.Of <IRingSlot>();
            var ring3     = Mock.Of <IRingSlot>();
            EquipmentSection equipmentSection = new EquipmentSection(character);

            // Act
            TestDelegate firstEquip  = () => equipmentSection.Equip(ring1);
            TestDelegate secondEquip = () => equipmentSection.Equip(ring2);
            TestDelegate thirdEquip  = () => equipmentSection.Equip(ring3);

            // Assert
            Assert.DoesNotThrow(firstEquip);                       // No exception is thrown the first time
            Assert.DoesNotThrow(secondEquip);                      // ...or the second time...
            Assert.Throws <InvalidOperationException>(thirdEquip); // But the third time is forbidden.
        }
Esempio n. 18
0
        public void EquipRings_HappyPath()
        {
            // Arrange
            var character = Mock.Of <ICharacter>();
            var ring1     = Mock.Of <IRingSlot>();
            var ring2     = Mock.Of <IRingSlot>();
            EquipmentSection equipmentSection = new EquipmentSection(character);

            // Act
            equipmentSection.Equip(ring1);
            equipmentSection.Equip(ring2);

            // Assert
            Assert.AreSame(ring1, equipmentSection.Rings.Item1,
                           "The first equipped ring should be stored in the first ring slot.");
            Assert.AreSame(ring2, equipmentSection.Rings.Item2,
                           "The second equipped ring should be stored in the first ring slot.");
            Mock.Get(ring1)
            .Verify(r => r.ApplyTo(It.Is <ICharacter>(c => c == character)),
                    "Equipping the item should call the item's .ApplyTo method, passing in the character as an argument.");
            Mock.Get(ring2)
            .Verify(r => r.ApplyTo(It.Is <ICharacter>(c => c == character)),
                    "Equipping the item should call the item's .ApplyTo method, passing in the character as an argument.");
        }