Exemplo n.º 1
0
        public async void Given_MatchDoesExist_When_UpdateTeamLeagueMatch_Then_MatchIsUpdated()
        {
            // Arrange
            var guid        = Guid.NewGuid();
            var teamLeagues = CreateTeamLeagues(guid, true);
            var teams       = CreateTeams();

            var contextMock = MockDbContext(
                teamLeagues.AsQueryable(),
                teams.AsQueryable());
            var handler = new UpdateTeamLeagueMatchCommandHandler(
                contextMock.Object,
                Mapper.CreateMapper());

            //Act
            var request = new UpdateTeamLeagueMatchCommand
            {
                LeagueName = "TeamLeague",
                Guid       = guid,
                HomeTeam   = "Team A",
                AwayTeam   = "Team B"
            };
            var result = await handler.Handle(request, CancellationToken.None);

            //Assert
            result.Should().BeOfType(typeof(TeamLeagueMatches.Commands.UpdateTeamLeagueMatch.TeamMatchDto));
            contextMock.Verify(mock => mock.SaveChangesAsync(It.IsAny <CancellationToken>()), Times.Once());
        }
Exemplo n.º 2
0
        public void Given_AwayTeamDoesNotExist_When_UpdateTeamLeagueMatch_Then_ThrowTeamNotFoundException()
        {
            //Arrange
            var guid        = Guid.NewGuid();
            var teamLeagues = CreateTeamLeagues(guid, true);
            var teams       = CreateTeams();

            teams.Remove(teams.Single(t => t.Name == "Team B"));

            var contextMock = MockDbContext(
                teamLeagues.AsQueryable(),
                teams.AsQueryable());
            var handler = new UpdateTeamLeagueMatchCommandHandler(contextMock.Object, Mapper.CreateMapper());

            //Act
            var request = new UpdateTeamLeagueMatchCommand
            {
                LeagueName = "TeamLeague",
                Guid       = guid,
                HomeTeam   = "Team A",
                AwayTeam   = "Team B"
            };
            Func <Task> func = async() => await handler.Handle(request, CancellationToken.None);

            //Assert
            func.Should().Throw <TeamNotFoundException>();
            contextMock.Verify(mock => mock.SaveChangesAsync(It.IsAny <CancellationToken>()), Times.Never());
        }