public void containerAddNullChildReturnsNull()
    {
      Container container = new Container("chest");
      var item = container.AddChild(null);

      Assert.That(item, Is.Null);
    }
    public void containerHasChildrenReturnsTrueIfChildren()
    {
      Container container = new Container("chest");
      var entity = new Thing("cup");
      var item = container.AddChild(entity);

      Assert.That(container.HasChildren(), Is.True);
    }
    public void containerAddChildReturnsChild()
    {
      Container container = new Container("chest");
      var entity = new Thing("cup");
      var item = container.AddChild(entity);

      Assert.That(item.SameIdentityAs(entity), Is.True);
    }
    public void containerGetChildrenReturnsChildren()
    {
      Container container = new Container("chest");
      var entity = new Thing("cup");
      var item = container.AddChild(entity);

      var children = container.GetChildren();
      Assert.That(children.First().SameIdentityAs(item), Is.True);
    }
    public List<IEntity> Parse(string objectString)
    {
      ObjectText = objectString;
      Objects = new List<IEntity>();

      if (objectString == string.Empty)
      {
        return Objects;
      }

      string[] objectArray = objectString.Split(new string[] { Settings.ObjectDelimiter}, StringSplitOptions.RemoveEmptyEntries);

      foreach (var s in objectArray)
      {
        var attributes = getObjectAttributes(s);

        var sName = attributes != string.Empty ? s.Replace(attributes, string.Empty) : s;
        IEntity entity = null;

        if (attributes != string.Empty)
        {
          attributes = attributes.Replace("[", string.Empty).Replace("]", string.Empty);

          if (attributes.IndexOfAny("mM".ToCharArray()) != -1)
          {
            entity = new Person(sName);
            ((Person)entity).Gender = Gender.Male;
          }

          if (attributes.IndexOfAny("fF".ToCharArray()) != -1)
          {
            if (entity != null && entity.IsPerson())
              throw new PersonCannotBeTwoGenders();

            entity = new Person(sName);
            ((Person)entity).Gender = Gender.Female;
          }

          if (attributes.IndexOfAny("pP".ToCharArray()) != -1)
          {
            if (entity != null && entity.IsPerson())
              throw new PersonCannotBeTwoGenders();

            entity = new Person(sName);
            ((Person)entity).Gender = Gender.Neutral;
          }

          if (attributes.IndexOfAny("cC".ToCharArray()) != -1)
          {
            if (entity != null && entity.IsPerson())
              throw new PersonCannotBeContainer();

            entity = new Container(sName);
          }

          if (attributes.IndexOfAny("uU".ToCharArray()) != -1)
          {
            if (entity != null && entity.IsPerson())
              throw new PersonCannotBeSupporter();

            entity = new Supporter(sName);
          }

          if (attributes.IndexOfAny("sS".ToCharArray()) != -1)
          {
            if (entity != null && entity.IsPerson())
            {
              throw new PersonCannotBeScenery();
            }
            entity = new Thing(sName) {Scenery = true};
          }
        }
        else
        {
          entity = new Thing(sName);
        }

        Objects.Add(entity);

      }

      return Objects;
    }
    public void supporterHasChildrenReturnsFalseIfNoChildren()
    {
      Container container = new Container("chest");

      Assert.That(container.HasChildren(), Is.False);
    }
 public void containerCanNotWearItems()
 {
   Container container = new Container("chest");
   var testDel = new TestDelegate(() => container.WearItem(new Thing("hatband")));
   Assert.That(testDel, Throws.TypeOf<CanNotWearItemsException>());
 }
 public void testContainerIsNotThingType()
 {
   Container container = new Container("chest");
   Assert.That(container.IsThing, Is.False);
 }
 public void testContainerIsContainerType()
 {
   Container container = new Container("chest");
   Assert.That(container.IsContainer, Is.True);
 }
 public void testContainerIsNotSupporterType()
 {
   Container container = new Container("chest");
   Assert.That(container.IsSupporter, Is.False);
 }
 public void testContainerIsNotPersonType()
 {
   Container container = new Container("chest");
   Assert.That(container.IsPerson, Is.False);
 }