public void ValidResponseCreate()
        {
            MatchesController controller = new MatchesController(databaseContext);
            IActionResult     result     = controller.Create() as IActionResult;

            Assert.IsNotNull(result);
        }
Example #2
0
        public async void CreateButtonTest()
        {
            //Arrange
            var db = MockDb.CreateMockDb();
            var c  = new MatchesController(db);

            var match = new Matches {
                Matche_Id = 2, AwayTeam_Id = 2, MatchDate = DateTime.Now, Stadium_Id = 1
            };

            //Act
            await c.Create(match);

            var r = c.Create();

            //Assert
            Assert.IsType <ViewResult>(r);
        }
Example #3
0
        public async void EditWrongIdTest()
        {
            //Arrange
            var db = MockDb.CreateMockDb();
            var c  = new MatchesController(db);

            var match = new Matches {
                Matche_Id = 2, AwayTeam_Id = 2, MatchDate = DateTime.Now, Stadium_Id = 1
            };
            //Act
            await c.Create(match);

            var r = await c.Edit(db.Matches.Find(1).Matche_Id, match);

            //Assert
            Assert.IsType <NotFoundResult>(r);
        }
Example #4
0
        public async void TestAddMatch()
        {
            //Arrange
            var db = MockDb.CreateMockDb();
            var c  = new MatchesController(db);


            var match = new Matches {
                Matche_Id = 2, HomeTeam_Id = 1, AwayTeam_Id = 2, MatchDate = DateTime.Now, Stadium_Id = 1
            };
            //Act
            var r = await c.Create(match);

            //Assert
            var result = Assert.IsType <RedirectToActionResult>(r);

            Assert.Equal("Index", result.ActionName);
            Assert.Equal(1, db.Matches.Where(x => x.Matche_Id == match.Matche_Id && x.HomeTeam_Id == match.HomeTeam_Id && x.AwayTeam_Id == match.AwayTeam_Id && x.MatchDate == match.MatchDate && x.Stadium_Id == match.Stadium_Id).Count());
        }
Example #5
0
        public async void DeleteConfirmTest()
        {
            //Arrange
            var db = MockDb.CreateMockDb();
            var c  = new MatchesController(db);

            var match = new Matches {
                Matche_Id = 2, AwayTeam_Id = 2, MatchDate = DateTime.Now, Stadium_Id = 1
            };
            //Act
            var r = await c.Create(match);

            //Finds the second element stores in a tmp variable
            var elementToDelete = db.Matches.Find(2);

            await c.DeleteConfirmed(elementToDelete.Matche_Id);

            Assert.DoesNotContain(elementToDelete, db.Matches);
        }
Example #6
0
        public async void EditTest()
        {
            //Arrange
            var db     = MockDb.CreateMockDb();
            var c      = new MatchesController(db);
            int tempId = 1;

            var match = new Matches {
                Matche_Id = 2, AwayTeam_Id = 2, MatchDate = DateTime.Now, Stadium_Id = 1
            };
            //Act
            await c.Create(match);

            match.AwayTeam_Id = tempId;
            var r = await c.Edit(db.Matches.Find(2).Matche_Id, match);

            //Assert
            Assert.IsType <RedirectToActionResult>(r);
            Assert.Equal(db.Matches.Find(2).AwayTeam_Id, tempId);
        }
Example #7
0
        public async void DeletePageTest()
        {
            //Arrange
            var db = MockDb.CreateMockDb();
            var c  = new MatchesController(db);

            var match = new Matches {
                Matche_Id = 2, AwayTeam_Id = 2, MatchDate = DateTime.Now, Stadium_Id = 1
            };
            //Act
            await c.Create(match);

            var r = await c.Delete(db.Matches.Find(2).Matche_Id);


            //Assert
            var result = Assert.IsType <ViewResult>(r);
            var model  = Assert.IsAssignableFrom <Matches>(result.ViewData.Model);

            Assert.Equal(db.Matches.Find(2).Matche_Id, model.Matche_Id);
            Assert.Equal(db.Matches.Find(2).AwayTeam_Id, model.AwayTeam_Id);
        }
        public async void CreatePageForEmptyAccountTest()
        {
            // Arrange
            const string userId = "MyUserId";

            Context.Add(new ApplicationUser
            {
                Id = userId
            });
            Context.SaveChanges();
            var user = new ClaimsPrincipal(
                new[]
            {
                new ClaimsIdentity(
                    new[]
                {
                    new Claim(ClaimTypes.NameIdentifier, userId)
                })
            });

            var controller = new MatchesController(Context, UserManager, StringLocalizerMock.Object,
                                                   InviteServiceMock.Object, LeaguesRepositoryMock.Object)
            {
                ControllerContext = new ControllerContext
                {
                    HttpContext = new DefaultHttpContext {
                        User = user
                    }
                }
            };

            // Act
            var result = await controller.Create(null);

            // Assert
            result.Should().BeOfType <RedirectToActionResult>().Which.ControllerName.Should().Be("Leagues");
            result.Should().BeOfType <RedirectToActionResult>().Which.ActionName.Should().Be("NoLeagues");
        }
Example #9
0
        public async void TestAddInvalidMatch()
        {
            //Arrange
            var db = MockDb.CreateMockDb();
            var c  = new MatchesController(db);


            var match = new Matches {
                Matche_Id = 2, AwayTeam_Id = 2, MatchDate = DateTime.Now, Stadium_Id = 1
            };

            c.ModelState.AddModelError("HomeTeam_Id", "Required");
            //Act
            var r = await c.Create(match);

            //Assert
            var result = Assert.IsType <ViewResult>(r);
            var model  = Assert.IsAssignableFrom <Matches>(result.ViewData.Model);

            Assert.Equal(match, model);
            Assert.IsType <SelectList>(result.ViewData["AwayTeam_Id"]);
            Assert.IsType <SelectList>(result.ViewData["HomeTeam_Id"]);
            Assert.IsType <SelectList>(result.ViewData["Stadium_Id"]);
        }
Example #10
0
        public async void EditModelStateNotValidTest()
        {
            //Arrange
            var db = MockDb.CreateMockDb();
            var c  = new MatchesController(db);

            var match = new Matches {
                Matche_Id = 2, MatchDate = DateTime.Now, Stadium_Id = 1
            };


            //Act
            await c.Create(match);

            c.ModelState.AddModelError("AwayTeam_Id", "Required");

            var r = await c.Edit(db.Matches.Find(2).Matche_Id, match);

            //Assert
            var result = Assert.IsType <ViewResult>(r);
            var model  = Assert.IsAssignableFrom <Matches>(result.ViewData.Model);

            Assert.Equal(match, model);
        }