예제 #1
0
 public List <Match> CreateMatches(List <Match> matches)
 {
     try
     {
         foreach (Match match in matches)
         {
             _matchVali.CheckIfMatchIsNull(match);
             _matchVali.ValidateMatch(match);
             _matchVali.ValidateMatchStartDate(match);
         }
         return(_matchRepo.CreateMatch(matches).ToList());
     }catch (Exception ex)
     {
         throw ex;
     }
 }
        public void TestThrowsExceptionIfGuestTeamIsEmptyOrNull()
        {
            MatchValidator matchVali = new MatchValidator();

            Match match = new Match()
            {
                GuestTeam = "",
                HomeTeam  = "FBC"
            };
            Exception ex = Assert.Throws <InvalidDataException>(() =>
                                                                matchVali.ValidateMatch(match));

            Assert.Equal("The home and guest team on a match cannot be empty", ex.Message);
        }
        public void TestThrowsExceptionIfGuestScoreIsNegative()
        {
            MatchValidator matchVali = new MatchValidator();

            Match match = new Match()
            {
                GuestTeam  = "DBF",
                HomeTeam   = "FBC",
                HomeScore  = 2,
                GuestScore = -1
            };
            Exception ex = Assert.Throws <InvalidDataException>(() =>
                                                                matchVali.ValidateMatch(match));

            Assert.Equal("Home and Guest score cannot be lower than zero", ex.Message);
        }
        public void TestThrowsExceptionIfGuestTeamContainsNumbers()
        {
            MatchValidator matchVali = new MatchValidator();

            Match match = new Match()
            {
                GuestTeam  = "DBF33",
                HomeTeam   = "FBC",
                HomeScore  = 2,
                GuestScore = 3,
            };
            Exception ex = Assert.Throws <InvalidDataException>(() =>
                                                                matchVali.ValidateMatch(match));

            Assert.Equal("The teams on match cannot contain numbers", ex.Message);
        }