示例#1
0
    public void GetChangedPlayers_WhenNoPlayers_ReturnsNoChanges()
    {
        var before = new List <Player> {
        };
        var after  = new List <Player> {
        };

        var priceChanges = PlayerChangesEventsExtractor.GetPriceChanges(after, before, new List <Team>());

        Assert.Empty(priceChanges);
    }
示例#2
0
    public void GetChangedPlayers_WhenSamePlayersWithPriceChange_ReturnsNoChanges()
    {
        var before = new List <Player> {
            TestBuilder.Player().WithCostChangeEvent(1)
        };
        var after = new List <Player> {
            TestBuilder.Player().WithCostChangeEvent(1)
        };

        var priceChanges = PlayerChangesEventsExtractor.GetPriceChanges(after, before, new List <Team>());

        Assert.Empty(priceChanges);
    }
示例#3
0
        public void GetChangedPlayers_WhenSamePlayersWithChangeInPriceChange_ReturnsChanges()
        {
            var before = new List <Player> {
                TestBuilder.Player().WithCostChangeEvent(0)
            };
            var after = new List <Player> {
                TestBuilder.Player().WithCostChangeEvent(1)
            };

            var priceChanges = PlayerChangesEventsExtractor.GetPriceChanges(after, before, new List <Team>());

            Assert.Single(priceChanges);
            Assert.Equal(TestBuilder.Player().SecondName, priceChanges.First().ToPlayer.SecondName);
        }
示例#4
0
    public void GetChangedPlayers_WhenSamePlayersWithChangeInPriceRemoved_ReturnsNoChanges()
    {
        var before = new List <Player> {
            TestBuilder.Player().WithCostChangeEvent(1)
        };
        var after = new List <Player> {
            TestBuilder.Player().WithCostChangeEvent(0)
        };

        var priceChanges = PlayerChangesEventsExtractor.GetPriceChanges(after, before, new List <Team> {
            TestBuilder.HomeTeam(), TestBuilder.AwayTeam()
        });

        Assert.Single(priceChanges);
    }
示例#5
0
    public void GetChangedPlayers_OneNewPlayerWithCostChange_ReturnsNewPlayer()
    {
        var before = new List <Player> {
            TestBuilder.Player().WithCostChangeEvent(1)
        };
        var after = new List <Player>
        {
            TestBuilder.Player().WithCostChangeEvent(1),
            TestBuilder.OtherPlayer().WithCostChangeEvent(1)
        };

        var priceChanges = PlayerChangesEventsExtractor.GetPriceChanges(after, before, new List <Team> {
            TestBuilder.HomeTeam(), TestBuilder.AwayTeam()
        });

        Assert.Empty(priceChanges);
    }
示例#6
0
文件: State.cs 项目: fplbot/fplbot
    public async Task Refresh(int currentGameweek)
    {
        using var scope = _logger.AddContext("StateRefresh");
        _logger.LogInformation($"Refreshing {currentGameweek}");
        var latest = await _fixtureClient.GetFixturesByGameweek(currentGameweek);

        var fixtureEvents    = LiveEventsExtractor.GetUpdatedFixtureEvents(latest, _currentGameweekFixtures, _players, _teams);
        var finishedFixtures = LiveEventsExtractor.GetProvisionalFinishedFixtures(latest, _currentGameweekFixtures, _teams, _players);

        _currentGameweekFixtures = latest;

        var globalSettings = await _settingsClient.GetGlobalSettings();

        var after         = globalSettings.Players;
        var priceChanges  = PlayerChangesEventsExtractor.GetPriceChanges(after, _players, _teams);
        var injuryUpdates = PlayerChangesEventsExtractor.GetInjuryUpdates(after, _players, _teams);
        var newPlayers    = PlayerChangesEventsExtractor.GetNewPlayers(after, _players, _teams);

        _players = after;

        if (fixtureEvents.Any())
        {
            await _session.Publish(new FixtureEventsOccured(fixtureEvents.ToList()));
        }

        if (priceChanges.Any())
        {
            await _session.Publish(new PlayersPriceChanged(priceChanges.ToList()));
        }

        if (injuryUpdates.Any())
        {
            await _session.Publish(new InjuryUpdateOccured(injuryUpdates));
        }

        foreach (var fixture in finishedFixtures)
        {
            await _session.Publish(new FixtureFinished(fixture));
        }

        if (newPlayers.Any())
        {
            await _session.Publish(new NewPlayersRegistered(newPlayers.ToList()));
        }
    }
