public void TestThrowsExceptionIfMatchIsNull() { MatchValidator matchVali = new MatchValidator(); Match match = null; Exception ex = Assert.Throws <InvalidDataException>(() => matchVali.CheckIfMatchIsNull(match)); Assert.Equal("Match must be something", ex.Message); }
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); }
internal static bool ValidateSecondPlayer(string firstPlayer, string secondPlayer, out string message) { try { MatchValidator.ValidateSecondPlayer(firstPlayer, secondPlayer); message = string.Empty; return(true); } catch (Exception ex) { message = ex.Message; return(false); } }
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); }
public void TestThrowsExceptionIfMatchStartDateIsBeforeTodayOnCreate() { MatchValidator matchVali = new MatchValidator(); Match match = new Match() { GuestTeam = "DBF", HomeTeam = "FBC", HomeScore = 2, GuestScore = 2, StartDate = new DateTime(2019, 11, 10) }; Exception ex = Assert.Throws <InvalidDataException>(() => matchVali.ValidateMatchStartDate(match)); Assert.Equal("Start date on match cannot be before today", ex.Message); }
static void Main(string[] args) { DatabaseConnectionManager databaseConnectionManager = new DatabaseConnectionManager(); UserValidator userValidator = new UserValidator(); MatchValidator matchValidator = new MatchValidator(); TicketValidator ticketValidator = new TicketValidator(); UserRepository userRepository = new UserRepository(databaseConnectionManager, "users", userValidator); TicketRepository ticketRepository = new TicketRepository(databaseConnectionManager, "tickets", ticketValidator); MatchRepository matchRepository = new MatchRepository(databaseConnectionManager, "matches", matchValidator); UserService userService = new UserService(userRepository); MatchService matchService = new MatchService(matchRepository); TicketService ticketService = new TicketService(ticketRepository, matchRepository); SellTicketsServer sellTicketsServer = new SellTicketsServer(ticketService, userService, matchService); ConcurrentServer concurrentServer = new SerialSellTicketsServer("127.0.0.1", 5555, sellTicketsServer); concurrentServer.Start(); }
internal static bool ValidateSetsToPlay(string numberOfSets, out string message) { try { if (int.TryParse(numberOfSets, out int maxNumberOfSetsToPlay)) { MatchValidator.ValidateSetsToPlay(maxNumberOfSetsToPlay); message = string.Empty; return(true); } else { message = "El numero de los Sets del partido debe tener un valor numérico"; return(false); } } catch (Exception ex) { message = ex.Message; return(false); } }
static void Main(string[] args) { DatabaseConnectionManager databaseConnectionManager = new DatabaseConnectionManager(); UserValidator userValidator = new UserValidator(); MatchValidator matchValidator = new MatchValidator(); TicketValidator ticketValidator = new TicketValidator(); UserRepository userRepository = new UserRepository(databaseConnectionManager, "users", userValidator); TicketRepository ticketRepository = new TicketRepository(databaseConnectionManager, "tickets", ticketValidator); MatchRepository matchRepository = new MatchRepository(databaseConnectionManager, "matches", matchValidator); UserService userService = new UserService(userRepository); MatchService matchService = new MatchService(matchRepository); TicketService ticketService = new TicketService(ticketRepository, matchRepository); SellTicketsServer sellTicketsServer = new SellTicketsServer(ticketService, userService, matchService); var server = new Grpc.Core.Server { Services = { AppService.BindService(sellTicketsServer) }, Ports = { new ServerPort("localhost", 5555, ServerCredentials.Insecure) } }; server.Start(); while (true) { var line = Console.ReadLine(); if (line != null && line.ToLower().Equals("exit")) { server.ShutdownAsync().Wait(); break; } } }
public MatchService(IMatchRepository matchRepo, IRoundService roundService) { _matchRepo = matchRepo; _roundService = roundService; _matchVali = new MatchValidator(); }
private int AddMatch() { var tOvers = 20; switch (mOvers.SelectedItem.ToString()) { case "Ten10": tOvers = 10; break; case "Twenty20": tOvers = 20; break; case "ThirtyFive35": tOvers = 35; break; case "Forty40": tOvers = 40; break; case "Fifty50": tOvers = 50; break; case "Custom": tOvers = 0; break; default: tOvers = Convert.ToInt32(mOvers.SelectedItem.ToString()); break; } var teams = Access.TeamService.GetTeams(); var homeTeam = teams.Where(n => n.Name.ToLower() == mHomeTeamName.SelectedItem.ToString().ToLower()).FirstOrDefault(); var awayTeam = teams.Where(n => n.Name.ToLower() == mAwayTeamName.SelectedItem.ToString().ToLower()).FirstOrDefault(); var match = new Match { TotalOvers = tOvers, Location = mLocation.SelectedItem.ToString(), UmpireOne = mUmpireOne.SelectedItem.ToString(), UmpireTwo = mUmpireTwo.SelectedItem.ToString(), HomeTeam = homeTeam == null ? null : Access.TeamService.MapTeamEntityToTeam(homeTeam), AwayTeam = awayTeam == null ? null : Access.TeamService.MapTeamEntityToTeam(awayTeam) }; var matchvalid = new MatchValidator().Validate(match); if (matchvalid.Any()) { Toast.MakeText(this.Activity, string.Join(System.Environment.NewLine, matchvalid.ToArray()), ToastLength.Long).Show(); return(0); } match.Location = (match.Location == @"Select Ground/Location") ? "" : match.Location; match.UmpireOne = (match.UmpireOne == @"Select Umpire") ? "" : match.UmpireOne; match.UmpireTwo = (match.UmpireTwo == @"Select Umpire") ? "" : match.UmpireTwo; var matchId = Access.MatchService.AddMatch(match); if (!string.IsNullOrEmpty(match.UmpireOne)) { Access.UmpireService.AddUmpire(matchId, match.UmpireOne, true); } if (!string.IsNullOrEmpty(match.UmpireTwo)) { Access.UmpireService.AddUmpire(matchId, match.UmpireTwo, string.IsNullOrEmpty(match.UmpireOne) ? true : false); } //Copy players into new match var homeTeamPlayers = Access.PlayerService.GetPlayersPerTeam(homeTeam.Id).GroupBy(hp => hp.Name).Select(hn => hn.First()).ToList(); //Remove multiple captain and keepers if (homeTeamPlayers.Where(n => n.Name.Contains("*")).Count() > 1) { for (int i = 1; i < homeTeamPlayers.Count; i++) { homeTeamPlayers[i].Name = homeTeamPlayers[i].Name.Trim('*'); } } if (homeTeamPlayers.Where(n => n.Name.Contains("†")).Count() > 1) { for (int i = 1; i < homeTeamPlayers.Count; i++) { homeTeamPlayers[i].Name = homeTeamPlayers[i].Name.Trim('†'); } } foreach (var hname in homeTeamPlayers) { Access.PlayerService.AddPlayer(homeTeam.Id, matchId, hname.Name); } var awayTeamPlayers = Access.PlayerService.GetPlayersPerTeam(awayTeam.Id).GroupBy(ap => ap.Name).Select(an => an.First()).ToList(); //Remove multiple captain and keepers if (awayTeamPlayers.Where(n => n.Name.Contains("*")).Count() > 1) { for (int i = 1; i < awayTeamPlayers.Count; i++) { awayTeamPlayers[i].Name = awayTeamPlayers[i].Name.Trim('*'); } } if (awayTeamPlayers.Where(n => n.Name.Contains("†")).Count() > 1) { for (int i = 1; i < awayTeamPlayers.Count; i++) { awayTeamPlayers[i].Name = awayTeamPlayers[i].Name.Trim('†'); } } foreach (var aname in awayTeamPlayers) { Access.PlayerService.AddPlayer(awayTeam.Id, matchId, aname.Name); } return(matchId); }
public MatchRepository(DatabaseConnectionManager databaseConnectionManager, string tableName, MatchValidator validator) : base(databaseConnectionManager, tableName, validator) { }