public void TestGetPositionsInTheWayOfMoveMethod( char initialHorizontal, int initialVertical, char targetHorizontal, int targetVertical, object[] positionsInTheWayOfMove) { List <Tuple <char, int> > positions = new List <Tuple <char, int> >(); if (positionsInTheWayOfMove != null) { for (int i = 0; i < positionsInTheWayOfMove.Length; i++) { if (i % 2 == 0) { positions.Add(new Tuple <char, int>((char)positionsInTheWayOfMove[i], (int)positionsInTheWayOfMove[i + 1])); } } } var getPositionsInTheWayOfMoveMethod = this.QueenType.GetMethod("GetPositionsInTheWayOfMove"); var normalChessMoveType = ChessGameLogicProvider.GetType("ChessGameLogic.ChessMoves.NormalChessMovePositions"); var chessBoardPositionType = ChessGameLogicProvider.GetType("ChessGameLogic.ChessBoardPosition"); var move = normalChessMoveType.GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic)[0] .Invoke(new object[] { initialHorizontal, initialVertical, targetHorizontal, targetVertical, }); var actualPositionsInTheWayOfMove = (ICollection)getPositionsInTheWayOfMoveMethod.Invoke(this.QueenInstance, new object[] { move }); if (positionsInTheWayOfMove == null) { Assert.IsNull(actualPositionsInTheWayOfMove); } else { Assert.AreEqual(positions.Count, actualPositionsInTheWayOfMove.Count); foreach (var postition in positions) { bool actualPositionsContainCurrentExpectedPosition = false; foreach (var actualPosition in actualPositionsInTheWayOfMove) { var actualHorizontal = (char)chessBoardPositionType .GetProperty("Horizontal", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(actualPosition); var actualVertical = (int)chessBoardPositionType .GetProperty("Vertical", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(actualPosition); if (actualHorizontal == postition.Item1 && actualVertical == postition.Item2) { actualPositionsContainCurrentExpectedPosition = true; break; } } Assert.That(actualPositionsContainCurrentExpectedPosition); } } }
public void TestAreMovePositionsPossibleMethod( char initialHorizontal, int initialVertical, char targetHorizontal, int targetVertical, bool isValid) { var arePositionsPossibleMethod = this.QueenType.GetMethod("AreMovePositionsPossible"); var normalChessMoveType = ChessGameLogicProvider.GetType("ChessGameLogic.ChessMoves.NormalChessMovePositions"); var chessBoardPositionType = ChessGameLogicProvider.GetType("ChessGameLogic.ChessBoardPosition"); var move = normalChessMoveType.GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic)[0] .Invoke(new object[] { initialHorizontal, initialVertical, targetHorizontal, targetVertical, }); var actualResult = arePositionsPossibleMethod.Invoke(this.QueenInstance, new object[] { move }); Assert.AreEqual(isValid, actualResult); }
public void TestIsPositionProducableMethod( char positionHorizontal, int positionVertical, ChessColors pawnColor, bool isProducable) { var isPositionProducableMethod = this.PawnType.GetMethod( "IsPositionProducable", BindingFlags.Instance | BindingFlags.NonPublic); var chessBoardPositionType = ChessGameLogicProvider.GetType("ChessGameLogic.ChessBoardPosition"); bool isPositionProducableActualResult; if (pawnColor == ChessColors.Black) { isPositionProducableActualResult = (bool)isPositionProducableMethod.Invoke( this.BlackPawnInstance, new object[] { chessBoardPositionType.GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic).First().Invoke(new object[] { positionHorizontal, positionVertical }), }); } else { isPositionProducableActualResult = (bool)isPositionProducableMethod.Invoke( this.WhitePawnInstance, new object[] { chessBoardPositionType.GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic).First().Invoke(new object[] { positionHorizontal, positionVertical }), }); } Assert.AreEqual(isProducable, isPositionProducableActualResult); }
public KingTests() { this.KingType = ChessGameLogicProvider.GetType("ChessGameLogic.ChessFigures.King"); this.KingInstance = this.KingType.GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic) .First() .Invoke(new object[] { ChessColors.White }); }
public void TestValidatePosition(char horizontal, int verticlal, bool isValid) { var positionValidatorType = ChessGameLogicProvider.GetType("ChessGameLogic.Validations.PositionValidator"); var methodValidatePostition = positionValidatorType.GetMethod("ValidatePosition", BindingFlags.Static | BindingFlags.NonPublic); var actualValidationResult = (bool)methodValidatePostition .Invoke(null, new object[] { horizontal, verticlal }); Assert.That(isValid == actualValidationResult); }
public PawnTests() { this.PawnType = ChessGameLogicProvider.GetType("ChessGameLogic.ChessFigures.Pawn"); var constructor = this.PawnType.GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic) .First(); this.WhitePawnInstance = constructor .Invoke(new object[] { ChessColors.White }); this.BlackPawnInstance = constructor .Invoke(new object[] { ChessColors.Black }); }
public void TestChessBoardPositionInitialization(char horizontal, int vertical, bool isValid) { if (isValid == false) { Assert.That(() => this.ChessBoardPositionType.GetConstructors(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)[0].Invoke(new object[] { horizontal, vertical }), Throws.InnerException.InstanceOf(ChessGameLogicProvider.GetType("ChessGameLogic.Exceptions.PositionOutOfBoardException"))); } else { var chessBoardPositionInstance = this.ChessBoardPositionType.GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic)[0].Invoke(new object[] { horizontal, vertical }); var actualHorizontal = (char)this.ChessBoardPositionType .GetProperty("Horizontal", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(chessBoardPositionInstance); var actualVertical = (int)this.ChessBoardPositionType .GetProperty("Vertical", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(chessBoardPositionInstance); Assert.That(actualHorizontal == horizontal); Assert.That(actualVertical == vertical); } }
public void TestIsAttackingMovePossibleMethod( char initialHorizontal, int initialVertical, char targetHorizontal, int targetVertical, ChessColors pawnColor, bool isValid) { var isAttackingMovePossibleMethod = this.PawnType.GetMethod( "IsAttackingMovePossible", BindingFlags.Instance | BindingFlags.NonPublic); var normalChessMoveType = ChessGameLogicProvider.GetType("ChessGameLogic.ChessMoves.NormalChessMovePositions"); var move = normalChessMoveType.GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic)[0] .Invoke(new object[] { initialHorizontal, initialVertical, targetHorizontal, targetVertical, }); bool actualResult; if (pawnColor == ChessColors.White) { actualResult = (bool)isAttackingMovePossibleMethod.Invoke(this.WhitePawnInstance, new object[] { move }); } else { actualResult = (bool)isAttackingMovePossibleMethod.Invoke(this.BlackPawnInstance, new object[] { move }); } Assert.AreEqual(isValid, actualResult); }
public void TestNormalChessMoveSettingPositionsCorrect( char initialPositionHorizontal, int initialPositionVertical, char targetPositionHorizontal, int targetPositionVertical, bool isValid) { var normalChessMoveType = ChessGameLogicProvider.GetType("ChessGameLogic.ChessMoves.NormalChessMovePositions"); var chessBoardPositionType = ChessGameLogicProvider.GetType("ChessGameLogic.ChessBoardPosition"); if (isValid == false) { Assert.That( () => normalChessMoveType .GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic)[0] .Invoke(new object[] { initialPositionHorizontal, initialPositionVertical, targetPositionHorizontal, targetPositionVertical, }), Throws.InnerException.InstanceOf(ChessGameLogicProvider.GetType("ChessGameLogic.Exceptions.PositionOutOfBoardException"))); } else { var normalChessMoveInstance = normalChessMoveType.GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic)[0].Invoke(new object[] { initialPositionHorizontal, initialPositionVertical, targetPositionHorizontal, targetPositionVertical, }); var initialPosition = normalChessMoveType .GetProperty("InitialPosition", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(normalChessMoveInstance); var targetPosition = normalChessMoveType .GetProperty("TargetPosition", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(normalChessMoveInstance); var chessBoardPositionEqualsMethod = chessBoardPositionType.GetMethods() .Where(m => this.FilterMethod(m)) .First(); object initialChessBoardPositionInstance = chessBoardPositionType.GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic)[0] .Invoke(new object[] { initialPositionHorizontal, initialPositionVertical, }); Assert.That((bool)chessBoardPositionEqualsMethod .Invoke( initialPosition, new object[] { initialChessBoardPositionInstance, })); object targetChessBoardPositionInstance = chessBoardPositionType.GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic)[0] .Invoke(new object[] { targetPositionHorizontal, targetPositionVertical, }); Assert.That((bool)chessBoardPositionEqualsMethod .Invoke(targetPosition, new object[] { targetChessBoardPositionInstance })); } }