Пример #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);
        }
Пример #2
0
        public void PlayerLookMethodReturnsAppropriateText()
        {
            var name           = "Testy Tess";
            var player         = new Player(name);
            var viewedLocation = new MockLocation("Test Area");

            player.Location = viewedLocation;

            //player displays correct text for location as view target
            Assert.Equal(player.Name + " looks around...", player.Look("").ToString());

            //player displays correct text when looking at an Actor as view target
            var viewedActorTargetName = "View Target";
            var viewedActorTarget     = new MockActorTarget(viewedActorTargetName);

            player.Location.Actors.Add(viewedActorTarget);

            Assert.Equal(player.Name + " looks at " + viewedActorTarget.Name, player.Look(viewedActorTargetName).ToString());
        }
Пример #3
0
        public void PlayerMoveMethodReturnsAppropriateText()
        {
            var name                = "Testy Tess";
            var player              = new Player(name);
            var startLocation       = new MockLocation("Start Area");
            var destinationLocation = new MockLocation("Destination Area");

            player.Location         = startLocation;
            startLocation.ExitNorth = destinationLocation;

            //move to exit without link to new location
            Assert.Equal(player.Name + " cannot move there!", player.Move("south").ToString());
            player.Location = startLocation;

            //no target given
            Assert.Equal(player.Name + " cannot move there!", player.Move("").ToString());
            player.Location = startLocation;

            //move to exit with link to new location
            Assert.Equal(player.Name + " moves...", player.Move("north").ToString());
        }
Пример #4
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);
        }