コード例 #1
0
        public void SuspensionManagerStrategiesTest()
        {
            var stateProvider     = new Mock <IStateProvider>();
            var plugin            = new Mock <IAdapterPlugin>();
            var suspensionManager = new SuspensionManager(stateProvider.Object, plugin.Object);

            var state = new MarketStateCollection("FXT-ID");

            // STEP 1: prepare the fixture
            // 1) fixture is in running
            // 2) with 2 in play markets
            // 3) 1 not in-play market
            // 4) 3 markets with an unknown state
            Fixture fixture = new Fixture
            {
                Id          = "FXT-ID",
                MatchStatus = MatchStatus.InRunning.ToString(),
                Sequence    = 2
            };

            var mkt1 = new Market {
                Id = "MKT-1"
            };

            mkt1.Selections.Add(new Selection {
                Id = "SELN", Status = SelectionStatus.Active
            });

            var mkt2 = new Market {
                Id = "MKT-2"
            };

            mkt2.Selections.Add(new Selection {
                Id = "SELN", Status = SelectionStatus.Active
            });

            var mkt3 = new Market {
                Id = "MKT-3"
            };

            mkt3.Selections.Add(new Selection {
                Id = "SELN", Status = SelectionStatus.Pending
            });

            var mkt4 = new Market {
                Id = "MKT-4"
            };

            mkt4.Selections.Add(new Selection {
                Id = "SELN", Status = SelectionStatus.Active
            });
            mkt4.AddOrUpdateTagValue("traded_in_play", "false");

            var mkt5 = new Market {
                Id = "MKT-5"
            };

            mkt5.Selections.Add(new Selection {
                Id = "SELN", Status = SelectionStatus.Active
            });
            mkt5.AddOrUpdateTagValue("traded_in_play", "true");

            var mkt6 = new Market {
                Id = "MKT-6"
            };

            mkt6.AddOrUpdateTagValue("traded_in_play", "true");

            fixture.Markets.Add(mkt1);
            fixture.Markets.Add(mkt2);
            fixture.Markets.Add(mkt3);
            fixture.Markets.Add(mkt4);
            fixture.Markets.Add(mkt5);
            fixture.Markets.Add(mkt6);
            state.Update(fixture, true);

            state.CommitChanges();

            // STEP 2: test the suspension strategies
            suspensionManager.SuspendAllMarketsStrategy(state);

            plugin.Verify(x => x.ProcessStreamUpdate(It.Is <Fixture>
                                                     (
                                                         y => y.Markets.Count == 6 &&
                                                         y.Markets.FirstOrDefault(z => z.Id == "MKT-1") != null &&
                                                         y.Markets.FirstOrDefault(z => z.Id == "MKT-2") != null &&
                                                         y.Markets.FirstOrDefault(z => z.Id == "MKT-3") != null &&
                                                         y.Markets.FirstOrDefault(z => z.Id == "MKT-4") != null &&
                                                         y.Markets.FirstOrDefault(z => z.Id == "MKT-5") != null &&
                                                         y.Markets.FirstOrDefault(z => z.Id == "MKT-6") != null
                                                     ), It.IsAny <bool>()));


            suspensionManager.SuspendFixtureIfInPlayStrategy(state);

            plugin.Verify(x => x.Suspend(It.Is <string>(y => y == "FXT-ID")));

            suspensionManager.SuspendFixtureStrategy(state);

            plugin.Verify(x => x.Suspend(It.Is <string>(y => y == "FXT-ID")));

            suspensionManager.SuspendInPlayMarketsStrategy(state);

            // The SuspensionManager takes a conservative approach.
            // If the traded_in_play tag is not present, it assumes
            // that the market is a in-play market
            plugin.Verify(x => x.ProcessStreamUpdate(It.Is <Fixture>
                                                     (
                                                         y => y.Markets.Count == 3 &&
                                                         y.Markets.FirstOrDefault(z => z.Id == "MKT-1") != null &&
                                                         y.Markets.FirstOrDefault(z => z.Id == "MKT-2") != null &&
                                                         y.Markets.FirstOrDefault(z => z.Id == "MKT-3") == null &&
                                                         y.Markets.FirstOrDefault(z => z.Id == "MKT-4") == null &&
                                                         y.Markets.FirstOrDefault(z => z.Id == "MKT-5") != null &&
                                                         y.Markets.FirstOrDefault(z => z.Id == "MKT-6") == null
                                                     ), It.IsAny <bool>()));


            // STEP 3: change the fixture
            // 1) change the fixture's match status
            // 2) remove a mkt
            // 3) add a new mkt

            fixture.MatchStatus = MatchStatus.MatchOver.ToString();

            fixture.Markets.Remove(fixture.Markets.FirstOrDefault(x => x.Id == "MKT-5"));

            var mkt7 = new Market {
                Id = "MKT-7"
            };

            mkt7.Selections.Add(new Selection {
                Id = "SELN", Status = SelectionStatus.Active
            });
            mkt7.AddOrUpdateTagValue("traded_in_play", "true");

            fixture.Markets.Add(mkt7);

            state.Update(fixture, true);
            state.CommitChanges();

            // STEP 4: test the suspension strategies again
            suspensionManager.SuspendAllMarketsStrategy(state);

            // note that we must have 7 markets now because the
            // SuspensionManager looks at the MarketState, not
            // at the fixture
            plugin.Verify(x => x.ProcessStreamUpdate(It.Is <Fixture>
                                                     (
                                                         y => y.Markets.Count == 7 &&
                                                         y.Markets.FirstOrDefault(z => z.Id == "MKT-1") != null &&
                                                         y.Markets.FirstOrDefault(z => z.Id == "MKT-2") != null &&
                                                         y.Markets.FirstOrDefault(z => z.Id == "MKT-3") != null &&
                                                         y.Markets.FirstOrDefault(z => z.Id == "MKT-4") != null &&
                                                         y.Markets.FirstOrDefault(z => z.Id == "MKT-5") != null &&
                                                         y.Markets.FirstOrDefault(z => z.Id == "MKT-6") != null &&
                                                         y.Markets.FirstOrDefault(z => z.Id == "MKT-7") != null
                                                     ), It.IsAny <bool>()));


            suspensionManager.SuspendFixtureIfInPlayStrategy(state);

            // The fixture is "MatchOver", so the Suspend() method should not have been called
            // Times.Exactly(2) because it has been called in the previous step...unfortunately
            // there seems to be no way to reset the verifications
            plugin.Verify(x => x.Suspend(It.Is <string>(y => y == "FXT-ID")), Times.Exactly(2));

            suspensionManager.SuspendFixtureStrategy(state);

            plugin.Verify(x => x.Suspend(It.Is <string>(y => y == "FXT-ID")), Times.Exactly(3));

            suspensionManager.SuspendInPlayMarketsStrategy(state);

            plugin.Verify(x => x.ProcessStreamUpdate(It.Is <Fixture>
                                                     (
                                                         y => y.Markets.Count == 4 &&
                                                         y.Markets.FirstOrDefault(z => z.Id == "MKT-1") != null &&
                                                         y.Markets.FirstOrDefault(z => z.Id == "MKT-2") != null &&
                                                         y.Markets.FirstOrDefault(z => z.Id == "MKT-3") == null &&
                                                         y.Markets.FirstOrDefault(z => z.Id == "MKT-4") == null &&
                                                         y.Markets.FirstOrDefault(z => z.Id == "MKT-5") != null &&
                                                         y.Markets.FirstOrDefault(z => z.Id == "MKT-6") == null &&
                                                         y.Markets.FirstOrDefault(z => z.Id == "MKT-7") != null
                                                     ), It.IsAny <bool>()));
        }
