public void DetailsValidGame()
        {
            // Act
            var actual = (game)controller.Details(1).Model;

            //Assert
            Assert.AreEqual(games.ToList()[0], actual);
        }
Exemple #2
0
        public void GetAGameWithExistingId_ReturnGameWithCorrectId()
        {
            //Arrange
            var okResult    = _controller.Details(1);
            int expected_Id = 1;

            //Act
            Assert.Equal(expected_Id, okResult.GameId);
        }
        //[Test]
        public void GetGameFromGameController()
        {
            GamesController controller = new GamesController();
            var             result     = controller.Details(1) as ViewResult;

            Assert.AreEqual("Details", result.ViewName);
        }
        public async Task Details_WhenIdIsNotNullAndGameFound_ShouldReturnNotFound()
        {
            // Arrange
            var gamesIndexViewModel   = A.Fake <IGamesIndexViewModel>();
            var gamesDetailsViewModel = A.Fake <IGamesDetailsViewModel>();
            var gameService           = A.Fake <IGameService>();

            var  gameRepository = A.Fake <IGameRepository>();
            Game?game           = new Game();

            A.CallTo(() => gameRepository.GetGameAsync(A <int> .Ignored)).Returns(game);

            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);

            int?id = 1;

            // Act
            var result = await testController.Details(id.Value);

            // Assert
            A.CallTo(() => gameRepository.GetGameAsync(id.Value)).MustHaveHappenedOnceExactly();
            gamesDetailsViewModel.Game.ShouldBe(game);
            result.ShouldBeOfType <ViewResult>();
            ((ViewResult)result).Model.ShouldBe(gamesDetailsViewModel);
        }
        public async void TestSelect_ValidGame_ShouldSuccess()
        {
            // Arrange
            GamesController controller = new GamesController(_context, _webHostEnvironment);

            InitializeGame();

            try
            {
                // Act
                var result = await controller.Details(game.GameId);

                // Assert
                Assert.IsType <ViewResult>(result);
                ViewResult viewResult = (ViewResult)result;
                Assert.NotNull(viewResult.ViewData.ModelState);
                Assert.NotEmpty(viewResult.ViewData.ModelState.Keys);

                foreach (string item in viewResult.ViewData.ModelState.Keys)
                {
                    Assert.Equal("", item);
                }
            }
            catch (Exception ex)
            {
            }
        }
Exemple #6
0
        public void GamesControllerDetails()
        {
            var gamesController = new GamesController(null);

            var result = gamesController.Details(null);

            Assert.IsNotNull(result);
        }
        public void DetailsTest()
        {
            // Arrange
            GamesController controller = new GamesController();

            // Act
            var result = controller.Details(1);

            // Assert
            Assert.IsNotNull(result);
        }
Exemple #8
0
        public void Details_ShouldReturnNullViewBag_WhenGameIdIsNull()
        {
            // Arrange
            var controller = new GamesController();

            // Act
            var result = controller.Details(null) as ViewResult;

            // Assert
            Assert.IsNotNull(result);
            Assert.IsNull(result.ViewBag.GameId);
        }
Exemple #9
0
        public void Details_ShouldReturnCorrectViewBag_WhenGameIdNotNull()
        {
            // Arrange
            var controller = new GamesController();

            // Act
            var result = controller.Details(5) as ViewResult;

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(5, result.ViewBag.GameId);
        }
        public void Details_ExceptionCaught_RethrowsException()
        {
            // Arrange
            var controller = new GamesController(_service, _sharedService);

            int?id = 1;

            A.CallTo(() => _service.FindEntityAsync(A <int> .Ignored, null)).Throws <Exception>();

            // Act
            // Assert
            Assert.ThrowsAsync <Exception>(async() => await controller.Details(id));
        }
Exemple #11
0
        public async Task Details_IdAsParam_ReturnDetailsIndexView()
        {
            var optionsBuilder = new DbContextOptionsBuilder <ApplicationDbContext>();

            optionsBuilder.UseInMemoryDatabase("test");
            var _dbContext = new ApplicationDbContext(optionsBuilder.Options);

            var c = new GamesController(_dbContext, _hostingEnv);

            var result = await c.Details(1);

            Assert.IsInstanceOfType(result, typeof(ViewResult));
        }
        public async Task Details_IdNull_ReturnsBadHttpRequest()
        {
            // Arrange
            var controller = new GamesController(_service, _sharedService);

            int?id = null;

            // Act
            var result = await controller.Details(id);

            // Assert
            Assert.IsInstanceOf <HttpStatusCodeResult>(result);
            Assert.AreEqual((int)HttpStatusCode.BadRequest, (result as HttpStatusCodeResult).StatusCode);
        }
Exemple #13
0
        public void Details_ReturnsNotFound_WhenIdIsNull()
        {
            var options = new DbContextOptionsBuilder <GameDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;

            var context    = new GameDbContext(options);
            var controller = new GamesController(context);


            var result = (NotFoundResult)controller.Details(null).Result;

            var contentResult = Assert.IsType <NotFoundResult>(result);

            Assert.Equal(result.StatusCode, contentResult.StatusCode);
        }
Exemple #14
0
        public async void GamesController_Game_Details()
        {
            //Arrange
            var mockGame = new Game()
            {
                GameId = 1
            };

            var mockGameRepository = new MockGameRepository().MockGetGameByID(mockGame);
            var controller         = new GamesController(mockGameRepository.Object);

            //act
            var result = await controller.Details(1);

            //Assert
            Assert.IsAssignableFrom <ActionResult <Game> >(result);
            mockGameRepository.VerifyGetGameByID(Times.Once());
        }
        public async Task Details_IdNotNullAndGameViewModelNull_ReturnsHttpNotFound()
        {
            // Arrange
            var controller = new GamesController(_service, _sharedService);

            int?id = 1;

            GameViewModel game = null;

            A.CallTo(() => _service.FindEntityAsync(A <int> .Ignored, null)).Returns(game);

            // Act
            var result = await controller.Details(id);

            // Assert
            A.CallTo(() => _service.FindEntityAsync((int)id, null)).MustHaveHappenedOnceExactly();

            Assert.IsInstanceOf <HttpNotFoundResult>(result);
        }
        public async void TestSelect_InvalidGame_ShouldFail(string value)
        {
            // Arrange
            GamesController controller = new GamesController(_context, _webHostEnvironment);

            InitializeGame();
            game.GameId = int.Parse(value);

            try
            {
                // Act
                var result = await controller.Details(game.GameId);
            }
            // Assert
            catch (Exception ex)
            {
                Assert.Equal("Xunit.Sdk.IsTypeException", ex.GetType().ToString());
            }
        }
        public async Task Details_WhenIdIsNull_ShouldReturnNotFound()
        {
            // 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);

            int?id = null;

            // Act
            var result = await testController.Details(id);

            // Assert
            result.ShouldBeOfType <NotFoundResult>();
        }