public void GetById_IdDoesNotExists_ReturnsNotFoundResult() { var controller = new GamesController(new FakeGamesRepository(), new FakeLogger()); var result = controller.GetById("some-id"); Assert.IsType <NotFoundResult>(result.Result); }
public void GetById_IdIsEmpty_ReturnsNotFoundResult() { var controller = new GamesController(new FakeGamesRepository(), new FakeLogger()); var result = controller.GetById(string.Empty); Assert.IsType <NotFoundResult>(result); }
public void GetById_IdIsNull_ReturnsNotFoundResult() { var controller = new GamesController(new FakeGamesRepository(), new FakeLogger()); var result = controller.GetById(null); Assert.IsType <NotFoundResult>(result.Result); Assert.Null(result.Value); }
public void GetById_IdExists_ReturnsOkResult() { var controller = new GamesController(new FakeGamesRepository(), new FakeLogger()); var result = controller.GetById("existing"); Assert.Null(result.Result); Assert.NotNull(result.Value); Assert.Equal("existing", result.Value.Id); }
public void GetById_IdExists_ReturnsOkResult() { var controller = new GamesController(new FakeGamesRepository(), new FakeLogger()); var result = controller.GetById("existing"); Assert.IsType <OkObjectResult>(result); var resultValue = ((OkObjectResult)result).Value; Assert.IsType <ApiResult <Game> >(resultValue); Assert.Equal("existing", ((ApiResult <Game>)resultValue).Data.Id); }
public void GetById_InputIsNotValid_GetByIdForRepositoryIsCalledAndJsonResultIsCorrect() { // Arrange var mock = new Mock <IGameRepository>(); //context int gameId = -7; GameDataModel expectedGame = null;//new GameWebModel() { Id = 1, Name = "name1", Key = "kkk1" }; mock.Setup(m => m.GetById(gameId)).Returns(expectedGame); var controller = new GamesController(mock.Object); // Act var result = controller.GetById(gameId) as JsonResult; // Assert Assert.IsNotNull(result); mock.Verify(a => a.GetById(gameId), Times.Once); Assert.AreEqual(expectedGame, result.Data); }