示例#1
0
        public void EXTRA_HitByBomb_ShouldIncreaseNumberOfBombsOnEachHit()
        {
            //Arrange
            GridCoordinate coordinate = new GridCoordinateBuilder().Build();
            GridSquare     square     = new GridSquare(coordinate);

            //Act
            int numberOfHits = RandomGenerator.Next(4, 11);

            for (int i = 0; i < numberOfHits; i++)
            {
                square.HitByBomb();
            }

            //Assert
            Assert.That(square.NumberOfBombs, Is.EqualTo(numberOfHits),
                        $"The number of bombs after one hit should be {numberOfHits} after calling HitByBomb {numberOfHits} times.");
        }
示例#2
0
        public void HitByBomb_ShouldRegisterTheHitAsAMissAndInvokeTheOnHitByBombEvent()
        {
            //Arrange
            GridCoordinate coordinate = new GridCoordinateBuilder().Build();
            GridSquare     square     = new GridSquare(coordinate);

            square.OnHitByBomb += Square_OnHitByBomb;

            //Act
            square.HitByBomb();

            //Assert
            Assert.That(square.NumberOfBombs, Is.EqualTo(1), "The number of bombs after one hit should be 1.");
            Assert.That(square.Status, Is.EqualTo(GridSquareStatus.Miss),
                        "When a square is hit by a bomb it gets the Status Miss " +
                        "(This Status can change after invoking the OnHitByBomb event).");
            Assert.That(_onHitByBombEventTriggered, Is.True,
                        "The OnHitByBomb event is not invoked. " +
                        "You can invoke the event with this statement: 'OnHitByBomb?.Invoke(this);'.");
        }
        private IGrid ArrangeGrid()
        {
            var gridMock = new Mock <IGrid>();
            int size     = RandomGenerator.Next(5, 11);

            gridMock.SetupGet(g => g.Size).Returns(size);
            var squares = new GridSquare[size, size];

            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    var square       = new GridSquare(new GridCoordinate(i, j));
                    int numberOfHits = RandomGenerator.Next(0, 3);
                    for (int k = 0; k < numberOfHits; k++)
                    {
                        square.HitByBomb();
                    }
                    squares[i, j] = square;
                }
            }
            gridMock.SetupGet(g => g.Squares).Returns(squares);
            return(gridMock.Object);
        }