Ejemplo n.º 1
0
        public void MaxWeightRestrictionWorks()
        {
            WetPaperBag   bag    = new WetPaperBag();
            AddItemStatus actual = bag.AddItem(new GreatAxe());

            Assert.AreEqual(AddItemStatus.ContainerOverWeight, actual);
        }
Ejemplo n.º 2
0
        public void ItemTypeRestriction()
        {
            ItemTypeRestriction restriction = new ItemTypeRestriction(ItemType.Weapon);
            AddItemStatus       result      = restriction.AddItem(new HealthPotion(), null);

            Assert.AreEqual(AddItemStatus.ItemWrongType, result);
        }
Ejemplo n.º 3
0
        public void CanAddItemToBackpack()
        {
            Backpack     b = new Backpack();
            HealthPotion p = new HealthPotion();

            AddItemStatus actual = b.AddItem(p);

            Assert.AreEqual(AddItemStatus.Ok, actual);
        }
Ejemplo n.º 4
0
        public void CannotAddNonPoitionsToPotionSatchel()
        {
            PotionSatchel container     = new PotionSatchel();
            GreatAxe      wrongItemType = new GreatAxe();

            AddItemStatus result = container.AddItem(wrongItemType);

            Assert.AreEqual(result, AddItemStatus.ItemWrongType);
        }
Ejemplo n.º 5
0
        public AddItemStatus CheckRule(Container addTo, Item toAdd)
        {
            AddItemStatus result = AddItemStatus.ItemWrongType;

            if (toAdd.Type == RestrictionType)
            {
                result = AddItemStatus.Ok;
            }
            return(result);
        }
Ejemplo n.º 6
0
        public AddItemStatus CheckRule(Container addTo, Item toAdd)
        {
            AddItemStatus result = AddItemStatus.ContainerFull;

            if (addTo.Capacity > addTo.CurrentIndex)
            {
                result = AddItemStatus.Ok;
            }

            return(result);
        }
Ejemplo n.º 7
0
        public void PotionSatchelOnlyAllowsPotions()
        {
            PotionSatchel ps  = new PotionSatchel();
            GreatAxe      axe = new GreatAxe();
            HealthPotion  p   = new HealthPotion();

            AddItemStatus result = ps.AddItem(axe);

            Assert.AreEqual(AddItemStatus.ItemNotRightType, result);

            result = ps.AddItem(p);
            Assert.AreEqual(AddItemStatus.Success, result);
        }
Ejemplo n.º 8
0
        public void PotionSatchelOnlyAllowsPotions()
        {
            PotionSatchel satchel    = new PotionSatchel();
            Sword         steelsword = new Sword();

            AddItemStatus result = satchel.AddItem(steelsword);

            Assert.AreEqual(AddItemStatus.ItemNotRightType, result);

            HealthPotion potion = new HealthPotion();

            result = satchel.AddItem(potion);
            Assert.AreEqual(AddItemStatus.Success, result);
        }
Ejemplo n.º 9
0
        public void CannotAddItemToFullBackpack()
        {
            Backpack b          = new Backpack();
            Sword    steelSword = new Sword();

            b.AddItem(steelSword);
            b.AddItem(steelSword);
            b.AddItem(steelSword);
            b.AddItem(steelSword);

            AddItemStatus actual = b.AddItem(steelSword);

            Assert.AreEqual(AddItemStatus.BagIsFull, actual);
        }
        public void PotionSatchelOnlyAllowsPotions()
        {
            PotionSatchel satchel = new PotionSatchel();
            TurtleArmor   armor   = new TurtleArmor();

            AddItemStatus result = satchel.AddItem(armor);

            Assert.AreEqual(AddItemStatus.ItemNotRightType, result);

            HealthPotion potion = new HealthPotion();

            result = satchel.AddItem(potion);
            Assert.AreEqual(AddItemStatus.Success, result);
        }
Ejemplo n.º 11
0
        public void PotionSatchelOnlyAllowsPotions()
        {
            PotionSatchel satchel = new PotionSatchel();
            GreatAxe      axe     = new GreatAxe();

            AddItemStatus result = satchel.AddItem(axe);

            Assert.AreEqual(AddItemStatus.ItemWrongType, result);

            HealthPotion potion = new HealthPotion();

            result = satchel.AddItem(potion);
            Assert.AreEqual(AddItemStatus.Success, result);
        }
Ejemplo n.º 12
0
        public override AddItemStatus AddItem(Item itemToAdd)
        {
            if (_currentWeight + itemToAdd.Weight > _maxWeight)
            {
                return(AddItemStatus.ItemTooHeavy);
            }
            AddItemStatus status = base.AddItem(itemToAdd);

            if (status == AddItemStatus.Success)
            {
                _currentWeight += itemToAdd.Weight;
            }
            return(status);
        }
Ejemplo n.º 13
0
 public virtual AddItemStatus AddItem(Item itemToAdd)
 {
     foreach (var restriction in _restrictions)
     {
         AddItemStatus result = restriction.AddItem(itemToAdd, this);
         if (result != AddItemStatus.Ok)
         {
             return(result);
         }
     }
     Items[CurrentIndex] = itemToAdd;
     CurrentIndex++;
     return(AddItemStatus.Ok);
 }
Ejemplo n.º 14
0
        public void CannotAddItemToFullBackpack()
        {
            Backpack b   = new Backpack();
            GreatAxe axe = new GreatAxe();

            b.AddItem(axe);
            b.AddItem(axe);
            b.AddItem(axe);
            b.AddItem(axe);

            AddItemStatus actual = b.AddItem(axe);

            Assert.AreEqual(AddItemStatus.BagIsFull, actual);
        }
Ejemplo n.º 15
0
        public void CannotAddItemToFullBackpack()
        {
            Backpack p = new Backpack();
            GreatAxe g = new GreatAxe();

            p.AddItem(g);
            p.AddItem(g);
            p.AddItem(g);
            p.AddItem(g);

            AddItemStatus actual = p.AddItem(g);

            Assert.AreEqual(AddItemStatus.ContainerFull, actual);
        }
        public void CannotAddItemToFullBackpack()
        {
            Backpack    b     = new Backpack();
            TurtleArmor armor = new TurtleArmor();

            b.AddItem(armor);
            b.AddItem(armor);
            b.AddItem(armor);
            b.AddItem(armor);

            AddItemStatus actual = b.AddItem(armor);

            Assert.AreEqual(AddItemStatus.BagIsFull, actual);
        }
Ejemplo n.º 17
0
        public AddItemStatus CheckRule(Container addTo, Item toAdd)
        {
            var items         = addTo.Items.Where(w => w != null);
            int currentWeight = 0;

            if (items.Any())
            {
                currentWeight = items.Sum(s => s.Weight);
            }

            var proposedWeight = currentWeight + toAdd.Weight;

            AddItemStatus result = AddItemStatus.ContainerOverweight;

            if (proposedWeight <= MaxWeight)
            {
                result = AddItemStatus.Ok;
            }

            return(result);
        }