예제 #1
0
        public void ShootAtOpponent_ShouldReturnAMisfireWhenNoBombsAreLoaded()
        {
            //Arrange
            GridCoordinate targetCoordinate = new GridCoordinateBuilder().Build();

            _player2Builder.WithBombsLoaded(false);
            Mock <IPlayer> player2Mock = _player2Builder.BuildMock();

            _game.Start();

            //Act
            ShotResult result = _game.ShootAtOpponent(_player2.Id, targetCoordinate);

            player2Mock.Verify(p => p.ShootAt(It.IsAny <IPlayer>(), It.IsAny <GridCoordinate>()), Times.Never,
                               "The ShootAt method of the player that shoots should not be called when no bombs are loaded.");
            Assert.That(result.ShotFired, Is.False, "The ShotResult should indicate that no shot is fired.");
            Assert.That(result.MisfireReason, Is.Not.Empty, "The ShotResult should contain a misfire reason.");
        }
예제 #2
0
        public void ShootAtOpponent_ShouldUseTheShootAtMethodOfThePlayer()
        {
            //Arrange
            GridCoordinate targetCoordinate = new GridCoordinateBuilder().Build();

            _player1Builder.WithBombsLoaded(true);

            ShotResult     expectedShotResult = ShotResult.CreateMissed();
            Mock <IPlayer> player1Mock        = _player1Builder.BuildMock();

            player1Mock.Setup(p => p.ShootAt(It.IsAny <IPlayer>(), It.IsAny <GridCoordinate>()))
            .Returns(expectedShotResult);

            _game.Start();

            //Act
            ShotResult result = _game.ShootAtOpponent(_player1.Id, targetCoordinate);

            player1Mock.Verify(p => p.ShootAt(_player2, targetCoordinate), Times.Once,
                               "The ShootAt method of the player that shoots is not called correctly.");
            Assert.That(result, Is.SameAs(expectedShotResult), "The ShotResult returned by the ShootAt method should be returned.");
        }