private Fixture RetrieveSnapshot()
        {
            _logger.Debug($"Getting snapshot for {_resource}");

            string snapshotJson = null;

            try
            {
                snapshotJson = _resource.GetSnapshot();
            }
            catch (Exception ex)
            {
                var apiError = new ApiException($"GetSnapshot for {_resource} failed", ex);
                UpdateStatsError(apiError);
                throw apiError;
            }

            if (string.IsNullOrEmpty(snapshotJson))
            {
                throw new Exception($"Received empty snapshot for {_resource}");
            }

            var snapshot = FixtureHelper.GetFromJson(snapshotJson);

            if (snapshot == null || snapshot != null && snapshot.Id.IsNullOrWhiteSpace())
            {
                throw new Exception($"Received a snapshot that resulted in an empty snapshot object {_resource}"
                                    + Environment.NewLine +
                                    $"Platform raw data=\"{snapshotJson}\"");
            }

            if (snapshot.Sequence < _currentSequence)
            {
                throw new Exception(
                          $"Received snapshot {snapshot} with sequence lower than currentSequence={_currentSequence}");
            }

            _fixtureStartTime = snapshot.StartTime;

            return(snapshot);
        }
Exemplo n.º 2
0
        protected void SetupCommonMockObjects(
            string sport,
            byte[] fixtureData,
            dynamic storedData,
            out Fixture snapshot,
            out Mock <IResourceFacade> resourceFacadeMock,
            Action <Mock <IResourceFacade>, string> resourceGetSnapshotCallsSequence = null)
        {
            resourceFacadeMock = new Mock <IResourceFacade>();

            FootabllSportMock.SetupGet(o => o.Name).Returns("Football");

            var snapshotJson = System.Text.Encoding.UTF8.GetString(fixtureData);

            snapshot = FixtureHelper.GetFromJson(snapshotJson);
            var snapshotVar = snapshot;

            resourceFacadeMock.Setup(o => o.Id).Returns(snapshot.Id);
            resourceFacadeMock.Setup(o => o.Sport).Returns(sport);
            resourceFacadeMock.Setup(o => o.MatchStatus).Returns((MatchStatus)Convert.ToInt32(snapshot.MatchStatus));
            resourceFacadeMock.Setup(o => o.Content).Returns(new Summary
            {
                Id          = snapshot.Id,
                Sequence    = snapshot.Sequence,
                MatchStatus = Convert.ToInt32(snapshot.MatchStatus),
                StartTime   = snapshot.StartTime?.ToString("yyyy-MM-ddTHH:mm:ssZ")
            });
            if (resourceGetSnapshotCallsSequence == null)
            {
                resourceFacadeMock.Setup(o => o.GetSnapshot()).Returns(snapshotJson);
            }
            else
            {
                resourceGetSnapshotCallsSequence(resourceFacadeMock, snapshotJson);
            }
            resourceFacadeMock.Setup(r => r.StartStreaming()).Raises(r => r.StreamConnected   += null, EventArgs.Empty);
            resourceFacadeMock.Setup(r => r.StopStreaming()).Raises(r => r.StreamDisconnected += null, EventArgs.Empty);
            StateManagerMock.Setup(o => o.CreateNewMarketRuleManager(It.Is <string>(id => id.Equals(snapshotVar.Id))))
            .Returns(MarketRulesManagerMock.Object);
            if (snapshot.IsMatchOver)
            {
                resourceFacadeMock.SetupGet(o => o.IsMatchOver).Returns(true);
            }

            var storedFixtureState = new FixtureState {
                Id = snapshot.Id, Sport = sport
            };

            if (storedData != null)
            {
                storedFixtureState.Epoch       = (int)storedData.Epoch;
                storedFixtureState.Sequence    = (int)storedData.Sequence;
                storedFixtureState.MatchStatus = (MatchStatus)storedData.MatchStatus;
                var dic = new Dictionary <string, FixtureState> {
                    { storedFixtureState.Id, storedFixtureState }
                };
                StoreProviderMock.Setup(o => o.Read(It.IsAny <string>()))
                .Returns(JsonConvert.SerializeObject(dic, Formatting.Indented));
            }

            ActorOfAsTestActorRef <FixtureStateActor>(
                Props.Create(() =>
                             new FixtureStateActor(
                                 SettingsMock.Object,
                                 StoreProviderMock.Object)),
                FixtureStateActor.ActorName);
        }