Exemple #1
0
        public Commitment CommitToAnInventory(IInventory targetInventory, ItemType itemType, int amount)
        {
            if (!_currentAmount.ContainsKey(itemType))
            {
                throw new CommitmentException("Cannot commit because inventory does not contain this type");
            }
            if (GetCurrentUncommittedAmount(itemType) < amount)
            {
                throw new CommitmentException("Cannot commit because inventory does not contain enough of this type");
            }
            if (!targetInventory.CanAcceptAmount(itemType, amount))
            {
                throw new CommitmentException("Cannot commit because target inventory does not have enough space");
            }

            Commitment newCommitment = new Commitment(amount, itemType, targetInventory, this);

            newCommitment.CommitToComitterAndComitee();
            var merged = Commitment.MergeCommitmentsOfThisType(itemType, this, targetInventory);

            return(merged);
        }