public void OnNext_CallsOnCompleted_ForWhiteListTrueSubscribers_HighMarketCapFilter()
        {
            var fundOne  = ((Order)null).Random();
            var eventOne = new UniverseEvent(UniverseStateEvent.Order, DateTime.UtcNow, fundOne);

            A.CallTo(() => this._highMarketCapFilter.Filter(eventOne)).Returns(false);

            var filter = new UniverseFilterService(
                this._unsubscriber,
                this._highMarketCapFilter,
                this._filteredRule,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                this._logger);

            filter.Subscribe(this._observer);

            filter.OnNext(eventOne);

            A.CallTo(() => this._observer.OnNext(eventOne)).MustHaveHappenedOnceExactly();
        }
        public void OnNext_CallsOnCompleted_ForBlackListTrueSubscribers_Markets()
        {
            var markets = new RuleFilter {
                Ids = new[] { "abc", "ghi" }, Type = RuleFilterType.Exclude
            };

            var filter = new UniverseFilterService(
                this._unsubscriber,
                this._highMarketCapFilter,
                this._filteredRule,
                null,
                null,
                markets,
                null,
                null,
                null,
                null,
                null,
                null,
                this._logger);

            filter.Subscribe(this._observer);

            var accOne = ((Order)null).Random();

            accOne.Market = new Market("1", "abc", "abc", MarketTypes.STOCKEXCHANGE);
            var eventOne = new UniverseEvent(UniverseStateEvent.Order, DateTime.UtcNow, accOne);

            var accTwo = ((Order)null).Random();

            accTwo.Market = new Market("1", "def", "def", MarketTypes.STOCKEXCHANGE);
            var eventTwo = new UniverseEvent(UniverseStateEvent.Order, DateTime.UtcNow, accTwo);

            var exchangeOne = new EquityIntraDayTimeBarCollection(
                new Market("1", "ghi", "ghi", MarketTypes.STOCKEXCHANGE),
                DateTime.UtcNow,
                new EquityInstrumentIntraDayTimeBar[0]);
            var eventThree = new UniverseEvent(UniverseStateEvent.EquityIntraDayTick, DateTime.UtcNow, exchangeOne);

            var exchangeTwo = new EquityIntraDayTimeBarCollection(
                new Market("1", "jkl", "jkl", MarketTypes.STOCKEXCHANGE),
                DateTime.UtcNow,
                new EquityInstrumentIntraDayTimeBar[0]);
            var eventFour = new UniverseEvent(UniverseStateEvent.EquityIntraDayTick, DateTime.UtcNow, exchangeTwo);

            filter.OnNext(eventOne);
            filter.OnNext(eventTwo);
            filter.OnNext(eventThree);
            filter.OnNext(eventFour);

            A.CallTo(() => this._observer.OnNext(eventOne)).MustNotHaveHappened();
            A.CallTo(() => this._observer.OnNext(eventTwo)).MustHaveHappenedOnceExactly();
            A.CallTo(() => this._observer.OnNext(eventThree)).MustNotHaveHappened();
            A.CallTo(() => this._observer.OnNext(eventFour)).MustHaveHappenedOnceExactly();
        }
        public void OnNext_CallsOnCompleted_ForWhiteListTrueSubscribers_Industries()
        {
            var industry = new RuleFilter {
                Ids = new[] { "abc" }, Type = RuleFilterType.Include
            };

            var filter = new UniverseFilterService(
                this._unsubscriber,
                this._highMarketCapFilter,
                this._filteredRule,
                null,
                null,
                null,
                null,
                null,
                null,
                industry,
                null,
                null,
                this._logger);

            filter.Subscribe(this._observer);

            var strategyOne = ((Order)null).Random();

            strategyOne.Instrument.IndustryCode = "abc";
            var eventOne = new UniverseEvent(UniverseStateEvent.Order, DateTime.UtcNow, strategyOne);

            var strategyTwo = ((Order)null).Random();

            strategyTwo.Instrument.IndustryCode = "def";
            var eventTwo = new UniverseEvent(UniverseStateEvent.Order, DateTime.UtcNow, strategyTwo);

            filter.OnNext(eventOne);
            filter.OnNext(eventTwo);

            A.CallTo(() => this._observer.OnNext(eventOne)).MustHaveHappenedOnceExactly();
            A.CallTo(() => this._observer.OnNext(eventTwo)).MustNotHaveHappened();
        }
        public void OnNext_CallsOnCompleted_ForWhiteListTrueSubscribers_Accounts()
        {
            var account = new RuleFilter {
                Ids = new[] { "abc" }, Type = RuleFilterType.Include
            };

            var filter = new UniverseFilterService(
                this._unsubscriber,
                this._highMarketCapFilter,
                this._filteredRule,
                account,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                this._logger);

            filter.Subscribe(this._observer);

            var accOne = ((Order)null).Random();

            accOne.OrderClientAccountAttributionId = "abc";
            var eventOne = new UniverseEvent(UniverseStateEvent.Order, DateTime.UtcNow, accOne);

            var accTwo = ((Order)null).Random();

            accTwo.OrderClientAccountAttributionId = "def";
            var eventTwo = new UniverseEvent(UniverseStateEvent.Order, DateTime.UtcNow, accTwo);

            filter.OnNext(eventOne);
            filter.OnNext(eventTwo);

            A.CallTo(() => this._observer.OnNext(eventOne)).MustHaveHappenedOnceExactly();
            A.CallTo(() => this._observer.OnNext(eventTwo)).MustNotHaveHappened();
        }
        public void OnNext_CallsOnCompleted_ForNoneTrueSubscribers_Strategies()
        {
            var strategy = new RuleFilter {
                Ids = new[] { "abc" }, Type = RuleFilterType.None
            };

            var filter = new UniverseFilterService(
                this._unsubscriber,
                this._highMarketCapFilter,
                this._filteredRule,
                null,
                null,
                null,
                null,
                strategy,
                null,
                null,
                null,
                null,
                this._logger);

            filter.Subscribe(this._observer);

            var fundOne = ((Order)null).Random();

            fundOne.OrderStrategy = "abc";
            var eventOne = new UniverseEvent(UniverseStateEvent.Order, DateTime.UtcNow, fundOne);

            var fundTwo = ((Order)null).Random();

            fundTwo.OrderStrategy = "def";
            var eventTwo = new UniverseEvent(UniverseStateEvent.Order, DateTime.UtcNow, fundTwo);

            filter.OnNext(eventOne);
            filter.OnNext(eventTwo);

            A.CallTo(() => this._observer.OnNext(eventOne)).MustHaveHappenedOnceExactly();
            A.CallTo(() => this._observer.OnNext(eventTwo)).MustHaveHappenedOnceExactly();
        }
        public void OnError_CallsOnCompleted_ForSubscribers()
        {
            var filter = new UniverseFilterService(
                this._unsubscriber,
                this._highMarketCapFilter,
                this._filteredRule,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                this._logger);

            filter.Subscribe(this._observer);

            filter.OnError(new ArgumentNullException());

            A.CallTo(() => this._observer.OnError(A <Exception> .Ignored)).MustHaveHappenedOnceExactly();
        }
        public void OnNext_CallsOnCompleted_ForSubscribers()
        {
            var filter = new UniverseFilterService(
                this._unsubscriber,
                this._highMarketCapFilter,
                this._filteredRule,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                this._logger);

            filter.Subscribe(this._observer);

            filter.OnNext(new UniverseEvent(UniverseStateEvent.Genesis, DateTime.UtcNow, new object()));

            A.CallTo(() => this._observer.OnNext(A <IUniverseEvent> .Ignored)).MustHaveHappenedOnceExactly();
        }
        public void OnCompleted_CallsOnCompleted_ForSubscribers()
        {
            var filter = new UniverseFilterService(
                this._unsubscriber,
                this._highMarketCapFilter,
                this._filteredRule,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                this._logger);

            filter.Subscribe(this._observer);

            filter.OnCompleted();

            A.CallTo(() => this._observer.OnCompleted()).MustHaveHappenedOnceExactly();
        }