Пример #1
0
        public async void Given_MatchDoesExist_When_GetTeamLeagueMatchDetails_Then_ReturnMatch()
        {
            // Arrange
            var teams  = new TeamsBuilder().Build();
            var league = new TeamLeagueBuilder()
                         .WithCompetitors(teams)
                         .WithRounds()
                         .Build();
            var leagues     = Enumerable.Repeat(league, 1);
            var contextMock = MockDbContext(leagues.AsQueryable());
            var handler     = new GetTeamLeagueMatchDetailsQueryHandler(
                contextMock.Object
                );

            //Act
            var guid    = new Guid("00000000-0000-0000-0000-000000000000");
            var request = new GetTeamLeagueMatchDetailsQuery
            {
                LeagueName = "Premier League",
                Guid       = guid
            };
            var result = await handler.Handle(request, CancellationToken.None);

            //Assert
            result.Should().NotBeNull();
            result.Guid.Should().Be(guid);
            result.RoundName.Should().Be("Round 1");
            result.Home().Should().NotBeNull();
            result.Away().Should().NotBeNull();

            //Assert lineup
            result.MatchEntries[0].Lineup.Count.Should().Be(11);
            int number = 1;

            result.MatchEntries[0].Lineup.ForEach(l =>
            {
                l.PlayerNumber.Should().Be(number.ToString());
                l.TeamMatchEntryTeamName.Should().Be("Tottenham Hotspur");
                number++;
            });

            result.MatchEntries[1].Lineup.Count.Should().Be(11);
            number = 1;
            result.MatchEntries[1].Lineup.ForEach(l =>
            {
                l.PlayerNumber.Should().Be(number.ToString());
                l.TeamMatchEntryTeamName.Should().Be("Manchester City");
                number++;
            });
        }
        public async void Given_TeamLeagueExist_When_GetTeamLeagueTable_Then_ReturnTable()
        {
            // Arrange
            var sports = new TeamSports
            {
                Options = new TeamSportsOptions
                {
                    AmountOfPlayers = 11
                }
            };
            var teams  = new TeamsBuilder().Build();
            var league = new TeamLeagueBuilder()
                         .WithCompetitors(teams)
                         .Build();

            league.Sports = sports;
            league.CreateRounds();

            var scores = new List <Tuple <Tuple <Team, int>, Tuple <Team, int> > >
            {
                AddScore(teams[0], teams[1], 1, 0),
                AddScore(teams[2], teams[3], 1, 1),
                AddScore(teams[0], teams[2], 2, 1),
                AddScore(teams[3], teams[1], 0, 1)
            };

            SetScores(league, scores);

            var contextMock = MockDbContext(new TeamLeague[] { league }.AsQueryable());
            var handler     = new GetTeamLeagueTableQueryHandler(
                contextMock.Object, Mapper.CreateMapper());

            //Act
            var result = await handler.Handle(new GetTeamLeagueTableQuery { LeagueName = "Premier League" }, CancellationToken.None);

            //Assert
            result.Should().NotBeNull();
            result.Table.Items.Should().NotBeNull();
            result.Table.Items.Count.Should().Be(4);
            result.Table.Items[0].Position.Should().Be(1);
            result.Table.Items[0].GamesPlayed.Should().Be(2);
            result.Table.Items[0].GamesWon.Should().Be(2);
            result.Table.Items[0].GamesDrawn.Should().Be(0);
            result.Table.Items[0].GamesLost.Should().Be(0);
            result.Table.Items[0].GoalsFor.Should().Be(3);
            result.Table.Items[0].GoalsAgainst.Should().Be(1);
            result.Table.Items[0].GoalDifference.Should().Be(2);
            result.Table.Items[0].Points.Should().Be(6);
        }
