public async void Given_TeamHasPlayers_When_GetPlayersForTeamCompetitor_Then_Success() { // 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 GetPlayersForTeamCompetitorQueryHandler( contextMock.Object, Mapper.MapperConfig() ); //Act var command = new GetPlayersForTeamCompetitorQuery { LeagueName = "Premier League", TeamName = "Tottenham Hotspur" }; var result = await handler.Handle(command, CancellationToken.None); //Assert result.Should().BeOfType <List <CompetitorPlayerDto> >(); result.ToList().Count.Should().Be(2); }
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 void Given_LeagueDoesNotExist_When_GetPlayerForTeamCompetitor_Then_ExceptionIsThrown() { // 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 = "DoesNotExist", TeamName = "Tottenham Hotspur", PlayerName = "John Doe" }; Func <Task> func = async() => await handler.Handle(command, CancellationToken.None); //Assert func.Should().Throw <TeamLeagueNotFoundException>(); }
public void Given_TeamLeagueDoesNotExist_When_AddPlayerToTeamCompetitor_Then_Exception() { // Arrange var builder = new TeamLeagueBuilder() .WithCompetitors(new TeamsBuilder().Build()); var teamLeague = builder.Build(); var players = new Domain.Player.Player[] { new Domain.Player.Player { FirstName = "John", LastName = "Doe" } }; var contextMock = MockDbContext( new List <TeamLeague> { teamLeague }.AsQueryable(), players.AsQueryable()); var handler = new AddPlayerToTeamCompetitorCommandHandler(contextMock.Object); //Act var command = new AddPlayerToTeamCompetitorCommand { LeagueName = "DoesNotExist", TeamName = "Tottenham Hotspur", PlayerNumber = "1", PlayerName = "John Doe" }; Func <Task> func = async() => await handler.Handle(command, CancellationToken.None); //Assert func.Should().Throw <TeamLeagueNotFoundException>(); }
public async void Given_AllConditionsPass_When_AddPlayerToTeamCompetitor_Then_Success() { // Arrange var builder = new TeamLeagueBuilder() .WithCompetitors(new TeamsBuilder().Build()); var teamLeague = builder.Build(); var players = new Domain.Player.Player[] { new Domain.Player.Player { FirstName = "John", LastName = "Doe" } }; var contextMock = MockDbContext( new List <TeamLeague> { teamLeague }.AsQueryable(), players.AsQueryable()); var handler = new AddPlayerToTeamCompetitorCommandHandler(contextMock.Object); //Act var command = new AddPlayerToTeamCompetitorCommand { LeagueName = "Premier League", TeamName = "Tottenham Hotspur", PlayerNumber = "1", PlayerName = "John Doe" }; var result = await handler.Handle(command, CancellationToken.None); //Assert result.Should().Be(Unit.Value); contextMock.Verify(mock => mock.SaveChangesAsync(It.IsAny <CancellationToken>()), Times.Once()); }
public async void Given_AllConditionsPass_When_AddTeamLeagueMatchSubstitution_Then_Success() { //Arrange var builder = new TeamLeagueBuilder() .WithCompetitors(new TeamsBuilder().Build()) .WithRounds(); var teamLeague = builder.Build(); var players = new Domain.Player.Player[] { new Domain.Player.Player { FirstName = "John", LastName = "Doe" }, new Domain.Player.Player { FirstName = "Jane", LastName = "Doe" } }; var mockContext = MockDbContext( new List <TeamLeague> { teamLeague }.AsQueryable(), teamLeague.Competitors.Select(c => c.Team).AsQueryable(), players.AsQueryable()); var mockLogger = new Mock <ILogger <AddTeamLeagueMatchSubstitutionCommandHandler> >(); var handler = new AddTeamLeagueMatchSubstitutionCommandHandler( mockContext.Object, Mapper.MapperConfig(), mockLogger.Object ); //Act var command = new AddTeamLeagueMatchSubstitutionCommand { LeagueName = "Premier League", MatchGuid = new Guid("00000000-0000-0000-0000-000000000000"), TeamName = "Tottenham Hotspur", Minute = "1", PlayerOut = "John Doe", PlayerIn = "Jane Doe" }; var result = await handler.Handle(command, CancellationToken.None); //Assert result.Should().BeAssignableTo <SubstitutionDto>(); result.PlayerOut.Should().Be("John Doe"); result.PlayerIn.Should().Be("Jane Doe"); mockContext.Verify(mock => mock.SaveChangesAsync(It.IsAny <CancellationToken>()), Times.Once()); }
public void Given_LeagueDoesNotExist_When_AddTeamLeagueMatchSubstitution_Then_TeamLeagueNotFoundExceptionIsThrown() { //Arrange var builder = new TeamLeagueBuilder() .WithCompetitors(new TeamsBuilder().Build()) .WithRounds(); var teamLeague = builder.Build(); var players = new Domain.Player.Player[] { new Domain.Player.Player { FirstName = "John", LastName = "Doe" }, new Domain.Player.Player { FirstName = "Jane", LastName = "Doe" } }; var mockContext = MockDbContext( new List <TeamLeague> { teamLeague }.AsQueryable(), teamLeague.Competitors.Select(c => c.Team).AsQueryable(), players.AsQueryable()); var mockLogger = new Mock <ILogger <AddTeamLeagueMatchSubstitutionCommandHandler> >(); var handler = new AddTeamLeagueMatchSubstitutionCommandHandler( mockContext.Object, Mapper.MapperConfig(), mockLogger.Object ); //Act var command = new AddTeamLeagueMatchSubstitutionCommand { LeagueName = "DoesNotExist", MatchGuid = new Guid("00000000-0000-0000-0000-000000000000"), TeamName = "Tottenham Hotspur", Minute = "1", PlayerOut = "John Doe", PlayerIn = "Jane Doe" }; Func <Task> func = async() => await handler.Handle(command, CancellationToken.None); //Assert func.Should().Throw <TeamLeagueNotFoundException>(); }
public void Given_MatchEntryDoesNotExist_When_AddPlayerToLineup_Then_MatchEntryNotFoundException() { // Arrange var builder = new TeamLeagueBuilder() .WithCompetitors(new TeamsBuilder().Build()) .WithRounds(); var teamLeague = builder.Build(); var players = new Domain.Player.Player[] { new Domain.Player.Player { FirstName = "John", LastName = "Doe" } }; var contextMock = MockDbContext( new List <TeamLeague> { teamLeague }.AsQueryable(), teamLeague.Competitors.Select(c => c.Team).AsQueryable(), players.AsQueryable()); var contextMediator = new Mock <IMediator>(); var contextLogger = new Mock <ILogger <AddPlayerToLineupCommandHandler> >(); var handler = new AddPlayerToLineupCommandHandler( contextMock.Object, contextMediator.Object, Mapper.MapperConfig(), contextLogger.Object ); //Act var command = new AddPlayerToLineupCommand { LeagueName = "Premier League", MatchGuid = new Guid("00000000-0000-0000-0000-000000000000"), TeamName = "DoesNotExist", Number = "1", Player = new TeamLeagueMatches.Commands.AddPlayerToLineup.PlayerDto { FirstName = "John", LastName = "Doe" } }; Func <Task> func = async() => await handler.Handle(command, CancellationToken.None); //Assert func.Should().Throw <MatchEntryNotFoundException>(); }
public async void Given_AllConditionsPass_When_AddPlayerToLineup_Then_Success() { // Arrange var builder = new TeamLeagueBuilder() .WithCompetitors(new TeamsBuilder().Build()) .WithRounds(); var teamLeague = builder.Build(); var players = new Domain.Player.Player[] { new Domain.Player.Player { FirstName = "John", LastName = "Doe" } }; var contextMock = MockDbContext( new List <TeamLeague> { teamLeague }.AsQueryable(), teamLeague.Competitors.Select(c => c.Team).AsQueryable(), players.AsQueryable()); var contextMediator = new Mock <IMediator>(); var contextLogger = new Mock <ILogger <AddPlayerToLineupCommandHandler> >(); var handler = new AddPlayerToLineupCommandHandler( contextMock.Object, contextMediator.Object, Mapper.MapperConfig(), contextLogger.Object ); //Act var command = new AddPlayerToLineupCommand { LeagueName = "Premier League", MatchGuid = new Guid("00000000-0000-0000-0000-000000000000"), TeamName = "Tottenham Hotspur", Number = "1", Player = new TeamLeagueMatches.Commands.AddPlayerToLineup.PlayerDto { FirstName = "John", LastName = "Doe" } }; var result = await handler.Handle(command, CancellationToken.None); //Assert result.Should().Be(Unit.Value); contextMock.Verify(mock => mock.SaveChangesAsync(It.IsAny <CancellationToken>()), Times.Once()); }
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"); }
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"); }