Ejemplo n.º 1
0
        private void UpdateSupervisorStateMsgHandler(UpdateSupervisorStateMsg msg)
        {
            _logger.Info($"Updating supervisor state for {msg.FixtureId} IsSnapshot={msg.IsSnapshot}");

            var fixtureOverview = GetFixtureOverview(msg.FixtureId);

            fixtureOverview.FeedUpdate = new FeedUpdateOverview()
            {
                Epoch                 = msg.Epoch,
                IsSnapshot            = msg.IsSnapshot,
                Sequence              = msg.CurrentSequence,
                LastEpochChangeReason = msg.LastEpochChangeReason,
                IsProcessed           = true,
                Issued                = DateTime.Now
            };
            fixtureOverview.TimeStamp = DateTime.UtcNow;
            fixtureOverview.Sport     = msg.Sport;
            fixtureOverview.Name      = msg.Name ?? fixtureOverview.Name;
            fixtureOverview.ListenerOverview.Sequence              = msg.CurrentSequence;
            fixtureOverview.ListenerOverview.Epoch                 = msg.Epoch;
            fixtureOverview.ListenerOverview.StartTime             = msg.StartTime ?? fixtureOverview.ListenerOverview.StartTime;
            fixtureOverview.ListenerOverview.LastEpochChangeReason = msg.LastEpochChangeReason ?? fixtureOverview.ListenerOverview.LastEpochChangeReason;
            fixtureOverview.ListenerOverview.MatchStatus           = msg.MatchStatus ?? fixtureOverview.ListenerOverview.MatchStatus;
            fixtureOverview.ListenerOverview.IsDeleted             = msg.IsDeleted;
            fixtureOverview.ListenerOverview.IsStreaming           = msg.IsStreaming;
            fixtureOverview.ListenerOverview.IsSuspended           = msg.IsSuspended;
            fixtureOverview.ListenerOverview.IsOver                = msg.IsOver;
            fixtureOverview.ListenerOverview.IsErrored             = msg.IsErrored;

            if (msg.IsSnapshot)
            {
                fixtureOverview.CompetitionId   = msg.CompetitionId;
                fixtureOverview.CompetitionName = msg.CompetitionName;
            }

            ServiceModel.FixtureDetails details = fixtureOverview.ToServiceModel();
            details.Id        = msg.FixtureId;
            details.IsDeleted = msg.IsDeleted;
            details.IsOver    = msg.IsOver;

            _streamingService.OnFixtureUpdate(details);

            if (msg.IsErrored.HasValue && msg.IsErrored.Value && msg.Exception != null)
            {
                var error = new ServiceModel.ProcessingEntryError
                {
                    Timestamp          = DateTime.UtcNow,
                    Message            = msg.Exception.Message,
                    FixtureId          = msg.FixtureId,
                    FixtureDescription = fixtureOverview.Name,
                    Sequence           = msg.CurrentSequence
                };

                _streamingService.OnError(error);
            }

            UpdateSportDetails(msg.Sport);
            SaveState();
        }
        public void UpdateSupervisorStateIsProcessed()
        {
            //
            //Arrange
            //
            var updateSupervisorStateMsg = new UpdateSupervisorStateMsg
            {
                FixtureId             = "fixture1Id",
                Sport                 = "sport1",
                Epoch                 = 1,
                CurrentSequence       = 1,
                StartTime             = DateTime.UtcNow.AddDays(-1),
                IsSnapshot            = true,
                CompetitionId         = "competition1Id",
                CompetitionName       = "competition1Name",
                Name                  = "name1",
                MatchStatus           = MatchStatus.Prematch,
                LastEpochChangeReason = null,
                IsStreaming           = true,
                IsErrored             = false,
                IsSuspended           = false,
                Exception             = null
            };
            var supervisorActorRef =
                ActorOfAsTestActorRef <SupervisorActor>(
                    Props.Create(() =>
                                 new SupervisorActor(
                                     SupervisorStreamingServiceMock.Object,
                                     ObjectProviderMock.Object)),
                    SupervisorActor.ActorName);
            var supervisorActor = supervisorActorRef.UnderlyingActor;

            //
            //Act
            //
            supervisorActorRef.Tell(updateSupervisorStateMsg);

            //
            //Assert
            //
            AwaitAssert(() =>
            {
                Assert.AreEqual(1, supervisorActor.FixturesOverview.Count);
                Assert.AreEqual(1, supervisorActor.SportsOverview.Count);
                Assert.IsTrue(supervisorActor.FixturesOverview.ContainsKey(updateSupervisorStateMsg.FixtureId));
                Assert.IsTrue(supervisorActor.SportsOverview.ContainsKey(updateSupervisorStateMsg.Sport));
                var fixtureOverview = supervisorActor.FixturesOverview[updateSupervisorStateMsg.FixtureId];
                var sportOverview   = supervisorActor.SportsOverview[updateSupervisorStateMsg.Sport];
                Assert.IsNotNull(fixtureOverview.ListenerOverview);
                Assert.AreEqual(updateSupervisorStateMsg.FixtureId, fixtureOverview.Id);
                Assert.AreEqual(updateSupervisorStateMsg.Sport, fixtureOverview.Sport);
                Assert.AreEqual(updateSupervisorStateMsg.Epoch, fixtureOverview.ListenerOverview.Epoch);
                Assert.AreEqual(updateSupervisorStateMsg.CurrentSequence, fixtureOverview.ListenerOverview.Sequence);
                Assert.AreEqual(updateSupervisorStateMsg.StartTime, fixtureOverview.ListenerOverview.StartTime);
                Assert.AreEqual(updateSupervisorStateMsg.CompetitionId, fixtureOverview.CompetitionId);
                Assert.AreEqual(updateSupervisorStateMsg.CompetitionName, fixtureOverview.CompetitionName);
                Assert.AreEqual(updateSupervisorStateMsg.Name, fixtureOverview.Name);
                Assert.AreEqual(updateSupervisorStateMsg.MatchStatus, fixtureOverview.ListenerOverview.MatchStatus);
                Assert.AreEqual(updateSupervisorStateMsg.LastEpochChangeReason, fixtureOverview.ListenerOverview.LastEpochChangeReason);
                Assert.AreEqual(updateSupervisorStateMsg.IsStreaming, fixtureOverview.ListenerOverview.IsStreaming);
                Assert.AreEqual(updateSupervisorStateMsg.IsErrored, fixtureOverview.ListenerOverview.IsErrored);
                Assert.AreEqual(updateSupervisorStateMsg.IsSuspended, fixtureOverview.ListenerOverview.IsSuspended);
                Assert.AreEqual(updateSupervisorStateMsg.IsOver, fixtureOverview.ListenerOverview.IsOver);
                Assert.IsNull(fixtureOverview.LastError);
                Assert.AreEqual(updateSupervisorStateMsg.Sport, sportOverview.Name);
                Assert.AreEqual(1, sportOverview.Total);
                Assert.AreEqual(0, sportOverview.InPlay);
                Assert.AreEqual(0, sportOverview.InSetup);
                Assert.AreEqual(1, sportOverview.InPreMatch);
                Assert.AreEqual(0, sportOverview.InErrorState);

                SupervisorStreamingServiceMock.Verify(a =>
                                                      a.OnFixtureUpdate(It.IsAny <ServiceModelInterface.IFixtureDetails>()),
                                                      Times.Once);
                SupervisorStreamingServiceMock.Verify(a =>
                                                      a.OnFixtureUpdate(It.Is <ServiceModelInterface.IFixtureDetails>(f =>
                                                                                                                      f.Id.Equals(fixtureOverview.Id) &&
                                                                                                                      f.IsDeleted.Equals(fixtureOverview.ListenerOverview.IsDeleted) &&
                                                                                                                      f.IsOver.Equals(fixtureOverview.ListenerOverview.IsOver) &&
                                                                                                                      f.IsStreaming.Equals(fixtureOverview.ListenerOverview.IsStreaming
                                                                                                                                           .GetValueOrDefault()) &&
                                                                                                                      f.IsInErrorState.Equals(fixtureOverview.ListenerOverview.IsErrored
                                                                                                                                              .GetValueOrDefault()) &&
                                                                                                                      f.StartTime.Equals(fixtureOverview.ListenerOverview.StartTime.GetValueOrDefault()) &&
                                                                                                                      f.Competition.Equals(fixtureOverview.CompetitionName) &&
                                                                                                                      f.CompetitionId.Equals(fixtureOverview.CompetitionId) &&
                                                                                                                      f.Description.Equals(fixtureOverview.Name) &&
                                                                                                                      f.State.Equals(ServiceModelInterface.FixtureState.PreMatch))),
                                                      Times.Once);
                SupervisorStreamingServiceMock.Verify(a =>
                                                      a.OnSportUpdate(It.IsAny <ServiceModelInterface.ISportDetails>()),
                                                      Times.Once);
                SupervisorStreamingServiceMock.Verify(a =>
                                                      a.OnSportUpdate(It.Is <ServiceModelInterface.ISportDetails>(s =>
                                                                                                                  s.Name.Equals(sportOverview.Name) &&
                                                                                                                  s.InErrorState.Equals(sportOverview.InErrorState) &&
                                                                                                                  s.InPlay.Equals(sportOverview.InPlay) &&
                                                                                                                  s.InPreMatch.Equals(sportOverview.InPreMatch) &&
                                                                                                                  s.InSetup.Equals(sportOverview.InSetup) &&
                                                                                                                  s.Total.Equals(sportOverview.Total))),
                                                      Times.Once);
                ObjectProviderMock.Verify(a =>
                                          a.SetObject(
                                              null,
                                              It.Is <Dictionary <string, FixtureOverview> >(d =>
                                                                                            d.Equals(supervisorActor.FixturesOverview))),
                                          Times.Once);
            },
                        TimeSpan.FromMilliseconds(ASSERT_WAIT_TIMEOUT),
                        TimeSpan.FromMilliseconds(ASSERT_EXEC_INTERVAL));
        }