Пример #3
0
        public async void Given_SubstitutionDoesExist_When_UpdateTeamLeagueSubstitution_Then_SubstitutionIsUpdated()
        {
            //Arrange
            var teams  = new TeamsBuilder().Build();
            var league = new TeamLeagueBuilder()
                         .WithCompetitors(teams)
                         .WithRounds()
                         .WithSubstitutions()
                         .Build();
            var players = new PlayerBuilder().Build();

            var leagues          = Enumerable.Repeat(league, 1);
            var matchGuid        = new Guid("00000000-0000-0000-0000-000000000000");
            var match            = league.GetMatch(matchGuid);
            var teamName         = "Tottenham Hotspur";
            var matchEntry       = match.MatchEntries.SingleOrDefault(me => me.Team.Name == teamName);
            var substitutionGuid = matchEntry.Substitutions.ToList()[0].Guid;
            var contextMock      = MockDbContext(
                leagues.AsQueryable(),
                players.AsQueryable()
                );
            var loggerMock = new Mock <ILogger <UpdateTeamLeagueMatchSubstitutionCommandHandler> >();

            var handler = new UpdateTeamLeagueMatchSubstitutionCommandHandler(
                contextMock.Object,
                loggerMock.Object
                );

            //Act
            var command = new UpdateTeamLeagueMatchSubstitutionCommand
            {
                LeagueName       = league.Name,
                MatchGuid        = matchGuid,
                TeamName         = teamName,
                SubstitutionGuid = substitutionGuid,
                Minute           = "1",
                PlayerOut        = players[0].FullName,
                PlayerIn         = players[1].FullName
            };

            var sub = await handler.Handle(command, CancellationToken.None);

            //Assert
            sub.Guid.Should().Be(substitutionGuid);
            sub.TeamMatchEntryTeamName.Should().Be(teamName);
            sub.Minute.Should().Be("1");
            sub.PlayerOut.FullName.Should().Be(players[0].FullName);
            sub.PlayerIn.FullName.Should().Be(players[1].FullName);
        }
        public void Given_PlayerDoesNotExist_When_UpdateTeamLeagueGoal_Then_PlayerNotFoundExceptionIsThrown()
        {
            //Arrange
            var teams  = new TeamsBuilder().Build();
            var league = new TeamLeagueBuilder()
                         .WithCompetitors(teams)
                         .WithRounds()
                         .WithGoals()
                         .Build();
            var players = new PlayerBuilder().Build();
            var player  = players[0];

            var leagues     = Enumerable.Repeat(league, 1);
            var matchGuid   = new Guid("00000000-0000-0000-0000-000000000000");
            var match       = league.GetMatch(matchGuid);
            var matchEntry  = match.MatchEntries.SingleOrDefault(me => me.Team.Name == "Tottenham Hotspur");
            var goalGuid    = matchEntry.Goals.ToList()[0].Guid;
            var contextMock = MockDbContext(
                leagues.AsQueryable(),
                players.AsQueryable()
                );
            var loggerMock = new Mock <ILogger <UpdateTeamLeagueMatchGoalCommandHandler> >();

            var handler = new UpdateTeamLeagueMatchGoalCommandHandler(
                contextMock.Object,
                Mapper.MapperConfig(),
                loggerMock.Object
                );

            //Act
            var command = new UpdateTeamLeagueMatchGoalCommand
            {
                LeagueName = league.Name,
                MatchGuid  = matchGuid,
                TeamName   = "Tottenham Hotspur",
                GoalGuid   = goalGuid,
                Minute     = "1",
                PlayerName = "DoesNotExist"
            };

            Func <Task> func = async() => await handler.Handle(command, CancellationToken.None);

            //Assert

            func.Should().Throw <PlayerNotFoundException>();
        }
