public void GetGames_WithUnknownUser_ReturnsErrorCode() { // act var game = _controller.GetGames("") as JsonResult; // assert dynamic model = game.Data.AsDynamic(); Assert.False(model.ok); }
public async Task GetGames_WhenNoExceptionIsCaught_ShouldGetGames() { // Arrange var gameRepository = A.Fake <IGameRepository>(); var games = new List <Game>(); A.CallTo(() => gameRepository.GetGamesAsync()).Returns(games); var sharedRepository = A.Fake <ISharedRepository>(); var mapper = A.Fake <IMapper>(); var linkGenerator = A.Fake <LinkGenerator>(); var gameService = A.Fake <IGameService>(); var testController = new GamesController(gameRepository, sharedRepository, mapper, linkGenerator, gameService); // Act var result = await testController.GetGames(); // Assert A.CallTo(() => gameRepository.GetGamesAsync()).MustHaveHappenedOnceExactly(); A.CallTo(() => mapper.Map <GameModel[]>(games)).MustHaveHappenedOnceExactly(); result.ShouldBeOfType <ActionResult <GameModel[]> >(); result.Value.ShouldBe(mapper.Map <GameModel[]>(games)); }
public void Get_Zero_Items() { TestHelpers.SetupDbSet(this.mockSet, new List <game>()); GamesController controller = new GamesController(this.mockContext.Object); IQueryable <game> result = controller.GetGames(); Assert.IsNotNull(result); Assert.AreEqual(0, result.Count()); }
public void Get_Should_Return_Items() { TestHelpers.SetupDbSet(this.mockSet, this.data); GamesController controller = new GamesController(this.mockContext.Object); IQueryable <game> result = controller.GetGames(); Assert.IsNotNull(result); Assert.AreNotEqual(0, result.Count()); }
public void GetGames_WhenCalled_ReturnsAllItems() { var controller = new GamesController(CreateMoqGames().Object); var result = controller.GetGames(1, 2); var okResult = result.Should().BeOfType <OkObjectResult>().Subject; var games = okResult.Value.Should().BeAssignableTo <IEnumerable <Games> >().Subject; games.Count().Should().Be(2); }
public void GetGamById_Ok() { // Arrange var mockRepository = new Mock <IUnitOfWork>(); var controller = new GamesController(mockRepository.Object); // Act var actionResult = controller.GetGames(); // Assert Assert.IsInstanceOfType(actionResult, typeof(NotFoundResult)); }
public void IssueErrorAndMessageShouldGetGamesFail() { // Arrange // Act var result = sutFailure.GetGames(getMyGameRequest, true); var message = ((GamesResult)((NotFoundObjectResult)result.Result.Result).Value).Message; var statusCode = ((NotFoundObjectResult)result.Result.Result).StatusCode; // Assert Assert.That(result.Result, Is.InstanceOf <ActionResult <IEnumerable <Game> > >()); Assert.That(message, Is.EqualTo("Status Code 404: Games not Found")); Assert.That(statusCode, Is.EqualTo(404)); }
public void SuccessfullyGetGames() { // Arrange // Act var result = sutSuccess.GetGames(getMyGameRequest, true); var message = ((GamesResult)((OkObjectResult)result.Result.Result).Value).Message; var statusCode = ((OkObjectResult)result.Result.Result).StatusCode; // Assert Assert.That(result.Result, Is.InstanceOf <ActionResult <IEnumerable <Game> > >()); Assert.That(message, Is.EqualTo("Status Code 200: Games Found")); Assert.That(statusCode, Is.EqualTo(200)); }
public void GetGames_ReturnsListOfGames() { // Arrange var gameService = new Mock <IGameService>(); gameService.Setup(s => s.GetGames()).Returns(new List <Game>()); var contoller = new GamesController(gameService.Object); // Act var result = contoller.GetGames(); // Assert Assert.IsAssignableFrom <IEnumerable <Game> >(result); Assert.Empty(result); }
public void GetGamesTest() { var gamesReturnedByRepository = RepositoryTestService.GetGames(); this.moqGamesRepository.Setup(m => m.GetGames()).Returns(gamesReturnedByRepository); GamesController gameController = new GamesController(this.moqGamesRepository.Object, this.autoMapper); var result = gameController.GetGames(); Assert.IsNotNull(result); Assert.That(result.Result, Is.InstanceOf(typeof(OkObjectResult))); OkObjectResult okObjectResult = result.Result as OkObjectResult; Assert.AreEqual(okObjectResult.StatusCode, 200); Assert.Greater((okObjectResult.Value as IList <GameDTO>).Count, 0); }
public void GetGames_should_return_all_games_with_pagination() { //Arrange var config = new HttpConfiguration(); var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost:58326/api/games"); var route = config.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}"); var routeData = new HttpRouteData(route, new HttpRouteValueDictionary { { "controller", "games" } }); _gamesController.ControllerContext = new HttpControllerContext(config, routeData, request); _gamesController.Request = request; _gamesController.Request.Properties[HttpPropertyKeys.HttpConfigurationKey] = config; _gameService.Setup(x => x.GetAll(It.IsAny <PaginationParameters>(), It.IsAny <FilterParameters>())).Returns(new PagedList <GameDTO>(new List <GameDTO>(), 5, 1, 10)); //Act var response = _gamesController.GetGames(It.IsAny <FilterParameters>(), It.IsAny <PaginationParameters>()); //Assert Assert.IsTrue((response as ResponseMessageResult).Response.Headers.Contains("X-Pagination")); }
public async Task GetGames_Void_TaskActionResultContainsIEnumerableOfGame() { // Arrange List <Game> expectedData = GetFakeList(); InitializeInmemoryDatabase(out DbContextOptions <GameReviewsContext> options, GetFakeList()); // Act using (var context = new GameReviewsContext(options)) { GamesController gamesController = new GamesController(context); IEnumerable <Game> games = (await gamesController.GetGames()).Value; // Assert Assert.Equal(expectedData.Count, games.Count()); for (int i = 0; i < expectedData.Count; ++i) { Assert.True(AreEqual(expectedData[i], games.ElementAt(i))); } } }
public void GetGames_Ok() { // Arrange IQueryable <GameDto> listOfgames = new List <GameDto>() { new GameDto() }.AsQueryable(); var expextedGame = new Mock <GameDto>().Object; var mockService = new Mock <IGameService>(); mockService.Setup(s => s.GetAllGames()).Returns(() => listOfgames); var controller = new GamesController(mockService.Object); // Act var actionResult = controller.GetGames(); var okResult = actionResult as OkNegotiatedContentResult <IQueryable <GameDto> >; // Assert // Assert Assert.IsNotNull(okResult); Assert.IsInstanceOfType(actionResult, typeof(OkNegotiatedContentResult <IQueryable <GameDto> >)); }
public async Task GetGames_WhenExceptionIsCaught_ShouldReturnInternalServerError() { // Arrange var gameRepository = A.Fake <IGameRepository>(); A.CallTo(() => gameRepository.GetGamesAsync()).Throws <Exception>(); var sharedRepository = A.Fake <ISharedRepository>(); var mapper = A.Fake <IMapper>(); var linkGenerator = A.Fake <LinkGenerator>(); var gameService = A.Fake <IGameService>(); var testController = new GamesController(gameRepository, sharedRepository, mapper, linkGenerator, gameService); // Act var result = await testController.GetGames(); // Assert result.Result.ShouldBeOfType <ObjectResult>(); ((ObjectResult)result.Result).StatusCode.ShouldBe(StatusCodes.Status500InternalServerError); ((ObjectResult)result.Result).Value.ShouldBe("Database failure"); }
private GameModel TestGameCreate() { GamesController controller = new GamesController(); var result = controller.GetGames(); Assert.IsInstanceOfType(result, typeof(GetGameListType)); var gameList = ((GetGameListType)result).Content; long nextExpectedGameId = 1; if (gameList.Count != 0) { nextExpectedGameId = gameList[gameList.Count - 1].Id + 1; } // test that nextExpectedGameId does not yet exist result = controller.GetGame(nextExpectedGameId); Assert.IsInstanceOfType(result, typeof(NotFoundResult)); // verify that all others in gamelist can be found foreach (GameModel game in gameList) { result = controller.GetGame(game.Id); Assert.IsInstanceOfType(result, typeof(GetGameType)); Assert.AreEqual(game, ((GetGameType)result).Content); } var player = TestHelpers.TestData.getAuthorizedPlayers()[0]; // Test Game Create and verify you can get it result = controller.CreateGame(); // Need to provide authorization to create a game Assert.IsInstanceOfType(result, typeof(UnauthorizedResult)); // Add Authorization var context = new HttpControllerContext(); var request = new HttpRequestMessage(); request.Headers.Add("Authorization", player.AuthCode); controller.ControllerContext = context; controller.Request = request; result = controller.CreateGame(); Assert.IsInstanceOfType(result, typeof(PostGameType)); GameModel newGame = ((PostGameType)result).Content; Assert.AreEqual(player.PlayerName, newGame.Hostname); Assert.AreEqual(nextExpectedGameId, newGame.Id); // Test that game can now be found // test that nextExpectedGameId does not yet exist result = controller.GetGame(newGame.Id); Assert.IsInstanceOfType(result, typeof(GetGameType)); return(newGame); }