public void When_LeagueNameIsEmpty_Then_ValidationError()
        {
            var command = new UpdateTeamLeagueMatchSubstitutionCommand
            {
                LeagueName = ""
            };

            var validator = new UpdateTeamLeagueMatchSubstitutionCommandValidator();

            validator.ShouldHaveValidationErrorFor(x => x.LeagueName, command);
        }
        public void When_MatchGuidIsEmpty_Then_ValidationError()
        {
            var command = new UpdateTeamLeagueMatchSubstitutionCommand
            {
                LeagueName = "Premier League",
                MatchGuid  = Guid.Empty
            };

            var validator = new UpdateTeamLeagueMatchSubstitutionCommandValidator();

            validator.ShouldHaveValidationErrorFor(x => x.MatchGuid, command);
        }
        public void When_SubstitutionGuidIsEmpty_Then_ValidationError()
        {
            var command = new UpdateTeamLeagueMatchSubstitutionCommand
            {
                LeagueName       = "Premier League",
                MatchGuid        = Guid.NewGuid(),
                TeamName         = "Tottenham Hotspur",
                SubstitutionGuid = Guid.Empty
            };

            var validator = new UpdateTeamLeagueMatchSubstitutionCommandValidator();

            validator.ShouldHaveValidationErrorFor(x => x.SubstitutionGuid, command);
        }
Example #4
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 When_PlayerInIsEmpty_Then_ValidationError()
        {
            var command = new UpdateTeamLeagueMatchSubstitutionCommand
            {
                LeagueName       = "Premier League",
                MatchGuid        = Guid.NewGuid(),
                TeamName         = "Tottenham Hotspur",
                SubstitutionGuid = Guid.NewGuid(),
                Minute           = "1",
                PlayerOut        = "John Doe",
                PlayerIn         = ""
            };

            var validator = new UpdateTeamLeagueMatchSubstitutionCommandValidator();

            validator.ShouldHaveValidationErrorFor(x => x.PlayerIn, command);
        }
Example #6
0
        public void Given_PlayerDoesNotExist_When_UpdateTeamLeagueSubstitution_Then_PlayerNotFoundExceptionIsThrown()
        {
            //Arrange
            var teams  = new TeamsBuilder().Build();
            var league = new TeamLeagueBuilder()
                         .WithCompetitors(teams)
                         .WithRounds()
                         .WithSubstitutions()
                         .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 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         = "Tottenham Hotspur",
                SubstitutionGuid = substitutionGuid,
                Minute           = "1",
                PlayerOut        = "DoesNotExist"
            };

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

            //Assert

            func.Should().Throw <PlayerNotFoundException>();
        }
        public void When_CommandIsOk_Then_NoValidationErrors()
        {
            var command = new UpdateTeamLeagueMatchSubstitutionCommand
            {
                LeagueName       = "Premier League",
                MatchGuid        = Guid.NewGuid(),
                TeamName         = "Tottenham Hotspur",
                SubstitutionGuid = Guid.NewGuid(),
                Minute           = "1",
                PlayerOut        = "John Doe",
                PlayerIn         = "Jane Doe"
            };

            var validator = new UpdateTeamLeagueMatchSubstitutionCommandValidator();

            validator.ShouldNotHaveValidationErrorFor(x => x.LeagueName, command);
            validator.ShouldNotHaveValidationErrorFor(x => x.MatchGuid, command);
            validator.ShouldNotHaveValidationErrorFor(x => x.TeamName, command);
            validator.ShouldNotHaveValidationErrorFor(x => x.SubstitutionGuid, command);
            validator.ShouldNotHaveValidationErrorFor(x => x.Minute, command);
            validator.ShouldNotHaveValidationErrorFor(x => x.PlayerOut, command);
            validator.ShouldNotHaveValidationErrorFor(x => x.PlayerIn, command);
        }