public void Given_TeamLeagueAlreadyExist_When_CreateTeamLeague_Then_Exception() { // Arrange var teamSports = new List <TeamSports>(); var countries = new List <Country>(); var leagues = new List <TeamLeague> { new TeamLeague { Name = "Premier League" } }; var teams = new TeamsBuilder().Build(); var contextMock = MockDbContext( teamSports.AsQueryable(), countries.AsQueryable(), leagues.AsQueryable(), teams.AsQueryable()); var handler = new CreateTeamLeagueCommandHandler(contextMock.Object, Mapper.CreateMapper()); //Act var request = new CreateTeamLeagueCommand { Name = "Premier League", SelectedTeams = teams.Select(t => t.Name).ToList() }; Func <Task> func = async() => await handler.Handle(request, CancellationToken.None); //Assert func.Should().Throw <CompetitionAlreadyExistsException>(); }
public async void Given_TeamLeagueDoesNotExist_When_CreateTeamLeague_Then_TeamLeagueIsCreated() { // Arrange var teamSports = new List <TeamSports> { new TeamSports { Name = "Soccer", Options = new TeamSportsOptions { AmountOfPlayers = 11 } } }; var countries = new List <Country>(); var leagues = new List <TeamLeague>(); var teams = new TeamsBuilder().Build(); var contextMock = MockDbContext( teamSports.AsQueryable(), countries.AsQueryable(), leagues.AsQueryable(), teams.AsQueryable()); var handler = new CreateTeamLeagueCommandHandler(contextMock.Object, Mapper.CreateMapper()); //Act var request = new CreateTeamLeagueCommand { Sports = "Soccer", Name = "Premier League", SelectedTeams = teams.Select(t => t.Name).ToList() }; var result = await handler.Handle(request, CancellationToken.None); //Assert result.Should().BeOfType <TeamLeagueDto>(); result.Rounds.Count().Should().Be((teams.Count - 1) * 2); result.Rounds.ToList().ForEach(r => { r.Matches.Count().Should().Be(teams.Count / 2); r.Matches.ToList().ForEach(m => { m.MatchEntries.Count().Should().Be(2); m.MatchEntries.ForEach(me => me.Lineup.Count().Should().Be(teamSports[0].Options.AmountOfPlayers)); }); }); contextMock.Verify(mock => mock.SaveChangesAsync(It.IsAny <CancellationToken>()), Times.Once()); }