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

            var validator = new UpdateTeamLeagueMatchGoalCommandValidator();

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

            var validator = new UpdateTeamLeagueMatchGoalCommandValidator();

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

            var validator = new UpdateTeamLeagueMatchGoalCommandValidator();

            validator.ShouldHaveValidationErrorFor(x => x.GoalGuid, command);
        }
        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>();
        }
        public void When_CommandIsOk_Then_NoValidationErrors()
        {
            var command = new UpdateTeamLeagueMatchGoalCommand
            {
                LeagueName = "Premier League",
                MatchGuid  = Guid.NewGuid(),
                TeamName   = "Tottenham Hotspur",
                GoalGuid   = Guid.NewGuid(),
                Minute     = "1",
                PlayerName = "John Doe"
            };

            var validator = new UpdateTeamLeagueMatchGoalCommandValidator();

            validator.ShouldNotHaveValidationErrorFor(x => x.LeagueName, command);
            validator.ShouldNotHaveValidationErrorFor(x => x.MatchGuid, command);
            validator.ShouldNotHaveValidationErrorFor(x => x.TeamName, command);
            validator.ShouldNotHaveValidationErrorFor(x => x.GoalGuid, command);
            validator.ShouldNotHaveValidationErrorFor(x => x.Minute, command);
            validator.ShouldNotHaveValidationErrorFor(x => x.PlayerName, command);
        }
Example #6
0
        public async Task <Application.TeamLeagueMatches.Commands.UpdateTeamLeagueMatchGoal.GoalDto> UpdateTeamLeagueMatchGoal(UpdateTeamLeagueMatchGoalCommand command)
        {
            var response = await httpRequestFactory.Put(
                $"{teamLeagueApiUrl}/{command.LeagueName}/matches/{command.MatchGuid}/matchEntries/{command.TeamName}/goals/{command.GoalGuid}",
                new
            {
                command.Minute,
                command.PlayerName
            }
                );

            if (response.IsSuccessStatusCode)
            {
                return(response.ContentAsType <Application.TeamLeagueMatches.Commands.UpdateTeamLeagueMatchGoal.GoalDto>());
            }
            return(null);
        }
        public async Task <IActionResult> UpdateMatchGoal(string leagueName, Guid matchGuid, string teamName, Guid goalGuid, UpdateTeamLeagueMatchGoalCommand command)
        {
            var goal = await competitionApi.UpdateTeamLeagueMatchGoal(
                new UpdateTeamLeagueMatchGoalCommand
            {
                LeagueName = WebUtility.HtmlDecode(leagueName),
                MatchGuid  = matchGuid,
                TeamName   = teamName,
                GoalGuid   = goalGuid
            });

            return(PartialView("ViewGoalMatchEvent", goal));
        }