public void Given_LeagueDoesNotExist_When_UpdateTeamLeagueMatchLineupEntry_Then_LineupEntryNotFoundExceptionIsThrown() { // Arrange var builder = new TeamLeagueBuilder() .WithCompetitors(new TeamsBuilder().Build()) .WithRounds(); var teamLeague = builder.Build(); var players = new PlayerBuilder().Build(); var contextMock = MockDbContext( Enumerable.Repeat(teamLeague, 1).AsQueryable(), players.AsQueryable() ); var handler = new UpdateTeamLeagueMatchLineupEntryCommandHandler( contextMock.Object, Mapper.MapperConfig() ); //Act var request = new UpdateTeamLeagueMatchLineupEntryCommand { LeagueName = "DoesNotExist", MatchGuid = new Guid("00000000-0000-0000-0000-000000000000"), TeamName = "Tottenham Hotspur", LineupEntryGuid = new Guid("00000000-0000-0000-0000-000000000000"), PlayerName = "John Doe", PlayerNumber = "1" }; Func <Task> func = async() => await handler.Handle(request, CancellationToken.None); //Assert func.Should().Throw <LineupEntryNotFoundException>(); }
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>(); }
public async void Given_EntryDoesExist_When_UpdateTeamLeagueMatchLineupEntry_Then_EntryIsUpdated() { // Arrange var builder = new TeamLeagueBuilder() .WithCompetitors(new TeamsBuilder().Build()) .WithRounds(); var teamLeague = builder.Build(); var players = new PlayerBuilder().Build(); var contextMock = MockDbContext( Enumerable.Repeat(teamLeague, 1).AsQueryable(), players.AsQueryable() ); var handler = new UpdateTeamLeagueMatchLineupEntryCommandHandler( contextMock.Object, Mapper.MapperConfig() ); //Act var request = new UpdateTeamLeagueMatchLineupEntryCommand { LeagueName = "Premier League", MatchGuid = new Guid("00000000-0000-0000-0000-000000000000"), TeamName = "Tottenham Hotspur", LineupEntryGuid = new Guid("00000000-0000-0000-0000-000000000000"), PlayerName = "John Doe", PlayerNumber = "1" }; var result = await handler.Handle(request, CancellationToken.None); //Assert result.Should().BeOfType <LineupEntryDto>(); contextMock.Verify(mock => mock.SaveChangesAsync(It.IsAny <CancellationToken>()), Times.Once()); result.Player.FirstName.Should().Be("John"); result.Player.LastName.Should().Be("Doe"); result.PlayerNumber.Should().Be("1"); }