コード例 #2
0
        public void SuspensionManagerStrategiesTest()
        {
            var stateProvider = new Mock<IStateProvider>();
            var plugin = new Mock<IAdapterPlugin>();
            var suspensionManager = new SuspensionManager(stateProvider.Object, plugin.Object);

            var state = new MarketStateCollection("FXT-ID");

            // STEP 1: prepare the fixture 
            // 1) fixture is in running
            // 2) with 2 in play markets
            // 3) 1 not in-play market
            // 4) 3 markets with an unknown state
            Fixture fixture = new Fixture
            {
                Id = "FXT-ID",
                MatchStatus = MatchStatus.InRunning.ToString(),
                Sequence = 2
            };

            var mkt1 = new Market { Id = "MKT-1" };
            mkt1.Selections.Add(new Selection { Id = "SELN", Status = SelectionStatus.Active });

            var mkt2 = new Market { Id = "MKT-2" };
            mkt2.Selections.Add(new Selection { Id = "SELN", Status = SelectionStatus.Active });

            var mkt3 = new Market { Id = "MKT-3" };
            mkt3.Selections.Add(new Selection { Id = "SELN", Status = SelectionStatus.Pending });

            var mkt4 = new Market { Id = "MKT-4" };
            mkt4.Selections.Add(new Selection { Id = "SELN", Status = SelectionStatus.Active });
            mkt4.AddOrUpdateTagValue("traded_in_play", "false");

            var mkt5 = new Market { Id = "MKT-5" };
            mkt5.Selections.Add(new Selection { Id = "SELN", Status = SelectionStatus.Active });
            mkt5.AddOrUpdateTagValue("traded_in_play", "true");

            var mkt6 = new Market { Id = "MKT-6" };
            mkt6.AddOrUpdateTagValue("traded_in_play", "true");

            fixture.Markets.Add(mkt1);
            fixture.Markets.Add(mkt2);
            fixture.Markets.Add(mkt3);
            fixture.Markets.Add(mkt4);
            fixture.Markets.Add(mkt5);
            fixture.Markets.Add(mkt6);
            state.Update(fixture, true);
            
            state.CommitChanges();
            
            // STEP 2: test the suspension strategies
            suspensionManager.SuspendAllMarketsStrategy(state);

            plugin.Verify(x => x.ProcessStreamUpdate(It.Is<Fixture>
                (
                    y => y.Markets.Count == 6 &&
                         y.Markets.FirstOrDefault(z => z.Id == "MKT-1") != null &&
                         y.Markets.FirstOrDefault(z => z.Id == "MKT-2") != null &&
                         y.Markets.FirstOrDefault(z => z.Id == "MKT-3") != null &&
                         y.Markets.FirstOrDefault(z => z.Id == "MKT-4") != null &&
                         y.Markets.FirstOrDefault(z => z.Id == "MKT-5") != null &&
                         y.Markets.FirstOrDefault(z => z.Id == "MKT-6") != null
                ), It.IsAny<bool>()));


            suspensionManager.SuspendFixtureIfInPlayStrategy(state);

            plugin.Verify(x => x.Suspend(It.Is<string>(y => y == "FXT-ID")));

            suspensionManager.SuspendFixtureStrategy(state);

            plugin.Verify(x => x.Suspend(It.Is<string>(y => y == "FXT-ID")));

            suspensionManager.SuspendInPlayMarketsStrategy(state);

            // The SuspensionManager takes a conservative approach.
            // If the traded_in_play tag is not present, it assumes
            // that the market is a in-play market
            plugin.Verify(x => x.ProcessStreamUpdate(It.Is<Fixture>
                (
                    y => y.Markets.Count == 3 &&
                         y.Markets.FirstOrDefault(z => z.Id == "MKT-1") != null &&
                         y.Markets.FirstOrDefault(z => z.Id == "MKT-2") != null &&
                         y.Markets.FirstOrDefault(z => z.Id == "MKT-3") == null &&
                         y.Markets.FirstOrDefault(z => z.Id == "MKT-4") == null &&
                         y.Markets.FirstOrDefault(z => z.Id == "MKT-5") != null &&
                         y.Markets.FirstOrDefault(z => z.Id == "MKT-6") == null
                ), It.IsAny<bool>()));


            // STEP 3: change the fixture
            // 1) change the fixture's match status
            // 2) remove a mkt
            // 3) add a new mkt

            fixture.MatchStatus = MatchStatus.MatchOver.ToString();

            fixture.Markets.Remove(fixture.Markets.FirstOrDefault(x => x.Id == "MKT-5"));

            var mkt7 = new Market { Id = "MKT-7" };
            mkt7.Selections.Add(new Selection { Id = "SELN", Status = SelectionStatus.Active });
            mkt7.AddOrUpdateTagValue("traded_in_play", "true");

            fixture.Markets.Add(mkt7);

            state.Update(fixture, true);
            state.CommitChanges();
            
            // STEP 4: test the suspension strategies again
            suspensionManager.SuspendAllMarketsStrategy(state);

            // note that we must have 7 markets now because the 
            // SuspensionManager looks at the MarketState, not
            // at the fixture
            plugin.Verify(x => x.ProcessStreamUpdate(It.Is<Fixture>
                (
                    y => y.Markets.Count == 7 &&
                         y.Markets.FirstOrDefault(z => z.Id == "MKT-1") != null &&
                         y.Markets.FirstOrDefault(z => z.Id == "MKT-2") != null &&
                         y.Markets.FirstOrDefault(z => z.Id == "MKT-3") != null &&
                         y.Markets.FirstOrDefault(z => z.Id == "MKT-4") != null &&
                         y.Markets.FirstOrDefault(z => z.Id == "MKT-5") != null &&
                         y.Markets.FirstOrDefault(z => z.Id == "MKT-6") != null &&
                         y.Markets.FirstOrDefault(z => z.Id == "MKT-7") != null 
                ), It.IsAny<bool>()));


            suspensionManager.SuspendFixtureIfInPlayStrategy(state);

            // The fixture is "MatchOver", so the Suspend() method should not have been called
            // Times.Exactly(2) because it has been called in the previous step...unfortunately
            // there seems to be no way to reset the verifications
            plugin.Verify(x => x.Suspend(It.Is<string>(y => y == "FXT-ID")), Times.Exactly(2));

            suspensionManager.SuspendFixtureStrategy(state);

            plugin.Verify(x => x.Suspend(It.Is<string>(y => y == "FXT-ID")), Times.Exactly(3));

            suspensionManager.SuspendInPlayMarketsStrategy(state);

            plugin.Verify(x => x.ProcessStreamUpdate(It.Is<Fixture>
                (
                    y => y.Markets.Count == 4 &&
                         y.Markets.FirstOrDefault(z => z.Id == "MKT-1") != null &&
                         y.Markets.FirstOrDefault(z => z.Id == "MKT-2") != null &&
                         y.Markets.FirstOrDefault(z => z.Id == "MKT-3") == null &&
                         y.Markets.FirstOrDefault(z => z.Id == "MKT-4") == null &&
                         y.Markets.FirstOrDefault(z => z.Id == "MKT-5") != null &&
                         y.Markets.FirstOrDefault(z => z.Id == "MKT-6") == null &&
                         y.Markets.FirstOrDefault(z => z.Id == "MKT-7") != null
                ), It.IsAny<bool>()));

        }