public void TestMethod_VerifyInitialPossibleMoves() { // Configure players player1.Active = true; player2.Active = false; // Set reference to active player NetworkBackgammonPlayer activePlayer = player1.Active ? player1 : player2; // Loop through all possible dice combinations foreach (NetworkBackgammonDice.DiceValue diceValueOne in Enum.GetValues(typeof(NetworkBackgammonDice.DiceValue))) { if (diceValueOne >= NetworkBackgammonDice.DiceValue.MIN && diceValueOne <= NetworkBackgammonDice.DiceValue.MAX) { foreach (NetworkBackgammonDice.DiceValue diceValueTwo in Enum.GetValues(typeof(NetworkBackgammonDice.DiceValue))) { if (diceValueTwo >= NetworkBackgammonDice.DiceValue.MIN && diceValueTwo <= NetworkBackgammonDice.DiceValue.MAX) { // Set (not random) dice values dice[0].CurrentValue = diceValueOne; dice[1].CurrentValue = diceValueTwo; bool activePlayerHasPossibleMoves = NetworkBackgammonGameEngine.CalculatePossibleMoves( ref player1, ref player2, dice); Assert.IsTrue(activePlayerHasPossibleMoves, "Active player should always have possible moves after the winning the initial dice roll"); Stream stream = GetManifestResourceStreamByName("InitialCheckers_" + (dice[0].CurrentValueUInt32 <= dice[1].CurrentValueUInt32 ? dice[0].CurrentValueUInt32.ToString() : dice[1].CurrentValueUInt32.ToString()) + "_" + (dice[1].CurrentValueUInt32 >= dice[0].CurrentValueUInt32 ? dice[1].CurrentValueUInt32.ToString() : dice[0].CurrentValueUInt32.ToString()) + ".xml"); Assert.IsNotNull(stream, "Data (XML) for verification comparison purposes is missing"); List <NetworkBackgammonChecker> checkersVerified = LoadCheckersFromXMLFile(stream); string checkerVerificationMessage = ""; bool checkerVerificationResult = VerifyCheckersAndPossibleMoves(activePlayer.Checkers, checkersVerified, ref checkerVerificationMessage); Assert.IsTrue(checkerVerificationResult, "Possible moves of active player for initial dice roll of " + dice[0] + ", " + dice[1] + " incorrect. Detail: " + checkerVerificationMessage); } } } } }
public void TestMethod_VBC_PossibleMovesCalculations_NullDice() { try { player1.Active = true; player2.Active = false; // Should throw a NetworkBackgammonGameEngineException bool retVal = NetworkBackgammonGameEngine.CalculatePossibleMoves(ref player1, ref player2, null); Assert.Fail("Calculation of possible moves returned ( " + retVal + " but should have thrown a NetworkBackgammonGameEngineException instead"); } catch (NetworkBackgammonGameEngineException) { // TODO: Check the details of the exception } }
public void TestMethod_VBC_PossibleMovesCalculations_InvalidDice() { try { player1.Active = true; player2.Active = false; dice[0].CurrentValue = NetworkBackgammonDice.DiceValue.MIN; dice[1].CurrentValue = NetworkBackgammonDice.DiceValue.INVALID; // Should throw a NetworkBackgammonGameEngineException bool retVal = NetworkBackgammonGameEngine.CalculatePossibleMoves(ref player1, ref player2, dice); Assert.Fail("Calculation of possible moves returned ( " + retVal + " but should have thrown a NetworkBackgammonGameEngineException instead"); } catch (NetworkBackgammonGameEngineException) { // TODO: Check the details of the exception } }
public void TestMethod_VBC_PossibleMovesCalculations_ZeroDice() { try { player1.Active = true; player2.Active = false; // Create dice array with 0 elements NetworkBackgammonDice[] diceForTest = new NetworkBackgammonDice[] { }; // Should throw a NetworkBackgammonGameEngineException bool retVal = NetworkBackgammonGameEngine.CalculatePossibleMoves(ref player1, ref player2, diceForTest); Assert.Fail("Calculation of possible moves returned ( " + retVal + " but should have thrown a NetworkBackgammonGameEngineException instead"); } catch (NetworkBackgammonGameEngineException) { // TODO: Check the details of the exception } }