Exemplo n.º 1
0
        public void PlayerGetMethodReturnsAppropriateText()
        {
            var name           = "Testy Tess";
            var player         = new Player(name);
            var playerLocation = new MockLocation("Test Area");
            var itemTargetName = "Thing";
            var itemTarget     = new MockItemTarget(itemTargetName);

            itemTarget.Location = playerLocation;

            player.Location = playerLocation;
            playerLocation.Items.Add(itemTarget);

            // player displays correct error message when passing empty target string
            var playerGetText = player.Get("").ToString();

            Assert.Equal("There is nothing to get!", playerGetText);

            //player displays correct error message when getting an item that doesn't exist
            playerGetText = player.Get("wtf").ToString();
            Assert.Equal("You cannot get that!", playerGetText);

            // player displays correct text when getting item
            playerGetText = player.Get(itemTargetName).ToString();
            Assert.Equal(player.Name + " gets the " + itemTarget.Name, playerGetText);

            // player successfully removed item from location
            Assert.Empty(playerLocation.Items);

            // item's Location is set to null
            Assert.Null(itemTarget.Location);

            // player succesfully added item to inventory
            Assert.Single(player.Inventory, itemTarget);
        }
Exemplo n.º 2
0
        public void PlayerDropMethodReturnsAppropriateText()
        {
            var name           = "Testy Tess";
            var player         = new Player(name);
            var playerLocation = new MockLocation("Test Area");
            var itemTargetName = "Thing";
            var itemTarget     = new MockItemTarget(itemTargetName);

            player.Location = playerLocation;
            player.Inventory.Add(itemTarget);

            // player displays correct error message when passing empty target string
            var playerDropText = player.Drop("").ToString();

            Assert.Equal("There is nothing to drop!", playerDropText);

            //player displays correct error message when getting an item that doesn't exist
            playerDropText = player.Drop("wtf").ToString();
            Assert.Equal("You don't have that item!", playerDropText);

            // player displays correct text when dropping item
            playerDropText = player.Drop(itemTargetName).ToString();
            Assert.Equal(player.Name + " drops the " + itemTarget.Name, playerDropText);

            // player successfully removes item from inventory
            Assert.Empty(player.Inventory);

            // Item Location is set to area Location
            Assert.Equal(playerLocation, itemTarget.Location);

            // player succesfully adds item to Location.Items list
            Assert.Single(playerLocation.Items, itemTarget);

            // sends correct error message if player tries to drop an item that is equiped
            player.EquipSlotMainWeapon = itemTarget;

            playerDropText = player.Drop(itemTargetName).ToString();

            Assert.Equal("You cannot drop an equiped item!", playerDropText);
        }