public void CheckFunctionCreate()
        {
            // Count the number of leagues in the database
            var preCountTask = databaseContext.League.CountAsync();

            preCountTask.Wait();
            int preCount = preCountTask.Result;

            // Create the controller and call the Create method
            LeaguesController controller = new LeaguesController(databaseContext);
            League            league     = new League();

            league.Year = "2007";
            var resultTask = controller.Create(league);

            resultTask.Wait();
            IActionResult result = resultTask.Result as IActionResult;

            // Count the number of leagues in the database after the change
            var postCountTask = databaseContext.League.CountAsync();

            postCountTask.Wait();
            int postCount = postCountTask.Result;

            // Check that there is one more league in the database than what was
            //  in it previous to the Create method call
            Assert.AreEqual(preCount + 1, postCount);
        }
        public void ValidResponseCreate()
        {
            // Create the League controller
            LeaguesController controller = new LeaguesController(databaseContext);

            // Call the Create page
            IActionResult result = controller.Create() as IActionResult;

            // Check that the controller returned a valid response
            Assert.IsNotNull(result);
        }
示例#3
0
        public void CreateGet_ShouldReturnLeagueCreateView()
        {
            // Arrange
            var leaguesIndexViewModel   = A.Fake <ILeaguesIndexViewModel>();
            var leaguesDetailsViewModel = A.Fake <ILeaguesDetailsViewModel>();
            var leagueRepository        = A.Fake <ILeagueRepository>();
            var sharedRepository        = A.Fake <ISharedRepository>();
            var testController          = new LeaguesController(leaguesIndexViewModel, leaguesDetailsViewModel,
                                                                leagueRepository, sharedRepository);

            // Act
            var result = testController.Create();

            // Assert
            result.ShouldBeOfType <ViewResult>();
        }
示例#4
0
        public async Task CreatePost_WhenModelStateIsValid_ShouldAddLeagueToDataStoreAndRedirectToIndexView()
        {
            // Arrange
            var leaguesIndexViewModel   = A.Fake <ILeaguesIndexViewModel>();
            var leaguesDetailsViewModel = A.Fake <ILeaguesDetailsViewModel>();
            var leagueRepository        = A.Fake <ILeagueRepository>();
            var sharedRepository        = A.Fake <ISharedRepository>();
            var testController          = new LeaguesController(leaguesIndexViewModel, leaguesDetailsViewModel,
                                                                leagueRepository, sharedRepository);

            var league = new League();

            // Act
            var result = await testController.Create(league);

            // Assert
            A.CallTo(() => leagueRepository.AddAsync(league)).MustHaveHappenedOnceExactly();
            A.CallTo(() => sharedRepository.SaveChangesAsync()).MustHaveHappenedOnceExactly();
            result.ShouldBeOfType <RedirectToActionResult>();
            ((RedirectToActionResult)result).ActionName.ShouldBe <string>(nameof(testController.Index));
        }
示例#5
0
        public async Task CreatePost_WhenModelStateIsNotValid_ShouldReturnLeagueCreateView()
        {
            // Arrange
            var leaguesIndexViewModel   = A.Fake <ILeaguesIndexViewModel>();
            var leaguesDetailsViewModel = A.Fake <ILeaguesDetailsViewModel>();
            var leagueRepository        = A.Fake <ILeagueRepository>();
            var sharedRepository        = A.Fake <ISharedRepository>();
            var testController          = new LeaguesController(leaguesIndexViewModel, leaguesDetailsViewModel,
                                                                leagueRepository, sharedRepository);

            var league = new League();

            testController.ModelState.AddModelError("LongName", "Please enter a long name.");

            // Act
            var result = await testController.Create(league);

            // Assert
            A.CallTo(() => leagueRepository.AddAsync(league)).MustNotHaveHappened();
            A.CallTo(() => sharedRepository.SaveChangesAsync()).MustNotHaveHappened();
            result.ShouldBeOfType <ViewResult>();
            ((ViewResult)result).Model.ShouldBe(league);
        }