예제 #1
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>();
        }
예제 #3
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>();
        }
        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();
        }