public async Task IsAbleToListGamesAsync() { await InsertGame(); var newGame = new Game { Name = "My New Game's Name Test" }; var insertResult = _sut.Create(newGame); var foundGames = _repositoryStub.FindAll().Result; Assert.AreEqual(2, foundGames.Count()); }
public async Task RateVideoGame_RatingHigherThenAllowedValueAndGameId_ReturnsNotFoundResult() { var optionsBuilder = new DbContextOptionsBuilder <ApplicationDbContext>(); optionsBuilder.UseInMemoryDatabase("test"); var _dbContext = new ApplicationDbContext(optionsBuilder.Options); var c = new GamesController(_dbContext, _hostingEnv); Games game = new Games(); game.Id = 1; game.Title = "test"; game.Genre = "rock"; game.Description = "loud stuff"; game.Publisher = "da"; game.Developer = "EA"; game.ESRB_Ratings = "lalaalaa"; game.ReleaseDate = new System.DateTime(); game.Price = 2; game.GameLink = "dsa"; game.Available = "dsadas"; game.EntryDate = new System.DateTime(); await c.Create(game); var sf = new StoreFrontController(_dbContext); var result = await sf.RateGame(9, 2); Assert.IsInstanceOfType(result, typeof(NotFoundResult)); }
public void WhenTheFollowingGAMETYPEGamesArePlayedInVENUE(string gameType, string venue, Table table) { var list = table.CreateSet <TestGame>(); var viewResult = (ViewResult)GamesController.Create(); var viewModel = (GameViewModel)viewResult.Model; foreach (var game in list) { var firstPlayer = viewModel.Players.FirstOrDefault(item => item.Text == game.FirstPlayer); if (firstPlayer == null) { throw new Exception($"Unknown player {game.FirstPlayer}"); } var secondPlayer = viewModel.OpponentPlayers.FirstOrDefault(item => item.Text == game.SecondPlayer); if (secondPlayer == null) { throw new Exception($"Unknown player {game.SecondPlayer}"); } var model = new GameViewModel { RegistrationDate = game.RegistrationDate.ToString(CultureInfo.InvariantCulture), GameType = gameType, NameFirstPlayer = firstPlayer.Value, NameSecondPlayer = secondPlayer.Value, ScoreFirstPlayer = game.S1, ScoreSecondPlayer = game.S2 }; GamesController.Create(model); } }
public async Task Create_GameObjectAsParam_ReturnsIndexView() { var optionsBuilder = new DbContextOptionsBuilder <ApplicationDbContext>(); optionsBuilder.UseInMemoryDatabase("test"); var _dbContext = new ApplicationDbContext(optionsBuilder.Options); var c = new GamesController(_dbContext, _hostingEnv); Games game = new Games(); game.Id = 1; game.Title = "test"; game.Genre = "rock"; game.Description = "loud stuff"; game.Publisher = "da"; game.Developer = "EA"; game.ESRB_Ratings = "lalaalaa"; game.ReleaseDate = new System.DateTime(); game.Price = 2; game.GameLink = "dsa"; game.Available = "dsadas"; game.EntryDate = new System.DateTime(); var result = await c.Create(game); Assert.IsInstanceOfType(result, typeof(RedirectToActionResult)); }
public async Task CreatePost_WhenModelStateIsNotValid_ShouldShowGameCreateView() { // Arrange var gamesIndexViewModel = A.Fake <IGamesIndexViewModel>(); var gamesDetailsViewModel = A.Fake <IGamesDetailsViewModel>(); var gameService = A.Fake <IGameService>(); var gameRepository = A.Fake <IGameRepository>(); var teamRepository = A.Fake <ITeamRepository>(); var seasonRepository = A.Fake <ISeasonRepository>(); var sharedRepository = A.Fake <ISharedRepository>(); var testController = new GamesController(gamesIndexViewModel, gamesDetailsViewModel, gameService, gameRepository, teamRepository, seasonRepository, sharedRepository); var game = new Game(); testController.ModelState.AddModelError("Season", "Please enter a season."); // Act var result = await testController.Create(game); // Assert A.CallTo(() => gameService.AddGameAsync(game)).MustNotHaveHappened(); A.CallTo(() => sharedRepository.SaveChangesAsync()).MustNotHaveHappened(); result.ShouldBeOfType <ViewResult>(); ((ViewResult)result).Model.ShouldBe(game); }
public async Task CreateTest() { var loginResponse = await authController.Login(new PunsApi.Requests.Authentication.LoginRequest { Email = "*****@*****.**", Password = "******" }); var _gameService = GetService <IGamesService>(); var httpContext = new DefaultHttpContext(); // Create the stream to house our content var stream = new MemoryStream(Encoding.UTF8.GetBytes("testowa")); httpContext.Request.Body = stream; httpContext.Request.ContentLength = stream.Length; var controller = new GamesController(_gameService) { // Set the controller context to our created HttpContext ControllerContext = new ControllerContext() { HttpContext = httpContext } }; var response = await controller.Create(new CreateGameRequest { GameName = "Testowa" }); Assert.True(true); }
public void GamesControllerCreate() { var gamesController = new GamesController(null); var result = gamesController.Create(); Assert.IsNotNull(result); }
public void CreateGet_ExceptionCaught_RethrowsException() { // Arrange var controller = new GamesController(_service, _sharedService); A.CallTo(() => _sharedService.GetSeasonsOrderedAsync(null)).Throws <Exception>(); // Act // Assert Assert.ThrowsAsync <Exception>(async() => await controller.Create()); }
public void CreateTest1() { // Arrange GamesController controller = new GamesController(); // Act var result = controller.Create(); // Assert Assert.IsNotNull(result); }
public async Task CreateGet_WhenSelectedWeekIsNull_ShouldShowGameCreateView() { // Arrange int selectedSeasonYear = 1920; GamesController.SelectedSeasonYear = selectedSeasonYear; GamesController.SelectedWeek = null; var gamesIndexViewModel = A.Fake <IGamesIndexViewModel>(); var gamesDetailsViewModel = A.Fake <IGamesDetailsViewModel>(); var gameService = A.Fake <IGameService>(); var gameRepository = A.Fake <IGameRepository>(); var teamRepository = A.Fake <ITeamRepository>(); var seasonRepository = A.Fake <ISeasonRepository>(); var seasons = new List <Season> { new Season { Year = selectedSeasonYear, NumOfWeeksScheduled = 3 } }; var selectedSeason = seasons.FirstOrDefault(s => s.Year == selectedSeasonYear); A.CallTo(() => seasonRepository.GetSeasonsAsync()).Returns(seasons); var sharedRepository = A.Fake <ISharedRepository>(); var testController = new GamesController(gamesIndexViewModel, gamesDetailsViewModel, gameService, gameRepository, teamRepository, seasonRepository, sharedRepository); // Act var result = await testController.Create(); // Assert A.CallTo(() => seasonRepository.GetSeasonsAsync()).MustHaveHappenedOnceExactly(); Assert.IsType <SelectList>(testController.ViewBag.Seasons); var seasonsSelectList = (SelectList)testController.ViewBag.Seasons; seasonsSelectList.Items.ShouldBe(seasons.OrderByDescending(s => s.Year)); seasonsSelectList.DataValueField.ShouldBe <string>("Year"); seasonsSelectList.DataTextField.ShouldBe <string>("Year"); seasonsSelectList.SelectedValue.ShouldBe(GamesController.SelectedSeasonYear); Assert.IsType <SelectList>(testController.ViewBag.Weeks); var weeksSelectList = (SelectList)testController.ViewBag.Weeks; weeksSelectList.Items.ShouldBeEquivalentTo(new List <int?> { 1, 2, 3 }); weeksSelectList.SelectedValue.ShouldBe(1); result.ShouldBeOfType <ViewResult>(); }
public async Task CreateGet_HappyPath() { // Arrange var controller = new GamesController(_service, _sharedService); GamesService.SelectedSeason = 2017; GamesService.SelectedWeek = new WeekViewModel(1); var seasons = new List <SeasonViewModel>(); A.CallTo(() => _sharedService.GetSeasonsOrderedAsync(null)).Returns(seasons); var teams = new List <TeamViewModel>(); A.CallTo(() => _service.GetTeamsAsync(null)).Returns(teams); // Act var result = await controller.Create(); // Assert A.CallTo(() => _sharedService.GetSeasonsOrderedAsync(null)).MustHaveHappenedOnceExactly(); Assert.IsInstanceOf <ViewResult>(result); var viewBag = (result as ViewResult).ViewBag; var viewBagSeasonID = viewBag.SeasonID; Assert.IsInstanceOf <SelectList>(viewBagSeasonID); Assert.AreSame(seasons, viewBagSeasonID.Items); Assert.AreEqual("ID", viewBagSeasonID.DataValueField); Assert.AreEqual("ID", viewBagSeasonID.DataTextField); Assert.AreEqual(GamesService.SelectedSeason, viewBagSeasonID.SelectedValues[0]); Assert.AreEqual(GamesService.SelectedWeek.ID, viewBag.Week); A.CallTo(() => _service.GetTeamsAsync(null)).MustHaveHappenedOnceExactly(); var viewBagGuestName = viewBag.GuestName; Assert.IsInstanceOf <SelectList>(viewBagGuestName); Assert.AreSame(teams, viewBagGuestName.Items); Assert.AreEqual("Name", viewBagGuestName.DataValueField); Assert.AreEqual("Name", viewBagGuestName.DataTextField); var viewBagHostName = viewBag.HostName; Assert.IsInstanceOf <SelectList>(viewBagHostName); Assert.AreSame(teams, viewBagHostName.Items); Assert.AreEqual("Name", viewBagHostName.DataValueField); Assert.AreEqual("Name", viewBagHostName.DataTextField); }
public void Create_AddGame_ReturneRightModel() { //Arrange Guid guid1 = Guid.NewGuid(); string GameName1 = "Name1"; GameViewModel Game = new GameViewModel { GameGuid = guid1, Name = GameName1 }; //Service.Setup(x => x.GetGames()).Returns(Game); GamesController controller = new GamesController(Service.Object, Mapper); //Act var result = controller.Create(Game) as ViewResult; //Assert Service.Verify(x => x.SaveGame(It.IsAny <GameDTO>())); }
public void CreatePost_ExceptionCaught_RethrowsException() { // Arrange var controller = new GamesController(_service, _sharedService); controller.ModelState.AddModelError("GuestScore", "Guest score is required."); var gameViewModel = new GameViewModel { SeasonID = 2017, GuestName = "Guest", HostName = "Host" }; A.CallTo(() => _sharedService.GetSeasonsOrderedAsync(null)).Throws <Exception>(); // Act // Assert Assert.ThrowsAsync <Exception>(async() => await controller.Create(gameViewModel)); }
public async Task CreatePost_ModelStateValid() { // Arrange var controller = new GamesController(_service, _sharedService); var gameViewModel = new GameViewModel { SeasonID = 2017 }; // Act var result = await controller.Create(gameViewModel); // Assert A.CallTo(() => _service.SetSelectedWeek(gameViewModel.Week)).MustHaveHappenedOnceExactly(); A.CallTo(() => _service.AddEntity(gameViewModel, null)).MustHaveHappenedOnceExactly(); Assert.IsInstanceOf <RedirectToRouteResult>(result); var resultAsRedirectToRouteResult = result as RedirectToRouteResult; Assert.AreEqual("Create", resultAsRedirectToRouteResult.RouteValues["action"]); Assert.AreEqual(gameViewModel.SeasonID, resultAsRedirectToRouteResult.RouteValues["seasonID"]); }
public async Task IntegrationTest() { var loginResponse = await authController.Login(new PunsApi.Requests.Authentication.LoginRequest { Email = "*****@*****.**", Password = "******" }); Assert.True(((Microsoft.AspNetCore.Mvc.ObjectResult)loginResponse).StatusCode == 200); var createRoomRespose = await controller.Create(new PunsApi.Requests.Rooms.CreateRoomRequest { PlayerMaxCount = 5, PlayerMinCount = 2, RoomName = "Testowy Pokoj" }); Assert.True(((Microsoft.AspNetCore.Mvc.ObjectResult)createRoomRespose).StatusCode == 200); var createGameResponse = await games_controller.Create(new CreateGameRequest { GameName = "Gra Testowa" }); Assert.True(((Microsoft.AspNetCore.Mvc.ObjectResult)createRoomRespose).StatusCode == 200); var fetchGameResponse = await games_controller.FetchGame(); Assert.True(((Microsoft.AspNetCore.Mvc.ObjectResult)fetchGameResponse).StatusCode == 200); }
public async Task CreatePost_WhenModelStateIsValid_ShouldAddGameToDataStoreAndRedirectToCreateView() { // Arrange var gamesIndexViewModel = A.Fake <IGamesIndexViewModel>(); var gamesDetailsViewModel = A.Fake <IGamesDetailsViewModel>(); var gameService = A.Fake <IGameService>(); var gameRepository = A.Fake <IGameRepository>(); var teamRepository = A.Fake <ITeamRepository>(); var seasonRepository = A.Fake <ISeasonRepository>(); var sharedRepository = A.Fake <ISharedRepository>(); var testController = new GamesController(gamesIndexViewModel, gamesDetailsViewModel, gameService, gameRepository, teamRepository, seasonRepository, sharedRepository); var game = new Game(); // Act var result = await testController.Create(game); // Assert A.CallTo(() => gameService.AddGameAsync(game)).MustHaveHappenedOnceExactly(); A.CallTo(() => sharedRepository.SaveChangesAsync()).MustHaveHappenedOnceExactly(); result.ShouldBeOfType <RedirectToActionResult>(); ((RedirectToActionResult)result).ActionName.ShouldBe <string>(nameof(testController.Create)); }
public async Task CreatePost_ModelStateNotValid() { // Arrange var controller = new GamesController(_service, _sharedService); controller.ModelState.AddModelError("GuestScore", "Guest score is required."); var gameViewModel = new GameViewModel { SeasonID = 2017, GuestName = "Guest", HostName = "Host" }; var seasons = new List <SeasonViewModel>(); A.CallTo(() => _sharedService.GetSeasonsOrderedAsync(null)).Returns(seasons); GamesService.SelectedWeek = new WeekViewModel(1); var teams = new List <TeamViewModel>(); A.CallTo(() => _service.GetTeamsAsync(null)).Returns(teams); // Act var result = await controller.Create(gameViewModel); // Assert A.CallTo(() => _sharedService.GetSeasonsOrderedAsync(null)).MustHaveHappenedOnceExactly(); Assert.IsInstanceOf <ViewResult>(result); var resultAsViewResult = result as ViewResult; var viewBag = resultAsViewResult.ViewBag; var viewBagSeasonID = viewBag.SeasonID; Assert.IsInstanceOf <SelectList>(viewBagSeasonID); Assert.AreSame(seasons, viewBagSeasonID.Items); Assert.AreEqual("ID", viewBagSeasonID.DataValueField); Assert.AreEqual("ID", viewBagSeasonID.DataTextField); Assert.AreEqual(gameViewModel.SeasonID, viewBagSeasonID.SelectedValues[0]); Assert.AreEqual(GamesService.SelectedWeek.ID, viewBag.Week); var viewBagGuestName = viewBag.GuestName; Assert.IsInstanceOf <SelectList>(viewBagGuestName); Assert.AreSame(teams, viewBagGuestName.Items); Assert.AreEqual("Name", viewBagGuestName.DataValueField); Assert.AreEqual("Name", viewBagGuestName.DataTextField); Assert.AreEqual(gameViewModel.GuestName, viewBagGuestName.SelectedValues[0]); var viewBagHostName = viewBag.HostName; Assert.IsInstanceOf <SelectList>(viewBagHostName); Assert.AreSame(teams, viewBagHostName.Items); Assert.AreEqual("Name", viewBagHostName.DataValueField); Assert.AreEqual("Name", viewBagHostName.DataTextField); Assert.AreEqual(gameViewModel.HostName, viewBagHostName.SelectedValues[0]); Assert.AreSame(gameViewModel, resultAsViewResult.Model); }
RedirectToRouteResult GivenAGame(string name) { return(controller.Create(new { name }.ToParams()) as RedirectToRouteResult); }