public void AddMatchesToRespectiveGroupsAndReturnsUpdatedState()
        {
            HTEC.Match m1 = new HTEC.Match()
            {
                GroupName = GroupName.A, HomeTeam = "Juventus", AwayTeam = "Napoli", Score = "2:2", Matchday = Matchday.First
            };
            HTEC.Match m2 = new HTEC.Match()
            {
                GroupName = GroupName.B, HomeTeam = "Torino", AwayTeam = "Parma", Score = "2:2", Matchday = Matchday.First
            };

            IEnumerable <HTEC.Group> groups = repository.AddMatches(new List <HTEC.Match>()
            {
                m1, m2
            });

            Assert.NotNull(groups);
            Assert.True(groups.Count() == 8);
            Assert.True(groups.FirstOrDefault(x => x.Name == GroupName.A) != null);
            Assert.True(groups.FirstOrDefault(x => x.Name == GroupName.A).Standing.Count == 4);
            Assert.True(groups.FirstOrDefault(x => x.Name == GroupName.B) != null);
            Assert.True(groups.FirstOrDefault(x => x.Name == GroupName.B).Standing.Count == 2);
            Assert.True(groups.FirstOrDefault(x => x.Name == GroupName.C) != null);
            Assert.True(groups.FirstOrDefault(x => x.Name == GroupName.C).Standing.Count == 2);
            Assert.True(groups.FirstOrDefault(x => x.Name == GroupName.D) != null);
            Assert.True(groups.FirstOrDefault(x => x.Name == GroupName.E) != null);
            Assert.True(groups.FirstOrDefault(x => x.Name == GroupName.F) != null);
            Assert.True(groups.FirstOrDefault(x => x.Name == GroupName.G) != null);
            Assert.True(groups.FirstOrDefault(x => x.Name == GroupName.H) != null);
        }
        public void DELETE_DeleteMatch_ReturnsOkIfValidMatchParametersSent()
        {
            ActionResult <HTEC.Match> actionResult = controller.Delete(validMatchParam);

            Assert.NotNull(actionResult);
            Assert.IsType <ActionResult <HTEC.Match> >(actionResult);
            OkObjectResult res = Assert.IsType <OkObjectResult>(actionResult.Result);

            HTEC.Match match = Assert.IsType <HTEC.Match>(res.Value);
            Assert.True(match.Id == validMatchParam);
        }
        public void ReturnsNullIfMatchToDeleteDoesNotExistInDb()
        {
            int matchCountBefore = repository.GetMatches(new HTEC.MatchFilter()).Count();

            HTEC.Match m = repository.DeleteMatch(999);

            int matchCountAfter = repository.GetMatches(new HTEC.MatchFilter()).Count();

            Assert.Null(m);
            Assert.True(matchCountBefore == matchCountAfter);
        }
        public void DeletesMatchFromDbIfFound()
        {
            int matchCountBefore = repository.GetMatches(new HTEC.MatchFilter()).Count();

            HTEC.Match m = repository.DeleteMatch(100);

            int matchCountAfter = repository.GetMatches(new HTEC.MatchFilter()).Count();

            Assert.NotNull(m);
            Assert.True(matchCountBefore > matchCountAfter);
        }
        public void ThrowsExceptionWhenNoValidMatchesAreSent()
        {
            HTEC.Match m = new HTEC.Match()
            {
                HomeTeam = "Inter", Score = "2:2"
            };

            Assert.Throws <ArgumentException>(() => { repository.AddMatches(new List <HTEC.Match>()
                {
                    m
                }); });
        }
        private void InitializeGroups(Mock <IMatchRepository> repositoryMock)
        {
            HTEC.Match m1 = new HTEC.Match()
            {
                Id = 101, GroupName = GroupName.A, HomeTeam = "Inter", AwayTeam = "Milan", Score = "3:0", Matchday = Matchday.First
            };

            IEnumerable <HTEC.Match> matches1 = new List <HTEC.Match>(4)
            {
                m1,
                new HTEC.Match()
                {
                    Id = 102, GroupName = GroupName.A, HomeTeam = "Juventus", AwayTeam = "Napoli", Score = "3:1", Matchday = Matchday.First
                },
                new HTEC.Match()
                {
                    Id = 103, GroupName = GroupName.A, HomeTeam = "Napoli", AwayTeam = "Milan", Score = "2:0", Matchday = Matchday.Second
                },
                new HTEC.Match()
                {
                    Id = 104, GroupName = GroupName.A, HomeTeam = "Inter", AwayTeam = "Juventus", Score = "1:0", Matchday = Matchday.Second
                }
            };

            Group group1 = new Group(GroupName.A, matches1);

            IEnumerable <HTEC.Match> matches2 = new List <HTEC.Match>(4)
            {
                new HTEC.Match()
                {
                    GroupName = GroupName.C, HomeTeam = "Parma", AwayTeam = "Fiorentina", Score = "0:2", Matchday = Matchday.First
                },
                new HTEC.Match()
                {
                    GroupName = GroupName.C, HomeTeam = "Lazio", AwayTeam = "Roma", Score = "1:1", Matchday = Matchday.First
                },
                new HTEC.Match()
                {
                    GroupName = GroupName.C, HomeTeam = "Parma", AwayTeam = "Roma", Score = "1:2", Matchday = Matchday.Second
                },
                new HTEC.Match()
                {
                    GroupName = GroupName.C, HomeTeam = "Fiorentina", AwayTeam = "Lazio", Score = "1:0", Matchday = Matchday.Second
                }
            };

            Group group2 = new Group(GroupName.C, matches2);

            repositoryMock.Setup(x => x.GetGroupResults(validGroupsList)).Returns(new List <Group>(2)
            {
                group1, group2
            });
            repositoryMock.Setup(x => x.GetMatch(validMatchParam)).Returns(m1);
            repositoryMock.Setup(x => x.DeleteMatch(validMatchParam)).Returns(m1);
            repositoryMock.Setup(x => x.EditMatches(invalidUpdates)).Throws <ArgumentException>();
            repositoryMock.Setup(x => x.AddMatches(invalidMatches)).Throws <ArgumentException>();
            repositoryMock.Setup(x => x.AddMatches(validMatches)).Returns(new List <Group>(2)
            {
                group1, group2
            });
            repositoryMock.Setup(x => x.GetMatches(invalidFilter)).Throws <ArgumentException>();
            repositoryMock.Setup(x => x.GetMatches(validFilter)).Returns(matches1);
        }
        public void ReturnsMatchFromDbIfExists()
        {
            HTEC.Match m = repository.GetMatch(100);

            Assert.NotNull(m);
        }
        public void ReturnsNullIfMatchDoesNotExistInDb()
        {
            HTEC.Match m = repository.GetMatch(999);

            Assert.Null(m);
        }