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()); }