public void RetrieveATeamPlayerInTheRepo() { TeamPlayerSeasonStatisticViewModel tp = new TeamPlayerSeasonStatisticViewModel(); int calledTPId = 0; int calledSeasonId = 0; var mock = new Mock <ITeamPlayerRepository>(MockBehavior.Strict); // Filling mock with data mock.As <ITeamPlayerRepository>().Setup(m => m.GetTeamPlayerStatisticForASeason(It.IsAny <int>(), It.IsAny <int>())) .Callback((int tpId, int seasonId) => { calledTPId = tpId; calledSeasonId = seasonId; }) .Returns(Task.FromResult(tp)); // Creating the controller which we want to create TeamPlayerStatisticViewController controller = new TeamPlayerStatisticViewController(mock.Object); // configuring the context for the controler fakeContext(controller); int inputParamTPId = 1; int inputParamSeasonId = 1; HttpResponseMessage response = controller.Get(inputParamTPId, inputParamSeasonId).Result; Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); var objectContent = response.Content as ObjectContent; // Verifying that the parameters have correctly been passed on the repo Assert.AreEqual(calledTPId, inputParamTPId); Assert.AreEqual(calledSeasonId, inputParamSeasonId); Assert.AreEqual(tp, objectContent.Value); }
public void RetrieveATeamPlayerFailureInTheRepo() { var mock = new Mock <ITeamPlayerRepository>(MockBehavior.Strict); // Filling mock with data mock.As <ITeamPlayerRepository>().Setup(m => m.GetTeamPlayerStatisticForASeason(It.IsAny <int>(), It.IsAny <int>())) .Returns(Task.FromResult((TeamPlayerSeasonStatisticViewModel)null)); // Creating the controller which we want to create TeamPlayerStatisticViewController controller = new TeamPlayerStatisticViewController(mock.Object); // configuring the context for the controler fakeContext(controller); HttpResponseMessage response = controller.Get(1, 1).Result; Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); }