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>();
        }
コード例 #5
0
        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>();
        }
コード例 #6
0
        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());
        }