I've got this method:
/// <summary>
/// Moves piece to location, does not verify that this is a valid move
/// </summary>
/// <param name="dest"></param>
public virtual void Move(Coordinate dest)
{
if (Board.IsPieceAtLocation(dest))
{
if (GetAllPossibleKills().Any(p => p.BoardLocation == dest))
{
Board.KillPieceAtLocation(dest);
}
else
{
throw new LocationOccupiedException("Board location already occupied and kill is not valid",this, Board.GetPieceAtLocation(dest));
}
}
BoardLocation = dest;
}
And it's covered by two unit tests:
[Test]
public void LocationOccupiedTest()
{
Board board = new Board();
board.GenerateNewGamePieces();
Assert.Throws<LocationOccupiedException>(()=>board.GetKing(false).Move(new Coordinate(0,0)));
}
[Test]
public void KillPieceTest()
{
Board board = new Board();
board.GenerateNewGamePieces();
Piece knight = board.GetPieceAtLocation(new Coordinate(1, 0));
knight.Move(new Coordinate(1,4));
Assert.DoesNotThrow(()=>knight.Move(new Coordinate(0,6)));
}
According to the coverage analysis, the whole method is covered except for:
if (GetAllPossibleKills().Any(p => p.BoardLocation == dest))
You can see the coverage status next to each line of code:
I don't understand how that can be the case given both branches of the if statement are traversed.
How can I get this covered?