示例#7
0
    public void GetChangedPlayers_WhenSamePlayersDuplicateWithChangeInPriceChange_ReturnsSingleChanges()
    {
        var before = new List <Player> {
            TestBuilder.Player().WithCostChangeEvent(0)
        };
        var after = new List <Player> {
            TestBuilder.Player().WithCostChangeEvent(1), TestBuilder.Player().WithCostChangeEvent(1)
        };

        var priceChanges = PlayerChangesEventsExtractor.GetPriceChanges(after, before, new List <Team> {
            TestBuilder.HomeTeam(), TestBuilder.AwayTeam()
        });

        Assert.Single(priceChanges);
        Assert.Equal(TestBuilder.Player().WebName, priceChanges.First().WebName);

        var before2 = new List <Player> {
            TestBuilder.Player().WithCostChangeEvent(0), TestBuilder.Player().WithCostChangeEvent(0)
        };
        var after2 = new List <Player> {
            TestBuilder.Player().WithCostChangeEvent(1), TestBuilder.Player().WithCostChangeEvent(1)
        };

        var priceChanges2 = PlayerChangesEventsExtractor.GetPriceChanges(after2, before2, new List <Team> {
            TestBuilder.HomeTeam(), TestBuilder.AwayTeam()
        });

        Assert.Single(priceChanges2);
        Assert.Equal(TestBuilder.Player().WebName, priceChanges2.First().WebName);

        var before3 = new List <Player> {
            TestBuilder.Player().WithCostChangeEvent(0), TestBuilder.Player().WithCostChangeEvent(0)
        };
        var after3 = new List <Player> {
            TestBuilder.Player().WithCostChangeEvent(1)
        };

        var priceChanges3 = PlayerChangesEventsExtractor.GetPriceChanges(after3, before3, new List <Team> {
            TestBuilder.HomeTeam(), TestBuilder.AwayTeam()
        });

        Assert.Single(priceChanges3);
        Assert.Equal(TestBuilder.Player().WebName, priceChanges3.First().WebName);
    }
示例#8
0
文件: State.cs 项目: ehamberg/fplbot
        public async Task Refresh(int currentGameweek)
        {
            var latest = await _fixtureClient.GetFixturesByGameweek(currentGameweek);

            var fixtureEvents    = LiveEventsExtractor.GetUpdatedFixtureEvents(latest, _currentGameweekFixtures);
            var finishedFixtures = LiveEventsExtractor.GetProvisionalFinishedFixtures(latest, _currentGameweekFixtures, _teams, _players);

            _currentGameweekFixtures = latest;

            var globalSettings = await _settingsClient.GetGlobalSettings();

            var after         = globalSettings.Players;
            var priceChanges  = PlayerChangesEventsExtractor.GetPriceChanges(after, _players, _teams);
            var injuryUpdates = PlayerChangesEventsExtractor.GetInjuryUpdates(after, _players, _teams);

            _players = after;

            if (fixtureEvents.Any())
            {
                var fixtureUpdates = new FixtureUpdates
                {
                    CurrentGameweek = _currentGameweek.Value,
                    Teams           = _teams,
                    Players         = _players,
                    Events          = fixtureEvents
                };
                await _mediator.Publish(new FixtureEventsOccured(fixtureUpdates));
            }

            if (priceChanges.Any())
            {
                await _mediator.Publish(new PriceChangeOccured(priceChanges));
            }

            if (injuryUpdates.Any())
            {
                await _mediator.Publish(new InjuryUpdateOccured(injuryUpdates));
            }

            if (finishedFixtures.Any())
            {
                await _mediator.Publish(new FixturesFinished(finishedFixtures.ToList()));
            }
        }