public void Test_GetAllPlayers() { // Arrange TennisPlayerController controller = new TennisPlayerController(repo); // Act IHttpActionResult actionResult = controller.Players(); OkNegotiatedContentResult <List <Player> > contectResult = actionResult as OkNegotiatedContentResult <List <Player> >; //Assert Assert.IsNotNull(actionResult); Assert.IsNotNull(contectResult); Assert.IsNotNull(contectResult.Content); Assert.AreEqual(contectResult.Content.Count, players.Count); foreach (Player ply in contectResult.Content) { Player currentPlayer = players.Find(p => p.Id == ply.Id); if (currentPlayer != null) { Assert.AreEqual(currentPlayer.Id, ply.Id); Assert.AreEqual(currentPlayer.FirstName, ply.FirstName); Assert.AreEqual(currentPlayer.LastName, ply.LastName); Assert.AreEqual(currentPlayer.ShortName, ply.ShortName); Assert.AreEqual(currentPlayer.Picture, ply.Picture); Assert.AreEqual(currentPlayer.Sex, ply.Sex); Assert.AreEqual(currentPlayer.Country.Code, ply.Country.Code); Assert.AreEqual(currentPlayer.Country.Picture, ply.Country.Picture); Assert.AreEqual(currentPlayer.Data.Rank, ply.Data.Rank); Assert.AreEqual(currentPlayer.Data.Height, ply.Data.Height); Assert.AreEqual(currentPlayer.Data.Last.Length, ply.Data.Last.Length); Assert.AreEqual(currentPlayer.Data.Points, ply.Data.Points); Assert.AreEqual(currentPlayer.Data.Weight, ply.Data.Weight); Assert.AreEqual(currentPlayer.Data.Age, ply.Data.Age); } } }
public void Test_GetPlayerByIdReturnPlayerWithTheSameId() { // Arrange TennisPlayerController controller = new TennisPlayerController(repo); Player existedPlayer = players.Find(p => p.Id == existPlayerId); // Act IHttpActionResult actionResult = controller.Player(existPlayerId); OkNegotiatedContentResult <Player> contectResult = actionResult as OkNegotiatedContentResult <Player>; //Assert Assert.IsNotNull(actionResult); Assert.IsNotNull(contectResult); Assert.IsNotNull(contectResult.Content); Assert.AreEqual(existPlayerId, contectResult.Content.Id); Assert.AreEqual(contectResult.Content.Id, existedPlayer.Id); Assert.AreEqual(contectResult.Content.FirstName, existedPlayer.FirstName); Assert.AreEqual(contectResult.Content.LastName, existedPlayer.LastName); Assert.AreEqual(contectResult.Content.ShortName, existedPlayer.ShortName); Assert.AreEqual(contectResult.Content.Picture, existedPlayer.Picture); Assert.AreEqual(contectResult.Content.Sex, existedPlayer.Sex); Assert.AreEqual(contectResult.Content.Country.Code, existedPlayer.Country.Code); Assert.AreEqual(contectResult.Content.Country.Picture, existedPlayer.Country.Picture); Assert.AreEqual(contectResult.Content.Data.Rank, existedPlayer.Data.Rank); Assert.AreEqual(contectResult.Content.Data.Height, existedPlayer.Data.Height); Assert.AreEqual(contectResult.Content.Data.Last.Length, existedPlayer.Data.Last.Length); Assert.AreEqual(contectResult.Content.Data.Points, existedPlayer.Data.Points); Assert.AreEqual(contectResult.Content.Data.Weight, existedPlayer.Data.Weight); Assert.AreEqual(contectResult.Content.Data.Age, existedPlayer.Data.Age); }
public async Task GetPlayerById_WhenPlayerIdIsZero_ShouldReturnBadRequest() { var playerServiceMock = new Mock <IPlayerService>(); var controller = new TennisPlayerController(playerServiceMock.Object); var result = await controller.GetPlayerById(0); Assert.IsType <BadRequestResult>(result); }
public void Test_GetPlayerByIdReturnNotFound() { // Arrange TennisPlayerController controller = new TennisPlayerController(repo); // Act IHttpActionResult actionResult = controller.Player(notExistPlayerId); //Assert Assert.IsInstanceOfType(actionResult, typeof(NotFoundResult)); }
public void Test_DeletePlayerByIdReturnOk() { // Arrange TennisPlayerController controller = new TennisPlayerController(repo); // Act IHttpActionResult actionResult = controller.Delete(existPlayerId); //Assert Assert.IsInstanceOfType(actionResult, typeof(OkResult)); }
private void SetOpponentShot() { if (currentShotIndex < shotDataList.Count - 1) { ShotDataObject currentShot = shotDataList[currentShotIndex]; if (currentShot.shot["point"] == "no" && currentShot.shot["error"] == "none") { ShotDataObject nextShot = shotDataList[currentShotIndex + 1]; TennisPlayerController opponentController = GetCurrentOpponentController(); opponentController.MakeShot(nextShot.startPosition, nextShot.shot["shotType"], currentShot.shotDuration); } } }
public async Task DeletePlayerShouldReturnOk() { //Arrange Mock <IDeletePlayerUsesCase> moqDeletePlayerUsesCase = new Mock <IDeletePlayerUsesCase>(); var player = new Player(2, "name2", "surname2", "M", It.IsAny <Country>(), "", It.IsAny <Data>()); moqDeletePlayerUsesCase.Setup(m => m.Handle(It.IsAny <DeletePlayerCommand>())).Verifiable(); var sut = new TennisPlayerController(It.IsAny <IGetPlayersUsesCase>(), It.IsAny <IGetPlayerUsesCase>(), moqDeletePlayerUsesCase.Object); //Act var result = await sut.Delete(player.Id); //Assert Assert.NotNull(result); Assert.IsType <OkResult>(result); }
public async Task GetPlayerShouldReturnOk() { //Arrange Mock <IGetPlayerUsesCase> moqGetPlayerUsesCase = new Mock <IGetPlayerUsesCase>(); var player = new Player(2, "name2", "surname2", "M", It.IsAny <Country>(), "", It.IsAny <Data>()); moqGetPlayerUsesCase.Setup(m => m.Handle(It.IsAny <PlayerRequest>())).Returns(Task.FromResult(player)); var sut = new TennisPlayerController(It.IsAny <IGetPlayersUsesCase>(), moqGetPlayerUsesCase.Object, It.IsAny <IDeletePlayerUsesCase>()); //Act var result = await sut.Get(player.Id); //Assert Assert.NotNull(result); Assert.IsType <OkObjectResult>(result); }
public async Task GetPlayersShouldReturnOk() { //Arrange Mock <IGetPlayersUsesCase> moqGetPlayersUsesCase = new Mock <IGetPlayersUsesCase>(); IEnumerable <Player> players = new List <Player>(); moqGetPlayersUsesCase.Setup(m => m.Handle()).Returns(Task.FromResult(players)); var sut = new TennisPlayerController(moqGetPlayersUsesCase.Object, It.IsAny <IGetPlayerUsesCase>(), It.IsAny <IDeletePlayerUsesCase>()); //Act var result = await sut.Get(); //Assert Assert.NotNull(result); Assert.IsType <OkObjectResult>(result); }
private void Serve() { waitForServe = true; TennisPlayerController servingPlayer = GetCurrentPlayerController(); ballController.SetBallVisible(false); servingPlayer.shotCallback += delegate() { ballController.SetBallVisible(true); waitForServe = false; SetOpponentShot(); }; Vector3 servingPoint = shotDataList[currentShotIndex].startPosition; float distanceToServingPoint = (servingPlayer.transform.position - servingPoint).magnitude; servingPlayer.MakeShot(servingPoint, "serve", distanceToServingPoint * .85f); }
public async Task GetPlayerById_WhenPlayerIdIsFound_ShouldBeHappyPath() { var playerServiceMock = new Mock <IPlayerService>(); playerServiceMock.Setup(e => e.GetAllPlayers()).ReturnsAsync( new System.Collections.Generic.List <Player> { new Player { id = 123 } } ); var controller = new TennisPlayerController(playerServiceMock.Object); var result = await controller.GetPlayerById(123); Assert.IsType <OkObjectResult>(result); }
private void PickShotStartPosition(ShotDataObject prevShot, ShotDataObject currentShot, PointPicker pointPicker, TennisPlayerController playerController) { if (prevShot != null) { float[] xyWeightMultiplier = new float[6]; float[] heightWeights = new float[3]; if (prevShot.shot["category"] == "serve") { // Current rally can only be around the cross course area. xyWeightMultiplier[1] = .9f; xyWeightMultiplier[4] = 1; if (prevShot.oddPoint) { xyWeightMultiplier[0] = .9f; xyWeightMultiplier[3] = .9f; if (prevShot.shot["direction"] == "wide") { xyWeightMultiplier[0] *= 3; xyWeightMultiplier[3] *= 3; } } else { xyWeightMultiplier[2] = .9f; xyWeightMultiplier[5] = .9f; if (prevShot.shot["direction"] == "wide") { xyWeightMultiplier[2] *= 3; xyWeightMultiplier[5] *= 3; } } if (prevShot.shot["direction"] == "downTheT") { xyWeightMultiplier[1] *= 4; xyWeightMultiplier[4] *= 4; } } else { xyWeightMultiplier[0] = 1; xyWeightMultiplier[1] = 1; xyWeightMultiplier[2] = 1; xyWeightMultiplier[3] = 1; xyWeightMultiplier[4] = 1; xyWeightMultiplier[5] = 1; if (prevShot.shot["direction"] == "right") { xyWeightMultiplier[2] *= 1.4f; xyWeightMultiplier[5] *= 1.4f; } if (prevShot.shot["direction"] == "downTheCourt") { xyWeightMultiplier[1] *= 1.4f; xyWeightMultiplier[4] *= 1.4f; } if (prevShot.shot["direction"] == "left") { xyWeightMultiplier[0] *= 1.4f; xyWeightMultiplier[3] *= 1.4f; } if (currentShot.shot["shotType"] == "forehandGround" || currentShot.shot["shotType"] == "forehandSlice" || currentShot.shot["shotType"] == "forehandVolley" || currentShot.shot["shotType"] == "forehandLob" || currentShot.shot["shotType"] == "forehandHalfVolley" || currentShot.shot["shotType"] == "forehandSwingingVolley") { xyWeightMultiplier[2] *= 1.4f; xyWeightMultiplier[5] *= 1.4f; } if (currentShot.shot["shotType"] == "backhandGround" || currentShot.shot["shotType"] == "backhandSlice" || currentShot.shot["shotType"] == "backhandVolley" || currentShot.shot["shotType"] == "backhandLob" || currentShot.shot["shotType"] == "backhandHalfVolley" || currentShot.shot["shotType"] == "backhandSwingingVolley") { xyWeightMultiplier[0] *= 1.4f; xyWeightMultiplier[3] *= 1.4f; } if (currentShot.shot["shotType"] == "forehandOverhead" || currentShot.shot["shotType"] == "backhandOverhead") { xyWeightMultiplier[0] *= 1.4f; xyWeightMultiplier[1] *= 1.4f; xyWeightMultiplier[2] *= 1.4f; } if (currentShot.shot["shotType"] == "forehandGround" || currentShot.shot["shotType"] == "backhandGround" || currentShot.shot["shotType"] == "forehandDropShot" || currentShot.shot["shotType"] == "backhandDropShot") { xyWeightMultiplier[3] *= 1.4f; xyWeightMultiplier[4] *= 1.4f; xyWeightMultiplier[5] *= 1.4f; } if (prevShot.shot["position"] == "approach") { xyWeightMultiplier[1] *= 1.4f; } if (prevShot.shot["position"] == "net") { xyWeightMultiplier[1] *= 4f; } if (prevShot.shot["position"] == "baseline") { xyWeightMultiplier[3] *= 2; xyWeightMultiplier[4] *= 2; xyWeightMultiplier[5] *= 2; } if (prevShot.shot["depth"] == "serviceBox") { xyWeightMultiplier[0] *= 4; xyWeightMultiplier[1] *= 4; xyWeightMultiplier[2] *= 4; } if (prevShot.shot["depth"] == "baseline") { xyWeightMultiplier[3] *= 4; xyWeightMultiplier[4] *= 4; xyWeightMultiplier[5] *= 4; } if (prevShot.shot["shotType"] == "forehandLob" || prevShot.shot["shotType"] == "backhandLob") { xyWeightMultiplier[3] *= 2; xyWeightMultiplier[4] *= 2; xyWeightMultiplier[5] *= 2; } } currentShot.shotDuration = UnityEngine.Random.Range(1.1f, 1.2f); currentShot.startPosition = pointPicker.PickRandomWithMultiplier(xyWeightMultiplier); if (currentShot.startPosition.y == 0 || currentShot.startPosition.y == float.NaN) { currentShot.startPosition.y = heightPicker.PickPointByWeights(1, 2, 0).y; } // We want to pick the exact height because of animation complication. // This may change later on. currentShot.startPosition.y = playerController.GetShotPoint(currentShot.shot["shotType"]).y; } else { // Current shot is a serve if (currentShot.oddPoint) { currentShot.startPosition = pointPicker.PickRandomWithMultiplier(0, 0, 0, 1, 2, 0); } else { currentShot.startPosition = pointPicker.PickRandomWithMultiplier(0, 0, 0, 0, 2, 1); } currentShot.shotDuration = UnityEngine.Random.Range(.9f, .96f); currentShot.startPosition.y = playerController.GetShotPoint("serve").y; } }