예제 #1
0
        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>();
        }
예제 #2
0
        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");
        }