Пример #5
0
        public async void Given_TeamLeagueDoesNotExist_When_CreateTeamLeague_Then_TeamLeagueIsCreated()
        {
            // Arrange
            var teamSports = new List <TeamSports> {
                new TeamSports {
                    Name    = "Soccer",
                    Options = new TeamSportsOptions {
                        AmountOfPlayers = 11
                    }
                }
            };
            var countries = new List <Country>();
            var leagues   = new List <TeamLeague>();
            var teams     = new TeamsBuilder().Build();

            var contextMock = MockDbContext(
                teamSports.AsQueryable(),
                countries.AsQueryable(),
                leagues.AsQueryable(),
                teams.AsQueryable());
            var handler = new CreateTeamLeagueCommandHandler(contextMock.Object, Mapper.CreateMapper());

            //Act
            var request = new CreateTeamLeagueCommand {
                Sports        = "Soccer",
                Name          = "Premier League",
                SelectedTeams = teams.Select(t => t.Name).ToList()
            };
            var result = await handler.Handle(request, CancellationToken.None);

            //Assert
            result.Should().BeOfType <TeamLeagueDto>();
            result.Rounds.Count().Should().Be((teams.Count - 1) * 2);
            result.Rounds.ToList().ForEach(r => {
                r.Matches.Count().Should().Be(teams.Count / 2);
                r.Matches.ToList().ForEach(m => {
                    m.MatchEntries.Count().Should().Be(2);
                    m.MatchEntries.ForEach(me => me.Lineup.Count().Should().Be(teamSports[0].Options.AmountOfPlayers));
                });
            });
            contextMock.Verify(mock => mock.SaveChangesAsync(It.IsAny <CancellationToken>()), Times.Once());
        }
Пример #6
0
        public void Given_LeagueDoesNotExist_When_UpdateTeamLeagueMatchScore_Then_ThrowTeamLeagueNotFoundException()
        {
            //Arrange
            var teams  = new TeamsBuilder().Build();
            var league = new TeamLeagueBuilder()
                         .WithCompetitors(teams)
                         .WithRounds()
                         .Build();

            var contextMock = MockDbContext(Enumerable.Repeat(league, 1).AsQueryable());
            var handler     = new UpdateTeamLeagueMatchScoreCommandHandler(
                contextMock.Object, Mapper.CreateMapper()
                );

            //Act
            var request = new UpdateTeamLeagueMatchScoreCommand
            {
                LeagueName   = "DoesNotExist",
                Guid         = new Guid("00000000-0000-0000-0000-000000000000"),
                MatchEntries = new List <TeamMatchEntryRequestDto>
                {
                    new TeamMatchEntryRequestDto
                    {
                        Team  = "Tottenham Hotspur",
                        Score = 1,
                    }
                    ,
                    new TeamMatchEntryRequestDto
                    {
                        Team  = "Manchester City",
                        Score = 1
                    }
                }
            };
            Func <Task> func = async() => await handler.Handle(request, CancellationToken.None);

            //Assert
            func.Should().Throw <TeamLeagueNotFoundException>();
            contextMock.Verify(mock => mock.SaveChangesAsync(It.IsAny <CancellationToken>()), Times.Never());
        }
Пример #7
0
        public async void Given_MatchDoesExist_When_UpdateTeamLeagueMatchScore_Then_ScoreIsUpdated()
        {
            //Arrange
            var teams  = new TeamsBuilder().Build();
            var league = new TeamLeagueBuilder()
                         .WithCompetitors(teams)
                         .WithRounds()
                         .Build();

            var contextMock = MockDbContext(Enumerable.Repeat(league, 1).AsQueryable());
            var handler     = new UpdateTeamLeagueMatchScoreCommandHandler(
                contextMock.Object, Mapper.CreateMapper()
                );

            //Act
            var request = new UpdateTeamLeagueMatchScoreCommand
            {
                LeagueName   = "Premier League",
                Guid         = new Guid("00000000-0000-0000-0000-000000000000"),
                MatchEntries = new List <TeamMatchEntryRequestDto>
                {
                    new TeamMatchEntryRequestDto
                    {
                        Team  = "Tottenham Hotspur",
                        Score = 1,
                    }
                    ,
                    new TeamMatchEntryRequestDto
                    {
                        Team  = "Manchester City",
                        Score = 1
                    }
                }
            };
            var result = await handler.Handle(request, CancellationToken.None);

            //Assert
            contextMock.Verify(mock => mock.SaveChangesAsync(It.IsAny <CancellationToken>()), Times.Once());
        }
