コード例 #1
0
ファイル: PlayerTest.cs プロジェクト: crhwebdev/console-rpg
        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
ファイル: PlayerTest.cs プロジェクト: crhwebdev/console-rpg
        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
ファイル: PlayerTest.cs プロジェクト: crhwebdev/console-rpg
        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
ファイル: PlayerTest.cs プロジェクト: crhwebdev/console-rpg
        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);
        }