Пример #8
0
        public void Given_SubstitutionDoesNotExist_When_GetTeamLeagueMatchSubstitution_Then_SubstitutionNotFoundExceptionIsThrown()
        {
            // Arrange
            var teams  = new TeamsBuilder().Build();
            var league = new TeamLeagueBuilder()
                         .WithCompetitors(teams)
                         .WithRounds()
                         .WithSubstitutions()
                         .Build();

            var leagues          = Enumerable.Repeat(league, 1);
            var matchGuid        = new Guid("00000000-0000-0000-0000-000000000000");
            var match            = league.GetMatch(matchGuid);
            var matchEntry       = match.MatchEntries.SingleOrDefault(me => me.Team.Name == "Tottenham Hotspur");
            var substitutionGuid = matchEntry.Substitutions.ToList()[0].Guid;

            var contextMock = MockDbContext(leagues.AsQueryable());
            var loggerMock  = new Mock <ILogger <GetTeamLeagueMatchSubstitutionQueryHandler> >();
            var handler     = new GetTeamLeagueMatchSubstitutionQueryHandler(
                contextMock.Object,
                Mapper.MapperConfig(),
                loggerMock.Object
                );

            // Act
            var request = new GetTeamLeagueMatchSubstitutionQuery
            {
                LeagueName       = "Premier League",
                MatchGuid        = matchGuid,
                TeamName         = "Tottenham Hotspur",
                SubstitutionGuid = new Guid("00000000-0000-0000-0000-000000000000")
            };
            Func <Task> func = async() => await handler.Handle(request, CancellationToken.None);

            // Assert
            func.Should().Throw <SubstitutionNotFoundException>();
        }
Пример #9
0
        public async void Given_TeamHasPlayer_When_GetPlayerForTeamCompetitor_Then_ReturnPlayer()
        {
            // Arrange
            var teams   = new TeamsBuilder().Build();
            var players = new PlayerBuilder().Build();
            var builder = new TeamLeagueBuilder()
                          .WithCompetitors(teams)
                          .WithPlayers(teams[0], players);

            var teamLeague = builder.Build();

            var contextMock = MockDbContext(
                new List <TeamLeague> {
                teamLeague
            }.AsQueryable(),
                teamLeague.Competitors.Select(c => c.Team).AsQueryable()
                );
            var handler = new GetPlayerForTeamCompetitorQueryHandler(
                contextMock.Object,
                Mapper.MapperConfig());

            //Act
            var command = new GetPlayerForTeamCompetitorQuery
            {
                LeagueName = "Premier League",
                TeamName   = "Tottenham Hotspur",
                PlayerName = "John Doe"
            };
            var result = await handler.Handle(command, CancellationToken.None);

            //Assert
            result.Should().BeOfType <CompetitorPlayerDto>();
            result.Player.Should().NotBeNull();
            result.Player.FirstName.Should().Be("John");
            result.Player.LastName.Should().Be("Doe");
            result.Number.Should().Be("1");
        }
        public async void Given_GoalExist_When_GetTeamLeagueMatchGoal_Then_ReturnGoal()
        {
            // Arrange
            var teams  = new TeamsBuilder().Build();
            var league = new TeamLeagueBuilder()
                         .WithCompetitors(teams)
                         .WithRounds()
                         .WithGoals()
                         .Build();

            var leagues    = Enumerable.Repeat(league, 1);
            var matchGuid  = new Guid("00000000-0000-0000-0000-000000000000");
            var match      = league.GetMatch(matchGuid);
            var matchEntry = match.MatchEntries.SingleOrDefault(me => me.Team.Name == "Tottenham Hotspur");
            var goalGuid   = matchEntry.Goals.ToList()[0].Guid;

            var contextMock = MockDbContext(leagues.AsQueryable());
            var loggerMock  = new Mock <ILogger <GetTeamLeagueMatchGoalQueryHandler> >();
            var handler     = new GetTeamLeagueMatchGoalQueryHandler(
                contextMock.Object,
                Mapper.MapperConfig(),
                loggerMock.Object
                );

            // Act
            var request = new GetTeamLeagueMatchGoalQuery
            {
                LeagueName = "Premier League",
                MatchGuid  = matchGuid,
                GoalGuid   = goalGuid
            };
            var result = await handler.Handle(request, CancellationToken.None);

            // Assert
            result.Should().NotBeNull();
        }